@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * @extends AlmanacQuery<AlmanacDevice>
5 */
6final class AlmanacDeviceQuery
7 extends AlmanacQuery {
8
9 private $ids;
10 private $phids;
11 private $names;
12 private $namePrefix;
13 private $nameSuffix;
14 private $isClusterDevice;
15 private $statuses;
16
17 public function withIDs(array $ids) {
18 $this->ids = $ids;
19 return $this;
20 }
21
22 public function withPHIDs(array $phids) {
23 $this->phids = $phids;
24 return $this;
25 }
26
27 public function withNames(array $names) {
28 $this->names = $names;
29 return $this;
30 }
31
32 public function withNamePrefix($prefix) {
33 $this->namePrefix = $prefix;
34 return $this;
35 }
36
37 public function withNameSuffix($suffix) {
38 $this->nameSuffix = $suffix;
39 return $this;
40 }
41
42 public function withStatuses(array $statuses) {
43 $this->statuses = $statuses;
44 return $this;
45 }
46
47 public function withNameNgrams($ngrams) {
48 return $this->withNgramsConstraint(
49 new AlmanacDeviceNameNgrams(),
50 $ngrams);
51 }
52
53 public function withIsClusterDevice($is_cluster_device) {
54 $this->isClusterDevice = $is_cluster_device;
55 return $this;
56 }
57
58 public function newResultObject() {
59 return new AlmanacDevice();
60 }
61
62 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
63 $where = parent::buildWhereClauseParts($conn);
64
65 if ($this->ids !== null) {
66 $where[] = qsprintf(
67 $conn,
68 'device.id IN (%Ld)',
69 $this->ids);
70 }
71
72 if ($this->phids !== null) {
73 $where[] = qsprintf(
74 $conn,
75 'device.phid IN (%Ls)',
76 $this->phids);
77 }
78
79 if ($this->names !== null) {
80 $hashes = array();
81 foreach ($this->names as $name) {
82 $hashes[] = PhabricatorHash::digestForIndex($name);
83 }
84 $where[] = qsprintf(
85 $conn,
86 'device.nameIndex IN (%Ls)',
87 $hashes);
88 }
89
90 if ($this->namePrefix !== null) {
91 $where[] = qsprintf(
92 $conn,
93 'device.name LIKE %>',
94 $this->namePrefix);
95 }
96
97 if ($this->nameSuffix !== null) {
98 $where[] = qsprintf(
99 $conn,
100 'device.name LIKE %<',
101 $this->nameSuffix);
102 }
103
104 if ($this->isClusterDevice !== null) {
105 $where[] = qsprintf(
106 $conn,
107 'device.isBoundToClusterService = %d',
108 (int)$this->isClusterDevice);
109 }
110
111 if ($this->statuses !== null) {
112 $where[] = qsprintf(
113 $conn,
114 'device.status IN (%Ls)',
115 $this->statuses);
116 }
117
118 return $where;
119 }
120
121 protected function getPrimaryTableAlias() {
122 return 'device';
123 }
124
125 public function getOrderableColumns() {
126 return parent::getOrderableColumns() + array(
127 'name' => array(
128 'table' => $this->getPrimaryTableAlias(),
129 'column' => 'name',
130 'type' => 'string',
131 'unique' => true,
132 'reverse' => true,
133 ),
134 );
135 }
136
137 protected function newPagingMapFromPartialObject($object) {
138 return array(
139 'id' => (int)$object->getID(),
140 'name' => $object->getName(),
141 );
142 }
143
144 public function getBuiltinOrders() {
145 return array(
146 'name' => array(
147 'vector' => array('name'),
148 'name' => pht('Device Name'),
149 ),
150 ) + parent::getBuiltinOrders();
151 }
152
153 public function getQueryApplicationClass() {
154 return PhabricatorAlmanacApplication::class;
155 }
156
157}