Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. /**
  2. * @return array
  3. */
  4. protected function initNavParams()
  5. {
  6. global $NavNum;
  7.  
  8. $navParams = [
  9. 'NAV_NUM' => ++$NavNum,
  10. 'PAGE_NUMBER' => 1,
  11. 'PAGE_ELEMENT_COUNT' => 20,
  12. ];
  13.  
  14. $unique = md5($this->getEntity()->getDBTableName());
  15. $pageKey = 'PAGEN_'.$navParams['NAV_NUM'];
  16. $sizeKey = 'SIZEN_'.$navParams['NAV_NUM'];
  17. $sessionPageKey = $unique.$pageKey;
  18. $sessionSizeKey = $unique.$sizeKey;
  19.  
  20.  
  21. /** @noinspection PhpDynamicAsStaticMethodCallInspection */
  22. if (\CPageOption::GetOptionString('main', 'nav_page_in_session', 'Y') == 'Y') {
  23. if (isset($_SESSION[$sessionPageKey]) && (int)$_SESSION[$sessionPageKey]) {
  24. $navParams['PAGE_NUMBER'] = (int)$_SESSION[$sessionPageKey];
  25. }
  26. if (isset($_SESSION[$sessionSizeKey]) && (int)$_SESSION[$sessionSizeKey]) {
  27. $navParams['PAGE_ELEMENT_COUNT'] = (int)$_SESSION[$sessionSizeKey];
  28. }
  29. }
  30.  
  31. if (isset($_REQUEST[$pageKey]) && (int)$_REQUEST[$pageKey]) {
  32. $navParams['PAGE_NUMBER'] = (int)$_REQUEST[$pageKey];
  33. }
  34. if (isset($_REQUEST[$sizeKey]) && (int)$_REQUEST[$sizeKey]) {
  35. $navParams['PAGE_ELEMENT_COUNT'] = (int)$_REQUEST[$sizeKey];
  36. }
  37.  
  38. if (!(int)$navParams['PAGE_NUMBER']) {
  39. $navParams['PAGE_NUMBER'] = 1;
  40. }
  41.  
  42. if (!(int)$navParams['PAGE_ELEMENT_COUNT']) {
  43. $navParams['PAGE_ELEMENT_COUNT'] = 20;
  44. }
  45.  
  46. /** @noinspection PhpDynamicAsStaticMethodCallInspection */
  47. if (\CPageOption::GetOptionString('main', 'nav_page_in_session', 'Y') == 'Y') {
  48. $_SESSION[$sessionPageKey] = $navParams['PAGE_NUMBER'];
  49. $_SESSION[$sessionSizeKey] = $navParams['PAGE_ELEMENT_COUNT'];
  50. }
  51.  
  52. return $navParams;
  53. }
  54.  
  55. /**
  56. * @param $navParams
  57. * @param $filter
  58. * @param $runtime
  59. */
  60. protected function initPagination($navParams, $filter, $runtime)
  61. {
  62. $params = [
  63. 'select' => [new ExpressionField('CNT', $this->useFoundRows ? 'FOUND_ROWS()' : 'COUNT(1)')],
  64. ];
  65. if (!$this->useFoundRows) {
  66. $params['filter'] = $filter;
  67. $params['runtime'] = $runtime;
  68. }
  69.  
  70. $total = (int)call_user_func([$this->entity->getDataClass(), 'getList'], $params)->fetch()['CNT'];
  71.  
  72. $adminResult = new \CAdminResult([], $this->entity->getDBTableName());
  73. $adminResult->NavPageCount = ceil($total / $navParams['PAGE_ELEMENT_COUNT']);
  74. $adminResult->NavPageNomer = $navParams['PAGE_NUMBER'];
  75. $adminResult->NavNum = $navParams['NAV_NUM'];
  76. $adminResult->NavPageSize = $navParams['PAGE_ELEMENT_COUNT'];
  77. $adminResult->NavRecordCount = $total;
  78.  
  79. $this->list->NavText($adminResult->GetNavPrint($this->getTitle()));
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement