• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/compatible/compatible.php
  • Класс: BitrixSaleCompatibleCDBResult
  • Вызов: CDBResult::compatibleNavQuery
function compatibleNavQuery(Query $query, array $arNavStartParams) //, $bIgnoreErrors = false)
{
	$cnt = $query->exec()->getSelectedRowsCount(); // TODO check groups

	global $DB;

	if(isset($arNavStartParams["SubstitutionFunction"]))
	{
		$arNavStartParams["SubstitutionFunction"]($this, $query->getLastQuery(), $cnt, $arNavStartParams);
		return null;
	}

	if(isset($arNavStartParams["bDescPageNumbering"]))
		$bDescPageNumbering = $arNavStartParams["bDescPageNumbering"];
	else
		$bDescPageNumbering = false;

	$this->InitNavStartVars($arNavStartParams);
	$this->NavRecordCount = $cnt;

	if($this->NavShowAll)
		$this->NavPageSize = $this->NavRecordCount;

	//calculate total pages depend on rows count. start with 1
	$this->NavPageCount = ($this->NavPageSize>0 ? floor($this->NavRecordCount/$this->NavPageSize) : 0);
	if($bDescPageNumbering)
	{
		$makeweight = 0;
		if($this->NavPageSize > 0)
			$makeweight = ($this->NavRecordCount % $this->NavPageSize);
		if($this->NavPageCount == 0 && $makeweight > 0)
			$this->NavPageCount = 1;

		//page number to display
		$this->calculatePageNumber($this->NavPageCount);

		//rows to skip
		$NavFirstRecordShow = 0;
		if($this->NavPageNomer != $this->NavPageCount)
			$NavFirstRecordShow += $makeweight;

		$NavFirstRecordShow += ($this->NavPageCount - $this->NavPageNomer) * $this->NavPageSize;
		$NavLastRecordShow = $makeweight + ($this->NavPageCount - $this->NavPageNomer + 1) * $this->NavPageSize;
	}
	else
	{
		if($this->NavPageSize > 0 && ($this->NavRecordCount % $this->NavPageSize > 0))
			$this->NavPageCount++;

		//calculate total pages depend on rows count. start with 1
		$this->calculatePageNumber(1, true, (bool)($arNavStartParams["checkOutOfRange"] ?? false));
		if ($this->NavPageNomer === null)
		{
			return null;
		}

		//rows to skip
		$NavFirstRecordShow = $this->NavPageSize*($this->NavPageNomer-1);
		$NavLastRecordShow = $this->NavPageSize*$this->NavPageNomer;
	}

	$NavAdditionalRecords = 0;
	if(is_set($arNavStartParams, "iNavAddRecords"))
		$NavAdditionalRecords = $arNavStartParams["iNavAddRecords"];

	if(!$this->NavShowAll)
	{
		$query->setOffset($NavFirstRecordShow);
		$query->setLimit($NavLastRecordShow - $NavFirstRecordShow + $NavAdditionalRecords);
	}

	$res_tmp = $query->exec(); //, $bIgnoreErrors);

//		// Return false on sql errors (if $bIgnoreErrors == true)
//		if ($bIgnoreErrors && ($res_tmp === false))
//			return false;

//		$this->result = $res_tmp->result;
	$this->DB = $DB;

	if($this->SqlTraceIndex)
		$start_time = microtime(true);

	$temp_arrray = array();
	$temp_arrray_add = array();
	$tmp_cnt = 0;

	while($ar = $res_tmp->fetch())
	{
		$tmp_cnt++;
		if (intval($NavLastRecordShow - $NavFirstRecordShow) > 0 && $tmp_cnt > ($NavLastRecordShow - $NavFirstRecordShow))
			$temp_arrray_add[] = $ar;
		else
			$temp_arrray[] = $ar;
	}

	if($this->SqlTraceIndex)
	{
		/** @noinspection PhpUndefinedVariableInspection */
		$exec_time = round(microtime(true) - $start_time, 10);
		$DB->addDebugTime($this->SqlTraceIndex, $exec_time);
		$DB->timeQuery += $exec_time;
	}

	$this->arResult = (!empty($temp_arrray)? $temp_arrray : false);
	$this->arResultAdd = (!empty($temp_arrray_add)? $temp_arrray_add : false);
	$this->nSelectedCount = $cnt;
	$this->bDescPageNumbering = $bDescPageNumbering;
	$this->bFromLimited = true;

	return null;
}