[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class AlmanacBindingQuery
   4    extends AlmanacQuery {
   5  
   6    private $ids;
   7    private $phids;
   8    private $servicePHIDs;
   9    private $devicePHIDs;
  10    private $interfacePHIDs;
  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 withServicePHIDs(array $phids) {
  23      $this->servicePHIDs = $phids;
  24      return $this;
  25    }
  26  
  27    public function withDevicePHIDs(array $phids) {
  28      $this->devicePHIDs = $phids;
  29      return $this;
  30    }
  31  
  32    public function withInterfacePHIDs(array $phids) {
  33      $this->interfacePHIDs = $phids;
  34      return $this;
  35    }
  36  
  37    protected function loadPage() {
  38      $table = new AlmanacBinding();
  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 willFilterPage(array $bindings) {
  53      $service_phids = mpull($bindings, 'getServicePHID');
  54      $device_phids = mpull($bindings, 'getDevicePHID');
  55      $interface_phids = mpull($bindings, 'getInterfacePHID');
  56  
  57      $services = id(new AlmanacServiceQuery())
  58        ->setParentQuery($this)
  59        ->setViewer($this->getViewer())
  60        ->withPHIDs($service_phids)
  61        ->execute();
  62      $services = mpull($services, null, 'getPHID');
  63  
  64      $devices = id(new AlmanacDeviceQuery())
  65        ->setParentQuery($this)
  66        ->setViewer($this->getViewer())
  67        ->withPHIDs($device_phids)
  68        ->execute();
  69      $devices = mpull($devices, null, 'getPHID');
  70  
  71      $interfaces = id(new AlmanacInterfaceQuery())
  72        ->setParentQuery($this)
  73        ->setViewer($this->getViewer())
  74        ->withPHIDs($interface_phids)
  75        ->execute();
  76      $interfaces = mpull($interfaces, null, 'getPHID');
  77  
  78      foreach ($bindings as $key => $binding) {
  79        $service = idx($services, $binding->getServicePHID());
  80        $device = idx($devices, $binding->getDevicePHID());
  81        $interface = idx($interfaces, $binding->getInterfacePHID());
  82        if (!$service || !$device || !$interface) {
  83          $this->didRejectResult($binding);
  84          unset($bindings[$key]);
  85          continue;
  86        }
  87  
  88        $binding->attachService($service);
  89        $binding->attachDevice($device);
  90        $binding->attachInterface($interface);
  91      }
  92  
  93      return $bindings;
  94    }
  95  
  96    protected function buildWhereClause($conn_r) {
  97      $where = array();
  98  
  99      if ($this->ids !== null) {
 100        $where[] = qsprintf(
 101          $conn_r,
 102          'id IN (%Ld)',
 103          $this->ids);
 104      }
 105  
 106      if ($this->phids !== null) {
 107        $where[] = qsprintf(
 108          $conn_r,
 109          'phid IN (%Ls)',
 110          $this->phids);
 111      }
 112  
 113      if ($this->servicePHIDs !== null) {
 114        $where[] = qsprintf(
 115          $conn_r,
 116          'servicePHID IN (%Ls)',
 117          $this->servicePHIDs);
 118      }
 119  
 120      if ($this->devicePHIDs !== null) {
 121        $where[] = qsprintf(
 122          $conn_r,
 123          'devicePHID IN (%Ls)',
 124          $this->devicePHIDs);
 125      }
 126  
 127      if ($this->interfacePHIDs !== null) {
 128        $where[] = qsprintf(
 129          $conn_r,
 130          'interfacePHID IN (%Ls)',
 131          $this->interfacePHIDs);
 132      }
 133  
 134      $where[] = $this->buildPagingClause($conn_r);
 135  
 136      return $this->formatWhereClause($where);
 137    }
 138  
 139  }


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