forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorOffsetPagedQuery.php
51 lines (40 loc) · 1.21 KB
/
PhabricatorOffsetPagedQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?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);
}
}