4 * A query class which uses offset/limit paging. Provides logic and accessors
5 * for offsets and limits.
7 abstract class PhabricatorOffsetPagedQuery
extends PhabricatorQuery
{
12 final public function setOffset($offset) {
13 $this->offset
= $offset;
17 final public function setLimit($limit) {
18 $this->limit
= $limit;
22 final public function getOffset() {
26 final public function getLimit() {
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
);
38 return qsprintf($conn, '');
42 final public function executeWithOffsetPager(PHUIPagerView
$pager) {
43 $this->setLimit($pager->getPageSize() +
1);
44 $this->setOffset($pager->getOffset());
46 $results = $this->execute();
48 return $pager->sliceResults($results);