[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/infrastructure/query/ -> PhabricatorOffsetPagedQuery.php (source)

   1  <?php
   2  
   3  /**
   4   * A query class which uses offset/limit paging. Provides logic and accessors
   5   * for offsets and limits.
   6   */
   7  abstract 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_r) {
  31      if ($this->limit && $this->offset) {
  32        return qsprintf($conn_r, 'LIMIT %d, %d', $this->offset, $this->limit);
  33      } else if ($this->limit) {
  34        return qsprintf($conn_r, 'LIMIT %d', $this->limit);
  35      } else if ($this->offset) {
  36        return qsprintf($conn_r, 'LIMIT %d, %d', $this->offset, PHP_INT_MAX);
  37      } else {
  38        return '';
  39      }
  40    }
  41  
  42    final public function executeWithOffsetPager(AphrontPagerView $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  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1