Path: blob/master/src/applications/almanac/query/AlmanacDeviceQuery.php
12256 views
<?php12final class AlmanacDeviceQuery3extends AlmanacQuery {45private $ids;6private $phids;7private $names;8private $namePrefix;9private $nameSuffix;10private $isClusterDevice;11private $statuses;1213public function withIDs(array $ids) {14$this->ids = $ids;15return $this;16}1718public function withPHIDs(array $phids) {19$this->phids = $phids;20return $this;21}2223public function withNames(array $names) {24$this->names = $names;25return $this;26}2728public function withNamePrefix($prefix) {29$this->namePrefix = $prefix;30return $this;31}3233public function withNameSuffix($suffix) {34$this->nameSuffix = $suffix;35return $this;36}3738public function withStatuses(array $statuses) {39$this->statuses = $statuses;40return $this;41}4243public function withNameNgrams($ngrams) {44return $this->withNgramsConstraint(45new AlmanacDeviceNameNgrams(),46$ngrams);47}4849public function withIsClusterDevice($is_cluster_device) {50$this->isClusterDevice = $is_cluster_device;51return $this;52}5354public function newResultObject() {55return new AlmanacDevice();56}5758protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {59$where = parent::buildWhereClauseParts($conn);6061if ($this->ids !== null) {62$where[] = qsprintf(63$conn,64'device.id IN (%Ld)',65$this->ids);66}6768if ($this->phids !== null) {69$where[] = qsprintf(70$conn,71'device.phid IN (%Ls)',72$this->phids);73}7475if ($this->names !== null) {76$hashes = array();77foreach ($this->names as $name) {78$hashes[] = PhabricatorHash::digestForIndex($name);79}80$where[] = qsprintf(81$conn,82'device.nameIndex IN (%Ls)',83$hashes);84}8586if ($this->namePrefix !== null) {87$where[] = qsprintf(88$conn,89'device.name LIKE %>',90$this->namePrefix);91}9293if ($this->nameSuffix !== null) {94$where[] = qsprintf(95$conn,96'device.name LIKE %<',97$this->nameSuffix);98}99100if ($this->isClusterDevice !== null) {101$where[] = qsprintf(102$conn,103'device.isBoundToClusterService = %d',104(int)$this->isClusterDevice);105}106107if ($this->statuses !== null) {108$where[] = qsprintf(109$conn,110'device.status IN (%Ls)',111$this->statuses);112}113114return $where;115}116117protected function getPrimaryTableAlias() {118return 'device';119}120121public function getOrderableColumns() {122return parent::getOrderableColumns() + array(123'name' => array(124'table' => $this->getPrimaryTableAlias(),125'column' => 'name',126'type' => 'string',127'unique' => true,128'reverse' => true,129),130);131}132133protected function newPagingMapFromPartialObject($object) {134return array(135'id' => (int)$object->getID(),136'name' => $object->getName(),137);138}139140public function getBuiltinOrders() {141return array(142'name' => array(143'vector' => array('name'),144'name' => pht('Device Name'),145),146) + parent::getBuiltinOrders();147}148149public function getQueryApplicationClass() {150return 'PhabricatorAlmanacApplication';151}152153}154155156