[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/almanac/query/ -> AlmanacDeviceQuery.php (source)

   1  <?php
   2  
   3  final class AlmanacDeviceQuery
   4    extends AlmanacQuery {
   5  
   6    private $ids;
   7    private $phids;
   8    private $names;
   9    private $datasourceQuery;
  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 withNames(array $names) {
  22      $this->names = $names;
  23      return $this;
  24    }
  25  
  26    public function withDatasourceQuery($query) {
  27      $this->datasourceQuery = $query;
  28      return $this;
  29    }
  30  
  31    protected function loadPage() {
  32      $table = new AlmanacDevice();
  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 buildWhereClause($conn_r) {
  47      $where = array();
  48  
  49      if ($this->ids !== null) {
  50        $where[] = qsprintf(
  51          $conn_r,
  52          'id IN (%Ld)',
  53          $this->ids);
  54      }
  55  
  56      if ($this->phids !== null) {
  57        $where[] = qsprintf(
  58          $conn_r,
  59          'phid IN (%Ls)',
  60          $this->phids);
  61      }
  62  
  63      if ($this->names !== null) {
  64        $hashes = array();
  65        foreach ($this->names as $name) {
  66          $hashes[] = PhabricatorHash::digestForIndex($name);
  67        }
  68        $where[] = qsprintf(
  69          $conn_r,
  70          'nameIndex IN (%Ls)',
  71          $hashes);
  72      }
  73  
  74      if ($this->datasourceQuery !== null) {
  75        $where[] = qsprintf(
  76          $conn_r,
  77          'name LIKE %>',
  78          $this->datasourceQuery);
  79      }
  80  
  81      $where[] = $this->buildPagingClause($conn_r);
  82  
  83      return $this->formatWhereClause($where);
  84    }
  85  
  86    public function getQueryApplicationClass() {
  87      return 'PhabricatorAlmanacApplication';
  88    }
  89  
  90  }


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