1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-18 18:51:12 +01:00
phorge-phorge/src/infrastructure/query/PhabricatorOffsetPagedQuery.php
epriestley 98690ee326 Update many Phabricator queries for new %Q query semantics
Summary: Depends on D19785. Ref T13217. This converts many of the most common clause construction pathways to the new %Q / %LQ / %LO / %LA / %LJ semantics.

Test Plan: Browsed around a bunch, saw fewer warnings and no obvious behavioral errors. The transformations here are generally mechanical (although I did them by hand).

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: hach-que

Maniphest Tasks: T13217

Differential Revision: https://secure.phabricator.com/D19789
2018-11-15 03:48:10 -08:00

51 lines
1.2 KiB
PHP

<?php
/**
* A query class which uses offset/limit paging. Provides logic and accessors
* for offsets and limits.
*/
abstract class PhabricatorOffsetPagedQuery extends PhabricatorQuery {
private $offset;
private $limit;
final public function setOffset($offset) {
$this->offset = $offset;
return $this;
}
final public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
final public function getOffset() {
return $this->offset;
}
final public function getLimit() {
return $this->limit;
}
protected function buildLimitClause(AphrontDatabaseConnection $conn) {
if ($this->limit && $this->offset) {
return qsprintf($conn, 'LIMIT %d, %d', $this->offset, $this->limit);
} else if ($this->limit) {
return qsprintf($conn, 'LIMIT %d', $this->limit);
} else if ($this->offset) {
return qsprintf($conn, 'LIMIT %d, %d', $this->offset, PHP_INT_MAX);
} else {
return qsprintf($conn, '');
}
}
final public function executeWithOffsetPager(PHUIPagerView $pager) {
$this->setLimit($pager->getPageSize() + 1);
$this->setOffset($pager->getOffset());
$results = $this->execute();
return $pager->sliceResults($results);
}
}