[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phragment/query/ -> PhragmentFragmentVersionQuery.php (source)

   1  <?php
   2  
   3  final class PhragmentFragmentVersionQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $ids;
   7    private $phids;
   8    private $fragmentPHIDs;
   9    private $sequences;
  10    private $sequenceBefore;
  11  
  12    public function withIDs(array $ids) {
  13      $this->ids = $ids;
  14      return $this;
  15    }
  16  
  17    public function withPHIDs(array $phids) {
  18      $this->phids = $phids;
  19      return $this;
  20    }
  21  
  22    public function withFragmentPHIDs(array $fragment_phids) {
  23      $this->fragmentPHIDs = $fragment_phids;
  24      return $this;
  25    }
  26  
  27    public function withSequences(array $sequences) {
  28      $this->sequences = $sequences;
  29      return $this;
  30    }
  31  
  32    public function withSequenceBefore($current) {
  33      $this->sequenceBefore = $current;
  34      return $this;
  35    }
  36  
  37    public function loadPage() {
  38      $table = new PhragmentFragmentVersion();
  39      $conn_r = $table->establishConnection('r');
  40  
  41      $data = queryfx_all(
  42        $conn_r,
  43        'SELECT * FROM %T %Q %Q %Q',
  44        $table->getTableName(),
  45        $this->buildWhereClause($conn_r),
  46        $this->buildOrderClause($conn_r),
  47        $this->buildLimitClause($conn_r));
  48  
  49      return $table->loadAllFromArray($data);
  50    }
  51  
  52    protected function buildWhereClause($conn_r) {
  53      $where = array();
  54  
  55      if ($this->ids) {
  56        $where[] = qsprintf(
  57          $conn_r,
  58          'id IN (%Ld)',
  59          $this->ids);
  60      }
  61  
  62      if ($this->phids) {
  63        $where[] = qsprintf(
  64          $conn_r,
  65          'phid IN (%Ls)',
  66          $this->phids);
  67      }
  68  
  69      if ($this->fragmentPHIDs) {
  70        $where[] = qsprintf(
  71          $conn_r,
  72          'fragmentPHID IN (%Ls)',
  73          $this->fragmentPHIDs);
  74      }
  75  
  76      if ($this->sequences) {
  77        $where[] = qsprintf(
  78          $conn_r,
  79          'sequence IN (%Ld)',
  80          $this->sequences);
  81      }
  82  
  83      if ($this->sequenceBefore !== null) {
  84        $where[] = qsprintf(
  85          $conn_r,
  86          'sequence < %d',
  87          $this->sequenceBefore);
  88      }
  89  
  90      $where[] = $this->buildPagingClause($conn_r);
  91  
  92      return $this->formatWhereClause($where);
  93    }
  94  
  95    protected function willFilterPage(array $page) {
  96      $fragments = array();
  97  
  98      $fragment_phids = array_filter(mpull($page, 'getFragmentPHID'));
  99      if ($fragment_phids) {
 100        $fragments = id(new PhabricatorObjectQuery())
 101          ->setViewer($this->getViewer())
 102          ->withPHIDs($fragment_phids)
 103          ->setParentQuery($this)
 104          ->execute();
 105        $fragments = mpull($fragments, null, 'getPHID');
 106      }
 107  
 108      foreach ($page as $key => $version) {
 109        $fragment_phid = $version->getFragmentPHID();
 110        if (empty($fragments[$fragment_phid])) {
 111          unset($page[$key]);
 112          continue;
 113        }
 114        $version->attachFragment($fragments[$fragment_phid]);
 115      }
 116  
 117      return $page;
 118    }
 119  
 120    public function getQueryApplicationClass() {
 121      return 'PhabricatorPhragmentApplication';
 122    }
 123  }


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