24 public static function query($sql,
Connection $connection, $numberOfRecords, $pageNumber, $numberOfRecordsPerPage, $backward =
false)
27 $numberOfRecords, $pageNumber, $numberOfRecordsPerPage, $backward
30 return $connection->query($sql, $offset, $limit);
43 public static function calculateQueryLimits($numberOfRecords, $pageNumber, $numberOfRecordsPerPage, $backward)
45 $pageNumber = intval($pageNumber);
46 $numberOfRecords = intval($numberOfRecords);
48 $numberOfRecordsPerPage = intval($numberOfRecordsPerPage);
49 if ($numberOfRecordsPerPage <= 0)
50 $numberOfRecordsPerPage = 10;
52 $pageCount = floor($numberOfRecords / $numberOfRecordsPerPage);
55 $makeweight = ($numberOfRecords % $numberOfRecordsPerPage);
56 if ($pageCount == 0 && $makeweight > 0)
61 if ($pageNumber > $pageCount)
62 $pageNumber = $pageCount;
64 $firstRecordToShow = 0;
65 if ($pageNumber != $pageCount)
66 $firstRecordToShow += $makeweight;
68 $firstRecordToShow += ($pageCount - $pageNumber) * $numberOfRecordsPerPage;
69 $lastRecordToShow = $makeweight + ($pageCount - $pageNumber + 1) * $numberOfRecordsPerPage;
73 if ($numberOfRecordsPerPage && ($numberOfRecords % $numberOfRecordsPerPage > 0))
78 if ($pageNumber > $pageCount)
79 $pageNumber = $pageCount;
81 $firstRecordToShow = $numberOfRecordsPerPage * ($pageNumber - 1);
82 $lastRecordToShow = $numberOfRecordsPerPage * $pageNumber;
85 return array($firstRecordToShow, $lastRecordToShow - $firstRecordToShow);