[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/harbormaster/query/ -> HarbormasterBuildLogQuery.php (source)

   1  <?php
   2  
   3  final class HarbormasterBuildLogQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $ids;
   7    private $phids;
   8    private $buildPHIDs;
   9  
  10    public function withIDs(array $ids) {
  11      $this->ids = $ids;
  12      return $this;
  13    }
  14  
  15    public function withPHIDs(array $phids) {
  16      $this->phids = $phids;
  17      return $this;
  18    }
  19  
  20    public function withBuildTargetPHIDs(array $build_target_phids) {
  21      $this->buildTargetPHIDs = $build_target_phids;
  22      return $this;
  23    }
  24  
  25    protected function loadPage() {
  26      $table = new HarbormasterBuildLog();
  27      $conn_r = $table->establishConnection('r');
  28  
  29      $data = queryfx_all(
  30        $conn_r,
  31        'SELECT * FROM %T %Q %Q %Q',
  32        $table->getTableName(),
  33        $this->buildWhereClause($conn_r),
  34        $this->buildOrderClause($conn_r),
  35        $this->buildLimitClause($conn_r));
  36  
  37      return $table->loadAllFromArray($data);
  38    }
  39  
  40    protected function willFilterPage(array $page) {
  41      $build_targets = array();
  42  
  43      $build_target_phids = array_filter(mpull($page, 'getBuildTargetPHID'));
  44      if ($build_target_phids) {
  45        $build_targets = id(new HarbormasterBuildTargetQuery())
  46          ->setViewer($this->getViewer())
  47          ->withPHIDs($build_target_phids)
  48          ->setParentQuery($this)
  49          ->execute();
  50        $build_targets = mpull($build_targets, null, 'getPHID');
  51      }
  52  
  53      foreach ($page as $key => $build_log) {
  54        $build_target_phid = $build_log->getBuildTargetPHID();
  55        if (empty($build_targets[$build_target_phid])) {
  56          unset($page[$key]);
  57          continue;
  58        }
  59        $build_log->attachBuildTarget($build_targets[$build_target_phid]);
  60      }
  61  
  62      return $page;
  63    }
  64  
  65    private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
  66      $where = array();
  67  
  68      if ($this->ids) {
  69        $where[] = qsprintf(
  70          $conn_r,
  71          'id IN (%Ld)',
  72          $this->ids);
  73      }
  74  
  75      if ($this->phids) {
  76        $where[] = qsprintf(
  77          $conn_r,
  78          'phid IN (%Ls)',
  79          $this->phids);
  80      }
  81  
  82      if ($this->buildTargetPHIDs) {
  83        $where[] = qsprintf(
  84          $conn_r,
  85          'buildTargetPHID IN (%Ls)',
  86          $this->buildTargetPHIDs);
  87      }
  88  
  89      $where[] = $this->buildPagingClause($conn_r);
  90  
  91      return $this->formatWhereClause($where);
  92    }
  93  
  94    public function getQueryApplicationClass() {
  95      return 'PhabricatorHarbormasterApplication';
  96    }
  97  
  98  }


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