1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
dbresult.php
См. документацию.
1<?php
2
9
10use Bitrix\Main;
11
12IncludeModuleLangFile(__FILE__);
13
14abstract class CAllDBResult
15{
18 var $arReplacedAliases; // replace tech. aliases in Fetch to human aliases
20 var $bNavStart = false;
21 var $bShowAll = false;
23 var $bFirstPrintNav = true;
26 var $add_anchor = "";
27 var $bPostNavigation = false;
28 var $bFromArray = false;
29 var $bFromLimited = false;
30 var $nPageWindow = 5;
31 var $nSelectedCount = false;
32 var $arGetNextCache = false;
35 var $arUserFields = false;
36 var $usedUserFields = false;
38 var $SqlTraceIndex = false;
40 var $DB;
42 var $is_filtered = false;
43 var $nStartPage = 0;
44 var $nEndPage = 0;
46 var $resultObject = null;
47
49 public function __construct($res = null)
50 {
51 $obj = is_object($res);
52 if ($obj && is_subclass_of($res, "CAllDBResult"))
53 {
54 $this->result = $res->result;
55 $this->nSelectedCount = $res->nSelectedCount;
56 $this->arResult = $res->arResult;
57 $this->arResultAdd = $res->arResultAdd;
58 $this->bNavStart = $res->bNavStart;
59 $this->NavPageNomer = $res->NavPageNomer;
60 $this->bShowAll = $res->bShowAll;
61 $this->NavNum = $res->NavNum;
62 $this->NavPageCount = $res->NavPageCount;
63 $this->NavPageSize = $res->NavPageSize;
64 $this->NavShowAll = $res->NavShowAll;
65 $this->NavRecordCount = $res->NavRecordCount;
66 $this->bFirstPrintNav = $res->bFirstPrintNav;
67 $this->PAGEN = $res->PAGEN;
68 $this->SIZEN = $res->SIZEN;
69 $this->bFromArray = $res->bFromArray;
70 $this->bFromLimited = $res->bFromLimited;
71 $this->nPageWindow = $res->nPageWindow;
72 $this->bDescPageNumbering = $res->bDescPageNumbering;
73 $this->SqlTraceIndex = $res->SqlTraceIndex;
74 $this->DB = $res->DB;
75 $this->arUserFields = $res->arUserFields;
76 }
77 elseif ($obj && $res instanceof Main\DB\ArrayResult)
78 {
79 $this->InitFromArray($res->getResource());
80 }
81 elseif ($obj && $res instanceof Main\DB\Result)
82 {
83 $this->result = $res->getResource();
84 $this->resultObject = $res;
85 }
86 elseif (is_array($res))
87 {
88 $this->arResult = $res;
89 }
90 else
91 {
92 $this->result = $res;
93 }
94 }
95
96 public function __sleep()
97 {
98 return [
99 'arResult',
100 'arReplacedAliases',
101 'arResultAdd',
102 'bNavStart',
103 'bShowAll',
104 'NavNum',
105 'NavPageCount',
106 'NavPageNomer',
107 'NavPageSize',
108 'NavShowAll',
109 'NavRecordCount',
110 'bFirstPrintNav',
111 'PAGEN',
112 'SIZEN',
113 'add_anchor',
114 'bPostNavigation',
115 'bFromArray',
116 'bFromLimited',
117 'nPageWindow',
118 'nSelectedCount',
119 'arGetNextCache',
120 'bDescPageNumbering',
121 ];
122 }
123
129 function Fetch()
130 {
131 global $DB;
132
133 if ($this->bNavStart || $this->bFromArray)
134 {
135 if (!is_array($this->arResult))
136 {
137 $res = false;
138 }
139 elseif ($res = current($this->arResult))
140 {
141 next($this->arResult);
142 }
143 }
144 else
145 {
146 if ($this->SqlTraceIndex)
147 {
148 $start_time = microtime(true);
149 }
150
151 $res = $this->FetchInternal();
152
153 if ($this->SqlTraceIndex)
154 {
156 $exec_time = round(microtime(true) - $start_time, 10);
157 $DB->addDebugTime($this->SqlTraceIndex, $exec_time);
158 $DB->timeQuery += $exec_time;
159 }
160 }
161
162 return $res;
163 }
164
168 protected function FetchInternal()
169 {
170 if ($this->resultObject !== null)
171 {
172 $res = $this->resultObject->fetch();
173 }
174 else
175 {
176 $res = $this->FetchRow();
177
178 if (!$res)
179 {
180 return false;
181 }
182
183 $this->AfterFetch($res);
184 }
185 return $res;
186 }
187
188 abstract protected function FetchRow();
189
190 abstract public function SelectedRowsCount();
191
192 abstract public function AffectedRowsCount();
193
194 abstract public function FieldsCount();
195
196 abstract public function FieldName($iCol);
197
198 abstract protected function GetRowsCount(): ?int;
199
200 abstract protected function Seek(int $offset): void;
201
202 function NavQuery($strSql, $cnt, $arNavStartParams, $bIgnoreErrors = false)
203 {
204 global $DB;
205
206 if (isset($arNavStartParams["SubstitutionFunction"]))
207 {
208 $arNavStartParams["SubstitutionFunction"]($this, $strSql, $cnt, $arNavStartParams);
209 return null;
210 }
211
212 $bDescPageNumbering = $arNavStartParams["bDescPageNumbering"] ?? false;
213
214 $this->InitNavStartVars($arNavStartParams);
215 $this->NavRecordCount = $cnt;
216
217 if ($this->NavShowAll)
218 {
219 $this->NavPageSize = $this->NavRecordCount;
220 }
221
222 //calculate total pages depend on rows count. start with 1
223 $this->NavPageCount = ($this->NavPageSize > 0 ? floor($this->NavRecordCount / $this->NavPageSize) : 0);
225 {
226 $makeweight = 0;
227 if ($this->NavPageSize > 0)
228 {
229 $makeweight = ($this->NavRecordCount % $this->NavPageSize);
230 }
231 if ($this->NavPageCount == 0 && $makeweight > 0)
232 {
233 $this->NavPageCount = 1;
234 }
235
236 //page number to display
237 $this->calculatePageNumber($this->NavPageCount);
238
239 //rows to skip
240 $NavFirstRecordShow = 0;
241 if ($this->NavPageNomer != $this->NavPageCount)
242 {
243 $NavFirstRecordShow += $makeweight;
244 }
245
246 $NavFirstRecordShow += ($this->NavPageCount - $this->NavPageNomer) * $this->NavPageSize;
247 $NavLastRecordShow = $makeweight + ($this->NavPageCount - $this->NavPageNomer + 1) * $this->NavPageSize;
248 }
249 else
250 {
251 if ($this->NavPageSize > 0 && ($this->NavRecordCount % $this->NavPageSize > 0))
252 {
253 $this->NavPageCount++;
254 }
255
256 //calculate total pages depend on rows count. start with 1
257 $this->calculatePageNumber(1, true, (bool)($arNavStartParams["checkOutOfRange"] ?? false));
258 if ($this->NavPageNomer === null)
259 {
260 return null;
261 }
262
263 //rows to skip
264 $NavFirstRecordShow = $this->NavPageSize * ($this->NavPageNomer - 1);
265 $NavLastRecordShow = $this->NavPageSize * $this->NavPageNomer;
266 }
267
268 $NavAdditionalRecords = 0;
269 if (is_set($arNavStartParams, "iNavAddRecords"))
270 {
271 $NavAdditionalRecords = $arNavStartParams["iNavAddRecords"];
272 }
273
274 if (!$this->NavShowAll)
275 {
276 $strSql .= " LIMIT " . ($NavLastRecordShow - $NavFirstRecordShow + $NavAdditionalRecords) . " OFFSET " . $NavFirstRecordShow;
277 }
278
279 if (is_object($this->DB))
280 {
281 $res_tmp = $this->DB->Query($strSql, $bIgnoreErrors);
282 }
283 else
284 {
285 $res_tmp = $DB->Query($strSql, $bIgnoreErrors);
286 }
287
288 // Return false on sql errors (if $bIgnoreErrors == true)
289 if ($bIgnoreErrors && ($res_tmp === false))
290 {
291 return false;
292 }
293
294 $this->result = $res_tmp->result;
295 $this->DB = $res_tmp->DB;
296
297 if ($this->SqlTraceIndex)
298 {
299 $start_time = microtime(true);
300 }
301
302 $temp_arrray = [];
303 $temp_arrray_add = [];
304 $tmp_cnt = 0;
305
306 while ($ar = $this->FetchInternal())
307 {
308 $tmp_cnt++;
309 if (intval($NavLastRecordShow - $NavFirstRecordShow) > 0 && $tmp_cnt > ($NavLastRecordShow - $NavFirstRecordShow))
310 {
311 $temp_arrray_add[] = $ar;
312 }
313 else
314 {
315 $temp_arrray[] = $ar;
316 }
317 }
318
319 if ($this->SqlTraceIndex)
320 {
322 $exec_time = round(microtime(true) - $start_time, 10);
323 $DB->addDebugTime($this->SqlTraceIndex, $exec_time);
324 $DB->timeQuery += $exec_time;
325 }
326
327 $this->arResult = (!empty($temp_arrray) ? $temp_arrray : false);
328 $this->arResultAdd = (!empty($temp_arrray_add) ? $temp_arrray_add : false);
329 $this->nSelectedCount = $cnt;
330 $this->bDescPageNumbering = $bDescPageNumbering;
331 $this->bFromLimited = true;
332
333 return null;
334 }
335
339 public function NavContinue()
340 {
341 if (is_array($this->arResultAdd) && !empty($this->arResultAdd))
342 {
343 $this->arResult = $this->arResultAdd;
344 return true;
345 }
346 return false;
347 }
348
352 public function IsNavPrint()
353 {
354 if ($this->NavRecordCount == 0 || ($this->NavPageCount == 1 && !$this->NavShowAll))
355 {
356 return false;
357 }
358
359 return true;
360 }
361
362 public function NavPrint($title, $show_allways = false, $StyleText = "text", $template_path = false)
363 {
364 echo $this->GetNavPrint($title, $show_allways, $StyleText, $template_path);
365 }
366
367 public function GetNavPrint($title, $show_allways = false, $StyleText = "text", $template_path = false, $arDeleteParam = false)
368 {
369 $res = '';
371
372 $sBegin = GetMessage("nav_begin");
373 $sEnd = GetMessage("nav_end");
374 $sNext = GetMessage("nav_next");
375 $sPrev = GetMessage("nav_prev");
376 $sAll = GetMessage("nav_all");
377 $sPaged = GetMessage("nav_paged");
378
380
381 if (!$show_allways)
382 {
383 if ($this->NavRecordCount == 0 || ($this->NavPageCount == 1 && !$this->NavShowAll))
384 {
385 return '';
386 }
387 }
388
389 $sUrlPath = GetPagePath();
390
391 $arDel = ["PAGEN_" . $this->NavNum, "SIZEN_" . $this->NavNum, "SHOWALL_" . $this->NavNum, "PHPSESSID"];
392 if (is_array($arDeleteParam))
393 {
394 $arDel = array_merge($arDel, $arDeleteParam);
395 }
396 $strNavQueryString = DeleteParam($arDel);
397 if ($strNavQueryString <> "")
398 {
399 $strNavQueryString = htmlspecialcharsbx("&" . $strNavQueryString);
400 }
401
402 if ($template_path !== false && !file_exists($template_path) && file_exists($_SERVER["DOCUMENT_ROOT"] . $template_path))
403 {
404 $template_path = $_SERVER["DOCUMENT_ROOT"] . $template_path;
405 }
406
407 if ($this->bDescPageNumbering === true)
408 {
409 if ($this->NavPageNomer + floor($nPageWindow / 2) >= $this->NavPageCount)
410 {
412 }
413 else
414 {
415 if ($this->NavPageNomer + floor($nPageWindow / 2) >= $nPageWindow)
416 {
417 $nStartPage = $this->NavPageNomer + floor($nPageWindow / 2);
418 }
419 else
420 {
421 if ($this->NavPageCount >= $nPageWindow)
422 {
424 }
425 else
426 {
428 }
429 }
430 }
431
432 if ($nStartPage - $nPageWindow >= 0)
433 {
435 }
436 else
437 {
438 $nEndPage = 1;
439 }
440 //echo "nEndPage = $nEndPage; nStartPage = $nStartPage;";
441 }
442 else
443 {
444 if ($this->NavPageNomer > floor($nPageWindow / 2) + 1 && $this->NavPageCount > $nPageWindow)
445 {
446 $nStartPage = $this->NavPageNomer - floor($nPageWindow / 2);
447 }
448 else
449 {
450 $nStartPage = 1;
451 }
452
453 if ($this->NavPageNomer <= $this->NavPageCount - floor($nPageWindow / 2) && $nStartPage + $nPageWindow - 1 <= $this->NavPageCount)
454 {
456 }
457 else
458 {
460 if ($nEndPage - $nPageWindow + 1 >= 1)
461 {
463 }
464 }
465 }
466
467 $this->nStartPage = $nStartPage;
468 $this->nEndPage = $nEndPage;
469
470 if ($template_path !== false && file_exists($template_path))
471 {
472 /*
473 $this->bFirstPrintNav - is first tiem call
474 $this->NavPageNomer - number of current page
475 $this->NavPageCount - total page count
476 $this->NavPageSize - page size
477 $this->NavRecordCount - records count
478 $this->bShowAll - show "all" link
479 $this->NavShowAll - is all shown
480 $this->NavNum - number of navigation
481 $this->bDescPageNumbering - reverse paging
482
483 $this->nStartPage - first page in chain
484 $this->nEndPage - last page in chain
485
486 $strNavQueryString - query string
487 $sUrlPath - current url
488
489 Url for link to the page #PAGE_NUMBER#:
490 $sUrlPath.'?PAGEN_'.$this->NavNum.'='.#PAGE_NUMBER#.$strNavQueryString.'#nav_start"'.$add_anchor
491 */
492
493 ob_start();
494 include($template_path);
495 $res = ob_get_contents();
496 ob_end_clean();
497 $this->bFirstPrintNav = false;
498 return $res;
499 }
500
501 if ($this->bFirstPrintNav)
502 {
503 $res .= '<a name="nav_start' . $add_anchor . '"></a>';
504 $this->bFirstPrintNav = false;
505 }
506
507 $res .= '<font class="' . $StyleText . '">' . $title . ' ';
508 if ($this->bDescPageNumbering === true)
509 {
510 $makeweight = ($this->NavRecordCount % $this->NavPageSize);
511 $NavFirstRecordShow = 0;
512 if ($this->NavPageNomer != $this->NavPageCount)
513 {
514 $NavFirstRecordShow += $makeweight;
515 }
516
517 $NavFirstRecordShow += ($this->NavPageCount - $this->NavPageNomer) * $this->NavPageSize + 1;
518
519 if ($this->NavPageCount == 1)
520 {
521 $NavLastRecordShow = $this->NavRecordCount;
522 }
523 else
524 {
525 $NavLastRecordShow = $makeweight + ($this->NavPageCount - $this->NavPageNomer + 1) * $this->NavPageSize;
526 }
527
528 $res .= $NavFirstRecordShow;
529 $res .= ' - ' . $NavLastRecordShow;
530 $res .= ' ' . GetMessage("nav_of") . ' ';
532 $res .= "\n<br>\n</font>";
533
534 $res .= '<font class="' . $StyleText . '">';
535
536 if ($this->NavPageNomer < $this->NavPageCount)
537 {
538 $res .= '<a href="' . $sUrlPath . '?PAGEN_' . $this->NavNum . '=' . $this->NavPageCount . $strNavQueryString . '#nav_start' . $add_anchor . '">' . $sBegin . '</a>&nbsp;|&nbsp;<a href="' . $sUrlPath . '?PAGEN_' . $this->NavNum . '=' . ($this->NavPageNomer + 1) . $strNavQueryString . '#nav_start' . $add_anchor . '">' . $sPrev . '</a>';
539 }
540 else
541 {
542 $res .= $sBegin . '&nbsp;|&nbsp;' . $sPrev;
543 }
544
545 $res .= '&nbsp;|&nbsp;';
546
547 $NavRecordGroup = $nStartPage;
548 while ($NavRecordGroup >= $nEndPage)
549 {
550 $NavRecordGroupPrint = $this->NavPageCount - $NavRecordGroup + 1;
551 if ($NavRecordGroup == $this->NavPageNomer)
552 {
553 $res .= '<b>' . $NavRecordGroupPrint . '</b>&nbsp';
554 }
555 else
556 {
557 $res .= '<a href="' . $sUrlPath . '?PAGEN_' . $this->NavNum . '=' . $NavRecordGroup . $strNavQueryString . '#nav_start' . $add_anchor . '">' . $NavRecordGroupPrint . '</a>&nbsp;';
558 }
559 $NavRecordGroup--;
560 }
561 $res .= '|&nbsp;';
562 if ($this->NavPageNomer > 1)
563 {
564 $res .= '<a href="' . $sUrlPath . '?PAGEN_' . $this->NavNum . '=' . ($this->NavPageNomer - 1) . $strNavQueryString . '#nav_start' . $add_anchor . '">' . $sNext . '</a>&nbsp;|&nbsp;<a href="' . $sUrlPath . '?PAGEN_' . $this->NavNum . '=1' . $strNavQueryString . '#nav_start' . $add_anchor . '">' . $sEnd . '</a>&nbsp;';
565 }
566 else
567 {
568 $res .= $sNext . '&nbsp;|&nbsp;' . $sEnd . '&nbsp;';
569 }
570 }
571 else
572 {
573 $res .= ($this->NavPageNomer - 1) * $this->NavPageSize + 1;
574 $res .= ' - ';
575 if ($this->NavPageNomer != $this->NavPageCount)
576 {
577 $res .= $this->NavPageNomer * $this->NavPageSize;
578 }
579 else
580 {
582 }
583 $res .= ' ' . GetMessage("nav_of") . ' ';
585 $res .= "\n<br>\n</font>";
586
587 $res .= '<font class="' . $StyleText . '">';
588
589 if ($this->NavPageNomer > 1)
590 {
591 $res .= '<a href="' . $sUrlPath . '?PAGEN_' . $this->NavNum . '=1' . $strNavQueryString . '#nav_start' . $add_anchor . '">' . $sBegin . '</a>&nbsp;|&nbsp;<a href="' . $sUrlPath . '?PAGEN_' . $this->NavNum . '=' . ($this->NavPageNomer - 1) . $strNavQueryString . '#nav_start' . $add_anchor . '">' . $sPrev . '</a>';
592 }
593 else
594 {
595 $res .= $sBegin . '&nbsp;|&nbsp;' . $sPrev;
596 }
597
598 $res .= '&nbsp;|&nbsp;';
599
600 $NavRecordGroup = $nStartPage;
601 while ($NavRecordGroup <= $nEndPage)
602 {
603 if ($NavRecordGroup == $this->NavPageNomer)
604 {
605 $res .= '<b>' . $NavRecordGroup . '</b>&nbsp';
606 }
607 else
608 {
609 $res .= '<a href="' . $sUrlPath . '?PAGEN_' . $this->NavNum . '=' . $NavRecordGroup . $strNavQueryString . '#nav_start' . $add_anchor . '">' . $NavRecordGroup . '</a>&nbsp;';
610 }
611 $NavRecordGroup++;
612 }
613 $res .= '|&nbsp;';
614 if ($this->NavPageNomer < $this->NavPageCount)
615 {
616 $res .= '<a href="' . $sUrlPath . '?PAGEN_' . $this->NavNum . '=' . ($this->NavPageNomer + 1) . $strNavQueryString . '#nav_start' . $add_anchor . '">' . $sNext . '</a>&nbsp;|&nbsp;<a href="' . $sUrlPath . '?PAGEN_' . $this->NavNum . '=' . $this->NavPageCount . $strNavQueryString . '#nav_start' . $add_anchor . '">' . $sEnd . '</a>&nbsp;';
617 }
618 else
619 {
620 $res .= $sNext . '&nbsp;|&nbsp;' . $sEnd . '&nbsp;';
621 }
622 }
623
624 if ($this->bShowAll)
625 {
626 $res .= $this->NavShowAll ? '|&nbsp;<a href="' . $sUrlPath . '?SHOWALL_' . $this->NavNum . '=0' . $strNavQueryString . '#nav_start' . $add_anchor . '">' . $sPaged . '</a>&nbsp;' : '|&nbsp;<a href="' . $sUrlPath . '?SHOWALL_' . $this->NavNum . '=1' . $strNavQueryString . '#nav_start' . $add_anchor . '">' . $sAll . '</a>&nbsp;';
627 }
628
629 $res .= '</font>';
630 return $res;
631 }
632
633 public function ExtractFields($strPrefix = "str_", $bDoEncode = true)
634 {
635 return $this->NavNext(true, $strPrefix, $bDoEncode);
636 }
637
638 public function ExtractEditFields($strPrefix = "str_")
639 {
640 return $this->NavNext(true, $strPrefix, true, false);
641 }
642
643 public function GetNext($bTextHtmlAuto = true, $use_tilda = true)
644 {
645 if ($arRes = $this->Fetch())
646 {
647 if (!$this->arGetNextCache)
648 {
649 $this->arGetNextCache = [];
650 foreach ($arRes as $FName => $arFValue)
651 {
652 $this->arGetNextCache[$FName] = array_key_exists($FName . "_TYPE", $arRes);
653 }
654 }
655 if ($use_tilda)
656 {
657 $arTilda = [];
658 foreach ($arRes as $FName => $arFValue)
659 {
660 if (isset($this->arGetNextCache[$FName]) && $this->arGetNextCache[$FName] && $bTextHtmlAuto)
661 {
662 $arTilda[$FName] = FormatText($arFValue, $arRes[$FName . "_TYPE"]);
663 }
664 elseif (is_array($arFValue))
665 {
666 $arTilda[$FName] = htmlspecialcharsEx($arFValue);
667 }
668 elseif ($arFValue != '' && preg_match("/[;&<>\"]/", $arFValue))
669 {
670 $arTilda[$FName] = htmlspecialcharsEx($arFValue);
671 }
672 else
673 {
674 $arTilda[$FName] = $arFValue;
675 }
676 $arTilda["~" . $FName] = $arFValue;
677 }
678 return $arTilda;
679 }
680 else
681 {
682 foreach ($arRes as $FName => $arFValue)
683 {
684 if ($this->arGetNextCache[$FName] && $bTextHtmlAuto)
685 {
686 $arRes[$FName] = FormatText($arFValue, $arRes[$FName . "_TYPE"]);
687 }
688 elseif (is_array($arFValue))
689 {
690 $arRes[$FName] = htmlspecialcharsEx($arFValue);
691 }
692 elseif (preg_match("/[;&<>\"]/", $arFValue))
693 {
694 $arRes[$FName] = htmlspecialcharsEx($arFValue);
695 }
696 }
697 }
698 }
699 return $arRes;
700 }
701
702 public static function NavStringForCache($nPageSize = 0, $bShowAll = true, $iNumPage = false)
703 {
704 $NavParams = CDBResult::GetNavParams($nPageSize, $bShowAll, $iNumPage);
705 return "|" . ($NavParams["SHOW_ALL"] ? "" : $NavParams["PAGEN"]) . "|" . $NavParams["SHOW_ALL"] . "|";
706 }
707
708 public static function GetNavParams($nPageSize = 0, $bShowAll = true, $iNumPage = false)
709 {
711 global $NavNum, $APPLICATION;
712
713 $bDescPageNumbering = false; //it can be extracted from $nPageSize
714
715 if (is_array($nPageSize))
716 {
717 $params = $nPageSize;
718 if (isset($params["iNumPage"]))
719 {
720 $iNumPage = $params["iNumPage"];
721 }
722 if (isset($params["nPageSize"]))
723 {
724 $nPageSize = $params["nPageSize"];
725 }
726 if (isset($params["bDescPageNumbering"]))
727 {
728 $bDescPageNumbering = $params["bDescPageNumbering"];
729 }
730 if (isset($params["bShowAll"]))
731 {
732 $bShowAll = $params["bShowAll"];
733 }
734 if (isset($params["NavShowAll"]))
735 {
736 $NavShowAll = $params["NavShowAll"];
737 }
738 if (isset($params["sNavID"]))
739 {
740 $sNavID = $params["sNavID"];
741 }
742 }
743
744 $nPageSize = intval($nPageSize);
745 $NavNum = intval($NavNum);
746
747 $PAGEN_NAME = "PAGEN_" . ($NavNum + 1);
748 $SHOWALL_NAME = "SHOWALL_" . ($NavNum + 1);
749
750 global ${$PAGEN_NAME}, ${$SHOWALL_NAME};
751
752 if ($iNumPage === false)
753 {
754 $PAGEN = ${$PAGEN_NAME} ?? 0;
755 }
756 else
757 {
758 $PAGEN = $iNumPage;
759 }
760
761 $PAGEN = (int)$PAGEN;
762 $SHOWALL = ${$SHOWALL_NAME};
763
765
766 $inSession = (CPageOption::GetOptionString("main", "nav_page_in_session", "Y") == "Y") && $application->getKernelSession()->isStarted();
767
768 if ($inSession)
769 {
770 $md5Path = md5($sNavID ?? $APPLICATION->GetCurPage());
771 $SESS_PAGEN = $md5Path . "SESS_PAGEN_" . ($NavNum + 1);
772 $SESS_ALL = $md5Path . "SESS_ALL_" . ($NavNum + 1);
773
774 $localStorage = $application->getLocalSession('navigation');
775 $session = $localStorage->getData();
776 }
777
778 if ($PAGEN <= 0)
779 {
780 if ($inSession && isset($session[$SESS_PAGEN]) && $session[$SESS_PAGEN] > 0)
781 {
782 $PAGEN = $session[$SESS_PAGEN];
783 }
784 elseif ($bDescPageNumbering === true)
785 {
786 $PAGEN = 0;
787 }
788 else
789 {
790 $PAGEN = 1;
791 }
792 }
793
794 //Number of records on a page
795 $SIZEN = $nPageSize;
796 if ($SIZEN < 1)
797 {
798 $SIZEN = 10;
799 }
800
801 //Show all records
802 $SHOW_ALL = ($bShowAll && (isset($SHOWALL) ? ($SHOWALL == 1) : ($inSession && isset($session[$SESS_ALL]) && $session[$SESS_ALL] == 1)));
803
804 //$NavShowAll comes from $nPageSize array
805 $res = [
806 "PAGEN" => $PAGEN,
807 "SIZEN" => $SIZEN,
808 "SHOW_ALL" => ($NavShowAll ?? $SHOW_ALL),
809 ];
810
811 if ($inSession)
812 {
813 $localStorage->set($SESS_PAGEN, $PAGEN);
814 $localStorage->set($SESS_ALL, $SHOW_ALL);
815 $res["SESS_PAGEN"] = $SESS_PAGEN;
816 $res["SESS_ALL"] = $SESS_ALL;
817 }
818
819 return $res;
820 }
821
822 public function InitNavStartVars($nPageSize = 0, $bShowAll = true, $iNumPage = false)
823 {
824 if (is_array($nPageSize) && isset($nPageSize["bShowAll"]))
825 {
826 $this->bShowAll = $nPageSize["bShowAll"];
827 }
828 else
829 {
830 $this->bShowAll = $bShowAll;
831 }
832
833 $this->bNavStart = true;
834
835 $arParams = self::GetNavParams($nPageSize, $bShowAll, $iNumPage);
836
837 $this->PAGEN = $arParams["PAGEN"];
838 $this->SIZEN = $arParams["SIZEN"];
839 $this->NavShowAll = $arParams["SHOW_ALL"];
840 $this->NavPageSize = $arParams["SIZEN"];
841 $this->SESS_SIZEN = $arParams["SESS_SIZEN"] ?? null;
842 $this->SESS_PAGEN = $arParams["SESS_PAGEN"] ?? null;
843 $this->SESS_ALL = $arParams["SESS_ALL"] ?? null;
844
845 global $NavNum;
846
847 $NavNum++;
848 $this->NavNum = $NavNum;
849
850 if ($this->NavNum > 1)
851 {
853 }
854 else
855 {
856 $add_anchor = "";
857 }
858
859 $this->add_anchor = $add_anchor;
860 }
861
862 public function NavStart($nPageSize = 0, $bShowAll = true, $iNumPage = false)
863 {
864 if ($this->bFromLimited)
865 {
866 return;
867 }
868
869 if (is_array($nPageSize))
870 {
871 $this->InitNavStartVars($nPageSize);
872 }
873 else
874 {
875 $this->InitNavStartVars(intval($nPageSize), $bShowAll, $iNumPage);
876 }
877
878 if ($this->bFromArray)
879 {
880 $this->NavRecordCount = count($this->arResult);
881 if ($this->NavRecordCount < 1)
882 {
883 return;
884 }
885
886 if ($this->NavShowAll)
887 {
888 $this->NavPageSize = $this->NavRecordCount;
889 }
890
891 $this->NavPageCount = floor($this->NavRecordCount / $this->NavPageSize);
892 if ($this->NavRecordCount % $this->NavPageSize > 0)
893 {
894 $this->NavPageCount++;
895 }
896
897 $useSession = (CPageOption::GetOptionString("main", "nav_page_in_session", "Y") == "Y");
898 $this->calculatePageNumber(1, $useSession);
899
900 $NavFirstRecordShow = $this->NavPageSize * ($this->NavPageNomer - 1);
901 $NavLastRecordShow = $this->NavPageSize * $this->NavPageNomer;
902
903 $this->arResult = array_slice($this->arResult, $NavFirstRecordShow, $NavLastRecordShow - $NavFirstRecordShow);
904 }
905 else
906 {
907 $this->DBNavStart();
908 }
909 }
910
911 protected function calculatePageNumber(int $defaultNumber = 1, bool $useSession = true, bool $checkOutOfRange = false)
912 {
914
915 $correct = false;
916 if ($this->PAGEN > 0 && $this->PAGEN <= $this->NavPageCount)
917 {
918 $this->NavPageNomer = $this->PAGEN;
919 $correct = true;
920 }
921 elseif ($useSession && $this->SESS_PAGEN && $application->getKernelSession()->isStarted())
922 {
923 $localStorage = $application->getLocalSession('navigation');
924 $session = $localStorage->getData();
925
926 if ($session[$this->SESS_PAGEN] > 0 && $session[$this->SESS_PAGEN] <= $this->NavPageCount)
927 {
928 $this->NavPageNomer = $session[$this->SESS_PAGEN];
929 $correct = true;
930 }
931 }
932
933 if (!$correct)
934 {
935 if ($checkOutOfRange !== true)
936 {
937 $this->NavPageNomer = $defaultNumber;
938 }
939 else
940 {
941 $this->NavPageNomer = null;
942 }
943 }
944 }
945
946 function DBNavStart()
947 {
948 global $DB;
949
950 //total rows count
951 if (($count = $this->GetRowsCount()) !== null)
952 {
953 $this->NavRecordCount = $count;
954 }
955 else
956 {
957 return;
958 }
959
960 if ($this->NavRecordCount < 1)
961 {
962 return;
963 }
964
965 if ($this->NavShowAll)
966 {
967 $this->NavPageSize = $this->NavRecordCount;
968 }
969
970 //calculate total pages depend on rows count. start with 1
971 $this->NavPageCount = floor($this->NavRecordCount / $this->NavPageSize);
972 if ($this->NavRecordCount % $this->NavPageSize > 0)
973 {
974 $this->NavPageCount++;
975 }
976
977 //page number to display. start with 1
978 $this->calculatePageNumber();
979
980 //rows to skip
981 $NavFirstRecordShow = $this->NavPageSize * ($this->NavPageNomer - 1);
982 $NavLastRecordShow = $this->NavPageSize * $this->NavPageNomer;
983
984 if ($this->SqlTraceIndex)
985 {
986 $start_time = microtime(true);
987 }
988
989 $this->Seek($NavFirstRecordShow);
990
991 $this->arResult = [];
992 for ($i = $NavFirstRecordShow; $i < $NavLastRecordShow; $i++)
993 {
994 if (($res = $this->FetchInternal()))
995 {
996 $this->arResult[] = $res;
997 }
998 else
999 {
1000 break;
1001 }
1002 }
1003
1004 if ($this->SqlTraceIndex)
1005 {
1007 $exec_time = round(microtime(true) - $start_time, 10);
1008 $DB->addDebugTime($this->SqlTraceIndex, $exec_time);
1009 $DB->timeQuery += $exec_time;
1010 }
1011 }
1012
1013 public function InitFromArray($arr)
1014 {
1015 if (is_array($arr))
1016 {
1017 reset($arr);
1018 $this->nSelectedCount = count($arr);
1019 }
1020 else
1021 {
1022 $this->nSelectedCount = false;
1023 }
1024
1025 $this->arResult = $arr;
1026 $this->bFromArray = true;
1027 }
1028
1029 public function NavNext($bSetGlobalVars = true, $strPrefix = "str_", $bDoEncode = true, $bSkipEntities = true)
1030 {
1031 $arr = $this->Fetch();
1032 if ($arr && $bSetGlobalVars)
1033 {
1034 foreach ($arr as $key => $val)
1035 {
1036 $varname = $strPrefix . $key;
1037 global $$varname;
1038
1039 if ($bDoEncode && !is_array($val) && !is_object($val))
1040 {
1041 if ($bSkipEntities)
1042 {
1043 $$varname = htmlspecialcharsEx($val);
1044 }
1045 else
1046 {
1047 $$varname = htmlspecialcharsbx($val);
1048 }
1049 }
1050 else
1051 {
1052 $$varname = $val;
1053 }
1054 }
1055 }
1056 return $arr;
1057 }
1058
1059 public function GetPageNavString($navigationTitle, $templateName = "", $showAlways = false, $parentComponent = null)
1060 {
1061 return $this->GetPageNavStringEx($dummy, $navigationTitle, $templateName, $showAlways, $parentComponent);
1062 }
1063
1064 public function GetPageNavStringEx(&$navComponentObject, $navigationTitle, $templateName = "", $showAlways = false, $parentComponent = null, $componentParams = [])
1065 {
1067 global $APPLICATION;
1068
1069 ob_start();
1070
1071 $params = array_merge(
1072 [
1073 "NAV_TITLE" => $navigationTitle,
1074 "NAV_RESULT" => $this,
1075 "SHOW_ALWAYS" => $showAlways,
1076 ],
1078 );
1079
1080 $navComponentObject = $APPLICATION->IncludeComponent(
1081 "bitrix:system.pagenavigation",
1082 $templateName,
1083 $params,
1084 $parentComponent,
1085 [
1086 "HIDE_ICONS" => "Y",
1087 ]
1088 );
1089
1090 $result = ob_get_contents();
1091 ob_end_clean();
1092
1093 return $result;
1094 }
1095
1097 {
1098 $this->usedUserFields = false;
1099
1100 if (is_array($arUserFields))
1101 {
1102 $this->arUserFields = $arUserFields;
1103 }
1104 else
1105 {
1106 $this->arUserFields = false;
1107 }
1108 }
1109
1110 protected function AfterFetch(&$res)
1111 {
1112 global $USER_FIELD_MANAGER;
1113
1114 if ($this->arUserFields)
1115 {
1116 //Cache actual user fields on first fetch
1117 if ($this->usedUserFields === false)
1118 {
1119 $this->usedUserFields = [];
1120 foreach ($this->arUserFields as $userField)
1121 {
1122 if (isset($userField['FIELD_NAME']) && array_key_exists($userField['FIELD_NAME'], $res))
1123 {
1124 $this->usedUserFields[] = $userField;
1125 }
1126 }
1127 }
1128 // We need to call OnAfterFetch for each user field
1129 foreach ($this->usedUserFields as $userField)
1130 {
1131 $name = $userField['FIELD_NAME'];
1132 if ($userField['MULTIPLE'] === 'Y')
1133 {
1134 if ($res[$name] !== null)
1135 {
1136 if (!str_starts_with($res[$name], 'a') && $res[$name] > 0)
1137 {
1138 $res[$name] = $USER_FIELD_MANAGER->LoadMultipleValues($userField, $res[$name]);
1139 }
1140 else
1141 {
1142 $res[$name] = unserialize($res[$name], ['allowed_classes' => false]);
1143 }
1144 }
1145 else
1146 {
1147 $res[$name] = false;
1148 }
1149 }
1150 $res[$name] = $USER_FIELD_MANAGER->OnAfterFetch($userField, $res[$name]);
1151 }
1152 }
1153
1154 if ($this->arReplacedAliases)
1155 {
1156 foreach ($this->arReplacedAliases as $tech => $human)
1157 {
1158 $res[$human] = $res[$tech];
1159 unset($res[$tech]);
1160 }
1161 }
1162 }
1163}
$arParams
Определения access_dialog.php:21
$count
Определения admin_tab.php:4
global $APPLICATION
Определения include.php:80
static getInstance()
Определения application.php:98
Определения dbresult.php:15
$NavNum
Определения dbresult.php:22
$nEndPage
Определения dbresult.php:44
$result
Определения dbresult.php:16
$SESS_ALL
Определения dbresult.php:25
$bNavStart
Определения dbresult.php:20
$bFirstPrintNav
Определения dbresult.php:23
$arResult
Определения dbresult.php:17
$arUserFields
Определения dbresult.php:35
$arResultAdd
Определения dbresult.php:19
$SIZEN
Определения dbresult.php:24
$bFromLimited
Определения dbresult.php:29
Seek(int $offset)
AfterFetch(&$res)
Определения dbresult.php:1110
GetNavPrint($title, $show_allways=false, $StyleText="text", $template_path=false, $arDeleteParam=false)
Определения dbresult.php:367
SetUserFields($arUserFields)
Определения dbresult.php:1096
$bFromArray
Определения dbresult.php:28
FetchInternal()
Определения dbresult.php:168
$nPageWindow
Определения dbresult.php:30
FieldName($iCol)
NavQuery($strSql, $cnt, $arNavStartParams, $bIgnoreErrors=false)
Определения dbresult.php:202
$NavShowAll
Определения dbresult.php:22
$NavPageCount
Определения dbresult.php:22
$PAGEN
Определения dbresult.php:24
$SESS_SIZEN
Определения dbresult.php:25
ExtractEditFields($strPrefix="str_")
Определения dbresult.php:638
GetPageNavStringEx(&$navComponentObject, $navigationTitle, $templateName="", $showAlways=false, $parentComponent=null, $componentParams=[])
Определения dbresult.php:1064
$nStartPage
Определения dbresult.php:43
$resultObject
Определения dbresult.php:46
static GetNavParams($nPageSize=0, $bShowAll=true, $iNumPage=false)
Определения dbresult.php:708
$bShowAll
Определения dbresult.php:21
Fetch()
Определения dbresult.php:129
$DB
Определения dbresult.php:40
$usedUserFields
Определения dbresult.php:36
ExtractFields($strPrefix="str_", $bDoEncode=true)
Определения dbresult.php:633
NavPrint($title, $show_allways=false, $StyleText="text", $template_path=false)
Определения dbresult.php:362
NavStart($nPageSize=0, $bShowAll=true, $iNumPage=false)
Определения dbresult.php:862
NavNext($bSetGlobalVars=true, $strPrefix="str_", $bDoEncode=true, $bSkipEntities=true)
Определения dbresult.php:1029
$SqlTraceIndex
Определения dbresult.php:38
InitNavStartVars($nPageSize=0, $bShowAll=true, $iNumPage=false)
Определения dbresult.php:822
__sleep()
Определения dbresult.php:96
InitFromArray($arr)
Определения dbresult.php:1013
IsNavPrint()
Определения dbresult.php:352
GetNext($bTextHtmlAuto=true, $use_tilda=true)
Определения dbresult.php:643
$NavRecordCount
Определения dbresult.php:22
$arReplacedAliases
Определения dbresult.php:18
calculatePageNumber(int $defaultNumber=1, bool $useSession=true, bool $checkOutOfRange=false)
Определения dbresult.php:911
static NavStringForCache($nPageSize=0, $bShowAll=true, $iNumPage=false)
Определения dbresult.php:702
$NavPageSize
Определения dbresult.php:22
$is_filtered
Определения dbresult.php:42
__construct($res=null)
Определения dbresult.php:49
GetPageNavString($navigationTitle, $templateName="", $showAlways=false, $parentComponent=null)
Определения dbresult.php:1059
$add_anchor
Определения dbresult.php:26
$bPostNavigation
Определения dbresult.php:27
$bDescPageNumbering
Определения dbresult.php:33
DBNavStart()
Определения dbresult.php:946
$SESS_PAGEN
Определения dbresult.php:25
$NavPageNomer
Определения dbresult.php:22
NavContinue()
Определения dbresult.php:339
$arGetNextCache
Определения dbresult.php:32
$nSelectedCount
Определения dbresult.php:31
$NavRecordCountChangeDisable
Определения dbresult.php:41
static GetOptionString($module_id, $name, $def="", $site=false)
Определения pageoption.php:10
$start_time
Определения clock_selector.php:9
$arr
Определения file_new.php:624
$res
Определения filter_act.php:7
global $USER_FIELD_MANAGER
Определения attempt.php:6
$componentParams
Определения group_wiki_index.php:20
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
$application
Определения bitrix.php:23
FormatText($strText, $strTextType="text")
Определения tools.php:2675
GetPagePath($page=false, $get_index_page=null)
Определения tools.php:3139
DeleteParam($ParamNames)
Определения tools.php:4548
htmlspecialcharsEx($str)
Определения tools.php:2685
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$name
Определения menu_edit.php:35
Определения arrayresult.php:2
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$title
Определения pdf.php:123
$val
Определения options.php:1793
$arRes
Определения options.php:104