views_php_plugin_pager.inc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * A (fake) pager plugin that wraps around the actual pager.
  4. *
  5. * @ingroup views_pager_plugins
  6. */
  7. class views_php_plugin_pager extends views_php_plugin_wrapper {
  8. /**
  9. * Perform any needed actions just prior to the query executing.
  10. */
  11. public function pre_execute($query) {
  12. $this->wrapped->pre_execute($query);
  13. foreach (array(/*'argument',*/ 'field', 'filter', 'sort', /*'relationship'*/) as $type) {
  14. foreach ($this->wrapped->view->$type as $id => $handler) {
  15. if (is_callable(array($handler, 'php_pre_execute'))) {
  16. $handler->php_pre_execute();
  17. }
  18. }
  19. }
  20. $this->wrapped->view->query->set_limit(0);
  21. $this->wrapped->view->query->set_offset(0);
  22. }
  23. /**
  24. * Perform any needed actions just after the query executing.
  25. */
  26. public function post_execute(&$result) {
  27. foreach (array(/*'argument',*/ 'field', 'filter', 'sort', /*'relationship'*/) as $type) {
  28. foreach ($this->wrapped->view->$type as $id => $handler) {
  29. if (is_callable(array($handler, 'php_post_execute'))) {
  30. $handler->php_post_execute();
  31. }
  32. }
  33. }
  34. $this->wrapped->total_items = count($this->wrapped->view->result);
  35. $this->wrapped->update_page_info();
  36. $item_per_page = $this->wrapped->get_items_per_page();
  37. if ($item_per_page > 0) {
  38. $offset = $this->wrapped->get_current_page() * $item_per_page + $this->wrapped->get_offset();
  39. $this->wrapped->view->result = array_slice($this->wrapped->view->result, $offset, $item_per_page);
  40. }
  41. $this->wrapped->post_execute($result);
  42. }
  43. /**
  44. * Execute the count query, which will be done just prior to the query
  45. * itself being executed.
  46. */
  47. function execute_count_query(&$count_query) {
  48. $this->wrapped->execute_count_query($count_query);
  49. }
  50. }