Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / almanac / query / AlmanacDeviceQuery.php
blob42796c48398c501e1e89da5f726c3b7e1b696c84
1 <?php
3 final class AlmanacDeviceQuery
4 extends AlmanacQuery {
6 private $ids;
7 private $phids;
8 private $names;
9 private $namePrefix;
10 private $nameSuffix;
11 private $isClusterDevice;
12 private $statuses;
14 public function withIDs(array $ids) {
15 $this->ids = $ids;
16 return $this;
19 public function withPHIDs(array $phids) {
20 $this->phids = $phids;
21 return $this;
24 public function withNames(array $names) {
25 $this->names = $names;
26 return $this;
29 public function withNamePrefix($prefix) {
30 $this->namePrefix = $prefix;
31 return $this;
34 public function withNameSuffix($suffix) {
35 $this->nameSuffix = $suffix;
36 return $this;
39 public function withStatuses(array $statuses) {
40 $this->statuses = $statuses;
41 return $this;
44 public function withNameNgrams($ngrams) {
45 return $this->withNgramsConstraint(
46 new AlmanacDeviceNameNgrams(),
47 $ngrams);
50 public function withIsClusterDevice($is_cluster_device) {
51 $this->isClusterDevice = $is_cluster_device;
52 return $this;
55 public function newResultObject() {
56 return new AlmanacDevice();
59 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
60 $where = parent::buildWhereClauseParts($conn);
62 if ($this->ids !== null) {
63 $where[] = qsprintf(
64 $conn,
65 'device.id IN (%Ld)',
66 $this->ids);
69 if ($this->phids !== null) {
70 $where[] = qsprintf(
71 $conn,
72 'device.phid IN (%Ls)',
73 $this->phids);
76 if ($this->names !== null) {
77 $hashes = array();
78 foreach ($this->names as $name) {
79 $hashes[] = PhabricatorHash::digestForIndex($name);
81 $where[] = qsprintf(
82 $conn,
83 'device.nameIndex IN (%Ls)',
84 $hashes);
87 if ($this->namePrefix !== null) {
88 $where[] = qsprintf(
89 $conn,
90 'device.name LIKE %>',
91 $this->namePrefix);
94 if ($this->nameSuffix !== null) {
95 $where[] = qsprintf(
96 $conn,
97 'device.name LIKE %<',
98 $this->nameSuffix);
101 if ($this->isClusterDevice !== null) {
102 $where[] = qsprintf(
103 $conn,
104 'device.isBoundToClusterService = %d',
105 (int)$this->isClusterDevice);
108 if ($this->statuses !== null) {
109 $where[] = qsprintf(
110 $conn,
111 'device.status IN (%Ls)',
112 $this->statuses);
115 return $where;
118 protected function getPrimaryTableAlias() {
119 return 'device';
122 public function getOrderableColumns() {
123 return parent::getOrderableColumns() + array(
124 'name' => array(
125 'table' => $this->getPrimaryTableAlias(),
126 'column' => 'name',
127 'type' => 'string',
128 'unique' => true,
129 'reverse' => true,
134 protected function newPagingMapFromPartialObject($object) {
135 return array(
136 'id' => (int)$object->getID(),
137 'name' => $object->getName(),
141 public function getBuiltinOrders() {
142 return array(
143 'name' => array(
144 'vector' => array('name'),
145 'name' => pht('Device Name'),
147 ) + parent::getBuiltinOrders();
150 public function getQueryApplicationClass() {
151 return 'PhabricatorAlmanacApplication';