views_php_plugin_pager.inc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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->post_execute($result);
  35. }
  36. public function pre_render() {
  37. foreach (array(/*'argument',*/ 'field', 'filter', 'sort', /*'relationship'*/) as $type) {
  38. foreach ($this->wrapped->view->$type as $id => $handler) {
  39. if (is_callable(array($handler, 'php_pre_render'))) {
  40. $handler->php_pre_render();
  41. }
  42. }
  43. }
  44. $this->update_wrapped_pager();
  45. $this->php_unwrap();
  46. }
  47. protected function update_wrapped_pager() {
  48. $this->wrapped->total_items = count($this->wrapped->view->result);
  49. $this->wrapped->update_page_info();
  50. $item_per_page = $this->wrapped->get_items_per_page();
  51. if ($item_per_page > 0) {
  52. $offset = $this->wrapped->get_current_page() * $item_per_page + $this->wrapped->get_offset();
  53. $this->wrapped->view->result = array_slice($this->wrapped->view->result, $offset, $item_per_page);
  54. }
  55. }
  56. /**
  57. * Execute the count query, which will be done just prior to the query
  58. * itself being executed.
  59. */
  60. function execute_count_query(&$count_query) {
  61. $this->wrapped->execute_count_query($count_query);
  62. }
  63. }