Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/query/AlmanacDeviceQuery.php
12256 views
1
<?php
2
3
final class AlmanacDeviceQuery
4
extends AlmanacQuery {
5
6
private $ids;
7
private $phids;
8
private $names;
9
private $namePrefix;
10
private $nameSuffix;
11
private $isClusterDevice;
12
private $statuses;
13
14
public function withIDs(array $ids) {
15
$this->ids = $ids;
16
return $this;
17
}
18
19
public function withPHIDs(array $phids) {
20
$this->phids = $phids;
21
return $this;
22
}
23
24
public function withNames(array $names) {
25
$this->names = $names;
26
return $this;
27
}
28
29
public function withNamePrefix($prefix) {
30
$this->namePrefix = $prefix;
31
return $this;
32
}
33
34
public function withNameSuffix($suffix) {
35
$this->nameSuffix = $suffix;
36
return $this;
37
}
38
39
public function withStatuses(array $statuses) {
40
$this->statuses = $statuses;
41
return $this;
42
}
43
44
public function withNameNgrams($ngrams) {
45
return $this->withNgramsConstraint(
46
new AlmanacDeviceNameNgrams(),
47
$ngrams);
48
}
49
50
public function withIsClusterDevice($is_cluster_device) {
51
$this->isClusterDevice = $is_cluster_device;
52
return $this;
53
}
54
55
public function newResultObject() {
56
return new AlmanacDevice();
57
}
58
59
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
60
$where = parent::buildWhereClauseParts($conn);
61
62
if ($this->ids !== null) {
63
$where[] = qsprintf(
64
$conn,
65
'device.id IN (%Ld)',
66
$this->ids);
67
}
68
69
if ($this->phids !== null) {
70
$where[] = qsprintf(
71
$conn,
72
'device.phid IN (%Ls)',
73
$this->phids);
74
}
75
76
if ($this->names !== null) {
77
$hashes = array();
78
foreach ($this->names as $name) {
79
$hashes[] = PhabricatorHash::digestForIndex($name);
80
}
81
$where[] = qsprintf(
82
$conn,
83
'device.nameIndex IN (%Ls)',
84
$hashes);
85
}
86
87
if ($this->namePrefix !== null) {
88
$where[] = qsprintf(
89
$conn,
90
'device.name LIKE %>',
91
$this->namePrefix);
92
}
93
94
if ($this->nameSuffix !== null) {
95
$where[] = qsprintf(
96
$conn,
97
'device.name LIKE %<',
98
$this->nameSuffix);
99
}
100
101
if ($this->isClusterDevice !== null) {
102
$where[] = qsprintf(
103
$conn,
104
'device.isBoundToClusterService = %d',
105
(int)$this->isClusterDevice);
106
}
107
108
if ($this->statuses !== null) {
109
$where[] = qsprintf(
110
$conn,
111
'device.status IN (%Ls)',
112
$this->statuses);
113
}
114
115
return $where;
116
}
117
118
protected function getPrimaryTableAlias() {
119
return 'device';
120
}
121
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,
130
),
131
);
132
}
133
134
protected function newPagingMapFromPartialObject($object) {
135
return array(
136
'id' => (int)$object->getID(),
137
'name' => $object->getName(),
138
);
139
}
140
141
public function getBuiltinOrders() {
142
return array(
143
'name' => array(
144
'vector' => array('name'),
145
'name' => pht('Device Name'),
146
),
147
) + parent::getBuiltinOrders();
148
}
149
150
public function getQueryApplicationClass() {
151
return 'PhabricatorAlmanacApplication';
152
}
153
154
}
155
156