Advertisement
Limarc

Getting of the page item in the list, Bitrix

Dec 30th, 2011
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. <?php
  2.  /**
  3.   * Getting of the page item in the list
  4.   *
  5.   * @access public
  6.   * @param array $arParams params element (only `int` type)
  7.   * @param array $arFilter filter elements
  8.   * @param array $arSort sort elements
  9.   * @return int
  10.   * @api
  11.   */
  12.  function GetNumPageElement (array $arParams, array $arFilter, array $arOrder = array('SORT' => 'ASC'))
  13.  {
  14.          //LQ_FI::CleanArrayInt($arParams);
  15.      
  16.          // -> check
  17.      if ($arParams['ID'] < 1 or $arParams['nPageSize'] < 1)
  18.      {
  19.          return 1;
  20.      }
  21.          
  22.      // -> complex?
  23.      $complex = isset($arOrder['SORT']) && count($arOrder) > 1;
  24.          
  25.      // -> ib interface
  26.      $arFilter['ACTIVE'] = 'Y';
  27.          
  28.          // -> section
  29.      if ($arParams['SECTION_ID'] > 0)
  30.      {
  31.          $arFilter['SECTION_ID'] = $arParams['SECTION_ID'];
  32.      }
  33.      
  34.      // -> limit
  35.      if ($complex === FALSE)
  36.      {
  37.          foreach ($arOrder as $key => $by)
  38.          {
  39.              if (isset($arParams[$key]))
  40.              {
  41.                  $prefix = (mb_stripos($by, 'asc') !== FALSE) ? '<=' : '>=';
  42.                                  
  43.                                  // -> add filter of limit
  44.                                  $arFilter[$prefix.$key] = $arParams[$key];
  45.              }
  46.          }
  47.      }
  48.          
  49.      unset($arFilter['ID']);
  50.          
  51.      // -> get
  52.      $obj = CIBlockElement::GetList($arOrder, $arFilter, FALSE, FALSE, array('ID'));
  53.          
  54.      // -> rows count
  55.      $rowsCount = $obj->SelectedRowsCount();
  56.      
  57.      // -> logic complex
  58.      if ($complex === TRUE)
  59.      {
  60.          $rowsCount = 0;
  61.          
  62.          // -> rows
  63.          while ($arItem = $obj->Fetch())
  64.          {
  65.              ++$rowsCount;
  66.              
  67.              // -> point break
  68.              if ($arItem['ID'] == $arParams['ID']) break;
  69.          }
  70.      }
  71.      
  72.      // -> calculate
  73.      if ($rowsCount <= $arParams['nPageSize'])
  74.      {
  75.          return 1;
  76.      }
  77.      
  78.      return ceil($rowsCount/$arParams['nPageSize']);
  79.  }
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement