Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Getting of the page item in the list
- *
- * @access public
- * @param array $arParams params element (only `int` type)
- * @param array $arFilter filter elements
- * @param array $arSort sort elements
- * @return int
- * @api
- */
- function GetNumPageElement (array $arParams, array $arFilter, array $arOrder = array('SORT' => 'ASC'))
- {
- //LQ_FI::CleanArrayInt($arParams);
- // -> check
- if ($arParams['ID'] < 1 or $arParams['nPageSize'] < 1)
- {
- return 1;
- }
- // -> complex?
- $complex = isset($arOrder['SORT']) && count($arOrder) > 1;
- // -> ib interface
- $arFilter['ACTIVE'] = 'Y';
- // -> section
- if ($arParams['SECTION_ID'] > 0)
- {
- $arFilter['SECTION_ID'] = $arParams['SECTION_ID'];
- }
- // -> limit
- if ($complex === FALSE)
- {
- foreach ($arOrder as $key => $by)
- {
- if (isset($arParams[$key]))
- {
- $prefix = (mb_stripos($by, 'asc') !== FALSE) ? '<=' : '>=';
- // -> add filter of limit
- $arFilter[$prefix.$key] = $arParams[$key];
- }
- }
- }
- unset($arFilter['ID']);
- // -> get
- $obj = CIBlockElement::GetList($arOrder, $arFilter, FALSE, FALSE, array('ID'));
- // -> rows count
- $rowsCount = $obj->SelectedRowsCount();
- // -> logic complex
- if ($complex === TRUE)
- {
- $rowsCount = 0;
- // -> rows
- while ($arItem = $obj->Fetch())
- {
- ++$rowsCount;
- // -> point break
- if ($arItem['ID'] == $arParams['ID']) break;
- }
- }
- // -> calculate
- if ($rowsCount <= $arParams['nPageSize'])
- {
- return 1;
- }
- return ceil($rowsCount/$arParams['nPageSize']);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement