@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * A query class which uses offset/limit paging. Provides logic and accessors
5 * for offsets and limits.
6 */
7abstract class PhabricatorOffsetPagedQuery extends PhabricatorQuery {
8
9 private $offset;
10 private $limit;
11
12 final public function setOffset($offset) {
13 $this->offset = $offset;
14 return $this;
15 }
16
17 final public function setLimit($limit) {
18 $this->limit = $limit;
19 return $this;
20 }
21
22 final public function getOffset() {
23 return $this->offset;
24 }
25
26 final public function getLimit() {
27 return $this->limit;
28 }
29
30 protected function buildLimitClause(AphrontDatabaseConnection $conn) {
31 if ($this->limit && $this->offset) {
32 return qsprintf($conn, 'LIMIT %d, %d', $this->offset, $this->limit);
33 } else if ($this->limit) {
34 return qsprintf($conn, 'LIMIT %d', $this->limit);
35 } else if ($this->offset) {
36 return qsprintf($conn, 'LIMIT %d, %d', $this->offset, PHP_INT_MAX);
37 } else {
38 return qsprintf($conn, '');
39 }
40 }
41
42 final public function executeWithOffsetPager(PHUIPagerView $pager) {
43 $this->setLimit($pager->getPageSize() + 1);
44 $this->setOffset($pager->getOffset());
45
46 $results = $this->execute();
47
48 return $pager->sliceResults($results);
49 }
50
51}