[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/project/query/ -> PhabricatorProjectColumnQuery.php (source)

   1  <?php
   2  
   3  final class PhabricatorProjectColumnQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $ids;
   7    private $phids;
   8    private $projectPHIDs;
   9    private $statuses;
  10  
  11    public function withIDs(array $ids) {
  12      $this->ids = $ids;
  13      return $this;
  14    }
  15  
  16    public function withPHIDs(array $phids) {
  17      $this->phids = $phids;
  18      return $this;
  19    }
  20  
  21    public function withProjectPHIDs(array $project_phids) {
  22      $this->projectPHIDs = $project_phids;
  23      return $this;
  24    }
  25  
  26    public function withStatuses(array $status) {
  27      $this->statuses = $status;
  28      return $this;
  29    }
  30  
  31    protected function loadPage() {
  32      $table = new PhabricatorProjectColumn();
  33      $conn_r = $table->establishConnection('r');
  34  
  35      $data = queryfx_all(
  36        $conn_r,
  37        'SELECT * FROM %T %Q %Q %Q',
  38        $table->getTableName(),
  39        $this->buildWhereClause($conn_r),
  40        $this->buildOrderClause($conn_r),
  41        $this->buildLimitClause($conn_r));
  42  
  43      return $table->loadAllFromArray($data);
  44    }
  45  
  46    protected function willFilterPage(array $page) {
  47      $projects = array();
  48  
  49      $project_phids = array_filter(mpull($page, 'getProjectPHID'));
  50      if ($project_phids) {
  51        $projects = id(new PhabricatorProjectQuery())
  52          ->setParentQuery($this)
  53          ->setViewer($this->getViewer())
  54          ->withPHIDs($project_phids)
  55          ->execute();
  56        $projects = mpull($projects, null, 'getPHID');
  57      }
  58  
  59      foreach ($page as $key => $column) {
  60        $phid = $column->getProjectPHID();
  61        $project = idx($projects, $phid);
  62        if (!$project) {
  63          unset($page[$key]);
  64          continue;
  65        }
  66        $column->attachProject($project);
  67      }
  68  
  69      return $page;
  70    }
  71  
  72    private function buildWhereClause($conn_r) {
  73      $where = array();
  74  
  75      if ($this->ids) {
  76        $where[] = qsprintf(
  77          $conn_r,
  78          'id IN (%Ld)',
  79          $this->ids);
  80      }
  81  
  82      if ($this->phids) {
  83        $where[] = qsprintf(
  84          $conn_r,
  85          'phid IN (%Ls)',
  86          $this->phids);
  87      }
  88  
  89      if ($this->projectPHIDs) {
  90        $where[] = qsprintf(
  91          $conn_r,
  92          'projectPHID IN (%Ls)',
  93          $this->projectPHIDs);
  94      }
  95  
  96      if ($this->statuses !== null) {
  97        $where[] = qsprintf(
  98          $conn_r,
  99          'status IN (%Ld)',
 100          $this->statuses);
 101      }
 102  
 103      $where[] = $this->buildPagingClause($conn_r);
 104  
 105      return $this->formatWhereClause($where);
 106    }
 107  
 108    public function getQueryApplicationClass() {
 109      return 'PhabricatorProjectApplication';
 110    }
 111  
 112  }


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