v1.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace zin;
  3. class pager extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array
  9. (
  10. 'type?: string="full"',
  11. 'page?: int',
  12. 'recTotal?: int',
  13. 'recPerPage?: int',
  14. 'linkCreator?: string',
  15. 'items?: array',
  16. 'sizeMenuCaret?: string'
  17. );
  18. /**
  19. * @param string $type
  20. */
  21. protected function buildProps($type = 'full')
  22. {
  23. global $lang;
  24. $pager = data('pager');
  25. $pager->setParams();
  26. $params = $pager->params;
  27. foreach($params as $key => $value)
  28. {
  29. if(strtolower($key) === 'recperpage') $params[$key] = '{recPerPage}';
  30. if(strtolower($key) === 'pageid') $params[$key] = '{page}';
  31. }
  32. $props = array();
  33. $props['page'] = $pager->pageID;
  34. $props['recTotal'] = $pager->recTotal;
  35. $props['recPerPage'] = $pager->recPerPage;
  36. $props['linkCreator'] = createLink($pager->moduleName, $pager->methodName, $params);
  37. $items = $this->prop('items');
  38. if(!$items) $items = array
  39. (
  40. $type == 'short' ? null : array('type' => 'info', 'text' => $lang->pager->totalCountAB),
  41. $type == 'short' ? null : array('type' => 'size-menu', 'text' => $lang->pager->pageSizeAB),
  42. array('type' => 'link', 'hint' => $lang->pager->firstPage, 'page' => 'first', 'icon' => 'icon-first-page'),
  43. array('type' => 'link', 'hint' => $lang->pager->previousPage, 'page' => 'prev', 'icon' => 'icon-angle-left'),
  44. array('type' => 'info', 'text' => '{page}/{pageTotal}'),
  45. array('type' => 'link', 'hint' => $lang->pager->nextPage, 'page' => 'next', 'icon' => 'icon-angle-right'),
  46. array('type' => 'link', 'hint' => $lang->pager->lastPage, 'page' => 'last', 'icon' => 'icon-last-page')
  47. );
  48. foreach($items as &$item)
  49. {
  50. if($item['type'] !== 'size-menu' || isset($item['caret'])) continue;
  51. $item['caret'] = $this->prop('sizeMenuCaret');
  52. }
  53. $props['items'] = $items;
  54. $this->setProp($props);
  55. }
  56. protected function build()
  57. {
  58. $this->buildProps($this->prop('type'));
  59. return zui::pager(inherit($this));
  60. }
  61. }