May
30

Email is dead, hello Wave!

Gepost in Sociale media, Tips & Tools door Albert

I got home yesterday and noticed a lot of buzz going on about something called Google Wave. At first I thought it might be yet another Google service but 5 minutes into the video presentation I was hooked. This is  indeed how on-line communication was meant to be. But you really should watch the video yourself to get a good picture. Mashable also made a great guide.

This product/platform/protocol  has got the potential to grow huge for a number of reasons:

1. It’s what people desperately need. Email is NOT the future.

2. It’s open. Unlike some people think, this won’t mean everything will be on Google’s server. Google is making a protocol and open platform which you will be able to host on your own server.

3. It’s extremely powerful through the use of an API. Google wisely chose to demo Wave at a room filled with 4000 developers which all got closed beta accounts in a sandbox environment. This way they want to make sure Wave will have plenty of cool extensions people can use, or integrate it with your Drupal website.

Some of the wave robots they built for the demo were already very impressive, and I for one can’t wait to see this product enrich the way we communicate on-line.

Related:

 

Drupalcon Paris’ website got a redesign and registrations are now open. The earlier version raised a lot of interesting discussion. According to some people the design was sexist. Frankly I hadn’t even noticed, but I think everybody will be happy with the new design.

Anyway, when I clicked around the site I noticed some great functionality on the ‘News’ section. A number of  boxes, populated with views or other content, which you can enable/disable and drag-n-drop around the page, using a three column layout in this case.

draggable content blocks using homebox

draggable content blocks using homebox

It reminded me of the dashboard functionality which will be available on the new drupal.org website. However this appeared to be a different module which is already available as an alpha release called homebox. Great stuff!

 
May
13

Count views results

Gepost in Drupal door Albert

Here’s a short snippet howto create custom result counters with index for your views in Drupal 5 and Drupal 6.

An example of this code could result:

Showing 21 – 30 of 46 results.

A very common usage, but not available out-of-the-box in Views 1 or 2. You will need to theme a bit using some code snippets. Here’s how you can do it:

Drupal 5 – Views 1

In Drupal 5, you can simply copy-paste this php code into the header part of your View.

<?php
// here are the variables we will need
global $pager_page_array, $pager_total_items, $pager_total, $current_view;
 
if ($pager_total[0] == 1) {
  // if there is only one page, do this:
  echo "Showing " . $pager_total_items[0] . " results.";
} else {
  // if there are more pages, we will need to take the current page
  // and multiply it with the number of results per page
  // add one, because the first page is zero.
  $from = 1 + ($pager_page_array[0] * $current_view-&gt;pager_limit);
  // add one page to get the last result in this particular page
  $to = (1 + $pager_page_array[0]) * $current_view-&gt;pager_limit;
  // check if the last page has less items than the amount allowed on each page
  if ($to &gt; $pager_total_items[0]) {
    $to = $pager_total_items[0];
  }
  echo "Showing " . $from . " - " . $to . " of " . $pager_total_items[0] . " results.";
}
?>

Drupal 6 – Views 2

In Drupal 6 and Views 2, the easiest way (in my opinion) is to create a custom template for your view and add the necessary code beneath. Unlike the above example for Drupal 5, this code will *not* work in the header of the view if you embed it using the Views 2 user interface.

update: actually it is possible to put a similar kind of code in the Header area of the view. However, some necessary variables are only populated when the pager is turned on. See this thread for more info. You can still do this in the theming layer with the code beneath.

So either create something like views-view.tpl.php (if you want to override all views) or views-view–[viewname].tpl.php for one view. You can find the required filename and template code by clicking on the “Theme: information” link in your admin interface in Views 2.

Now, you can embed this code anywhere you like:

<?php
$from = ($view-&gt;pager['current_page'] * $view-&gt;pager['items_per_page']) + 1;
$to = $from + count($view-&gt;result) - 1;
$total = $view-&gt;total_rows;
if ($total &lt;= $to ) {
  // no need to show where we are if everything fits on the first page
  echo "Showing " . $total . " results.";
} else {
  echo "Showing " . $from . " - " . $to . " of " . $total . " results.";
}
?>

Custom pager or fields in views
Here are some related modules which might come in handy: