Posted By

wza on 06/28/10


Tagged

view textmate module drupal views totals


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tronx


drupal views view totals


 / Published in: PHP
 

  1. function module_view_totals($viewName, $display_id = 'default', $argument) {
  2.  
  3. // load viewobject
  4. $view = views_get_view($viewName);
  5.  
  6. // ensure view exists
  7. if (!$view) return;
  8.  
  9. // set object property to return total rows
  10. $view->get_total_rows = true;
  11.  
  12. // set display_id
  13. $view->set_display($display_id);
  14.  
  15. //set argument
  16. $view->set_arguments(array($argument));
  17.  
  18. // execute view
  19. $view->execute();
  20.  
  21. // acquire data from views object and $_REQUEST
  22. $itemsPerPage = $view->pager['items_per_page'];
  23. $currentPage = $_REQUEST['page']+1;
  24. $total = $view->total_rows;
  25.  
  26. // start calculation
  27. $start = 10*$currentPage-9;
  28. $end = $itemsPerPage * $currentPage;
  29. if ($end>$total) $end = $total;
  30.  
  31. // return html
  32. //return "Displaying $start - $end of $total";
  33. return $total;
  34. }

Report this snippet  

You need to login to post a comment.