Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
paginator.php
1<?php
2namespace Bitrix\Main\DB;
10{
24 public static function query($sql, Connection $connection, $numberOfRecords, $pageNumber, $numberOfRecordsPerPage, $backward = false)
25 {
26 list($offset, $limit) = self::calculateQueryLimits(
27 $numberOfRecords, $pageNumber, $numberOfRecordsPerPage, $backward
28 );
29
30 return $connection->query($sql, $offset, $limit);
31 }
32
43 public static function calculateQueryLimits($numberOfRecords, $pageNumber, $numberOfRecordsPerPage, $backward)
44 {
45 $pageNumber = intval($pageNumber);
46 $numberOfRecords = intval($numberOfRecords);
47
48 $numberOfRecordsPerPage = intval($numberOfRecordsPerPage);
49 if ($numberOfRecordsPerPage <= 0)
50 $numberOfRecordsPerPage = 10;
51
52 $pageCount = floor($numberOfRecords / $numberOfRecordsPerPage);
53 if ($backward)
54 {
55 $makeweight = ($numberOfRecords % $numberOfRecordsPerPage);
56 if ($pageCount == 0 && $makeweight > 0)
57 $pageCount = 1;
58
59 if ($pageNumber < 1)
60 $pageNumber = 1;
61 if ($pageNumber > $pageCount)
62 $pageNumber = $pageCount;
63
64 $firstRecordToShow = 0;
65 if ($pageNumber != $pageCount)
66 $firstRecordToShow += $makeweight;
67
68 $firstRecordToShow += ($pageCount - $pageNumber) * $numberOfRecordsPerPage;
69 $lastRecordToShow = $makeweight + ($pageCount - $pageNumber + 1) * $numberOfRecordsPerPage;
70 }
71 else
72 {
73 if ($numberOfRecordsPerPage && ($numberOfRecords % $numberOfRecordsPerPage > 0))
74 $pageCount++;
75
76 if ($pageNumber < 1)
77 $pageNumber = 1;
78 if ($pageNumber > $pageCount)
79 $pageNumber = $pageCount;
80
81 $firstRecordToShow = $numberOfRecordsPerPage * ($pageNumber - 1);
82 $lastRecordToShow = $numberOfRecordsPerPage * $pageNumber;
83 }
84
85 return array($firstRecordToShow, $lastRecordToShow - $firstRecordToShow);
86 }
87}
static query($sql, Connection $connection, $numberOfRecords, $pageNumber, $numberOfRecordsPerPage, $backward=false)
Definition paginator.php:24
static calculateQueryLimits($numberOfRecords, $pageNumber, $numberOfRecordsPerPage, $backward)
Definition paginator.php:43