Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/nuance/query/NuanceItemQuery.php
12256 views
1
<?php
2
3
final class NuanceItemQuery
4
extends NuanceQuery {
5
6
private $ids;
7
private $phids;
8
private $sourcePHIDs;
9
private $queuePHIDs;
10
private $itemTypes;
11
private $itemKeys;
12
private $containerKeys;
13
private $statuses;
14
15
public function withIDs(array $ids) {
16
$this->ids = $ids;
17
return $this;
18
}
19
20
public function withPHIDs(array $phids) {
21
$this->phids = $phids;
22
return $this;
23
}
24
25
public function withSourcePHIDs(array $source_phids) {
26
$this->sourcePHIDs = $source_phids;
27
return $this;
28
}
29
30
public function withQueuePHIDs(array $queue_phids) {
31
$this->queuePHIDs = $queue_phids;
32
return $this;
33
}
34
35
public function withItemTypes(array $item_types) {
36
$this->itemTypes = $item_types;
37
return $this;
38
}
39
40
public function withItemKeys(array $item_keys) {
41
$this->itemKeys = $item_keys;
42
return $this;
43
}
44
45
public function withStatuses(array $statuses) {
46
$this->statuses = $statuses;
47
return $this;
48
}
49
50
public function withItemContainerKeys(array $container_keys) {
51
$this->containerKeys = $container_keys;
52
return $this;
53
}
54
55
public function newResultObject() {
56
return new NuanceItem();
57
}
58
59
protected function willFilterPage(array $items) {
60
$viewer = $this->getViewer();
61
$source_phids = mpull($items, 'getSourcePHID');
62
63
$sources = id(new NuanceSourceQuery())
64
->setViewer($viewer)
65
->withPHIDs($source_phids)
66
->execute();
67
$sources = mpull($sources, null, 'getPHID');
68
69
foreach ($items as $key => $item) {
70
$source = idx($sources, $item->getSourcePHID());
71
if (!$source) {
72
$this->didRejectResult($items[$key]);
73
unset($items[$key]);
74
continue;
75
}
76
$item->attachSource($source);
77
}
78
79
$type_map = NuanceItemType::getAllItemTypes();
80
foreach ($items as $key => $item) {
81
$type = idx($type_map, $item->getItemType());
82
if (!$type) {
83
$this->didRejectResult($items[$key]);
84
unset($items[$key]);
85
continue;
86
}
87
$item->attachImplementation($type);
88
}
89
90
$queue_phids = array();
91
foreach ($items as $item) {
92
$queue_phid = $item->getQueuePHID();
93
if ($queue_phid) {
94
$queue_phids[$queue_phid] = $queue_phid;
95
}
96
}
97
98
if ($queue_phids) {
99
$queues = id(new NuanceQueueQuery())
100
->setViewer($viewer)
101
->withPHIDs($queue_phids)
102
->execute();
103
$queues = mpull($queues, null, 'getPHID');
104
} else {
105
$queues = array();
106
}
107
108
foreach ($items as $key => $item) {
109
$queue_phid = $item->getQueuePHID();
110
111
if (!$queue_phid) {
112
$item->attachQueue(null);
113
continue;
114
}
115
116
$queue = idx($queues, $queue_phid);
117
118
if (!$queue) {
119
unset($items[$key]);
120
$this->didRejectResult($item);
121
continue;
122
}
123
124
$item->attachQueue($queue);
125
}
126
127
return $items;
128
}
129
130
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
131
$where = parent::buildWhereClauseParts($conn);
132
133
if ($this->sourcePHIDs !== null) {
134
$where[] = qsprintf(
135
$conn,
136
'sourcePHID IN (%Ls)',
137
$this->sourcePHIDs);
138
}
139
140
if ($this->queuePHIDs !== null) {
141
$where[] = qsprintf(
142
$conn,
143
'queuePHID IN (%Ls)',
144
$this->queuePHIDs);
145
}
146
147
if ($this->ids !== null) {
148
$where[] = qsprintf(
149
$conn,
150
'id IN (%Ld)',
151
$this->ids);
152
}
153
154
if ($this->phids !== null) {
155
$where[] = qsprintf(
156
$conn,
157
'phid IN (%Ls)',
158
$this->phids);
159
}
160
161
if ($this->statuses !== null) {
162
$where[] = qsprintf(
163
$conn,
164
'status IN (%Ls)',
165
$this->statuses);
166
}
167
168
if ($this->itemTypes !== null) {
169
$where[] = qsprintf(
170
$conn,
171
'itemType IN (%Ls)',
172
$this->itemTypes);
173
}
174
175
if ($this->itemKeys !== null) {
176
$where[] = qsprintf(
177
$conn,
178
'itemKey IN (%Ls)',
179
$this->itemKeys);
180
}
181
182
if ($this->containerKeys !== null) {
183
$where[] = qsprintf(
184
$conn,
185
'itemContainerKey IN (%Ls)',
186
$this->containerKeys);
187
}
188
189
return $where;
190
}
191
192
}
193
194