Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/query/HarbormasterBuildPlanQuery.php
12256 views
1
<?php
2
3
final class HarbormasterBuildPlanQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $phids;
8
private $statuses;
9
private $datasourceQuery;
10
private $planAutoKeys;
11
private $needBuildSteps;
12
13
public function withIDs(array $ids) {
14
$this->ids = $ids;
15
return $this;
16
}
17
18
public function withPHIDs(array $phids) {
19
$this->phids = $phids;
20
return $this;
21
}
22
23
public function withStatuses(array $statuses) {
24
$this->statuses = $statuses;
25
return $this;
26
}
27
28
public function withDatasourceQuery($query) {
29
$this->datasourceQuery = $query;
30
return $this;
31
}
32
33
public function withPlanAutoKeys(array $keys) {
34
$this->planAutoKeys = $keys;
35
return $this;
36
}
37
38
public function withNameNgrams($ngrams) {
39
return $this->withNgramsConstraint(
40
new HarbormasterBuildPlanNameNgrams(),
41
$ngrams);
42
}
43
44
public function needBuildSteps($need) {
45
$this->needBuildSteps = $need;
46
return $this;
47
}
48
49
public function newResultObject() {
50
return new HarbormasterBuildPlan();
51
}
52
53
protected function didFilterPage(array $page) {
54
if ($this->needBuildSteps) {
55
$plan_phids = mpull($page, 'getPHID');
56
57
$steps = id(new HarbormasterBuildStepQuery())
58
->setParentQuery($this)
59
->setViewer($this->getViewer())
60
->withBuildPlanPHIDs($plan_phids)
61
->execute();
62
$steps = mgroup($steps, 'getBuildPlanPHID');
63
64
foreach ($page as $plan) {
65
$plan_steps = idx($steps, $plan->getPHID(), array());
66
$plan->attachBuildSteps($plan_steps);
67
}
68
}
69
70
return $page;
71
}
72
73
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
74
$where = parent::buildWhereClauseParts($conn);
75
76
if ($this->ids !== null) {
77
$where[] = qsprintf(
78
$conn,
79
'plan.id IN (%Ld)',
80
$this->ids);
81
}
82
83
if ($this->phids !== null) {
84
$where[] = qsprintf(
85
$conn,
86
'plan.phid IN (%Ls)',
87
$this->phids);
88
}
89
90
if ($this->statuses !== null) {
91
$where[] = qsprintf(
92
$conn,
93
'plan.planStatus IN (%Ls)',
94
$this->statuses);
95
}
96
97
if (!phutil_nonempty_string($this->datasourceQuery)) {
98
$where[] = qsprintf(
99
$conn,
100
'plan.name LIKE %>',
101
$this->datasourceQuery);
102
}
103
104
if ($this->planAutoKeys !== null) {
105
$where[] = qsprintf(
106
$conn,
107
'plan.planAutoKey IN (%Ls)',
108
$this->planAutoKeys);
109
}
110
111
return $where;
112
}
113
114
protected function getPrimaryTableAlias() {
115
return 'plan';
116
}
117
118
public function getQueryApplicationClass() {
119
return 'PhabricatorHarbormasterApplication';
120
}
121
122
public function getOrderableColumns() {
123
return parent::getOrderableColumns() + array(
124
'name' => array(
125
'column' => 'name',
126
'type' => 'string',
127
'reverse' => true,
128
),
129
);
130
}
131
132
protected function newPagingMapFromPartialObject($object) {
133
return array(
134
'id' => (int)$object->getID(),
135
'name' => $object->getName(),
136
);
137
}
138
139
public function getBuiltinOrders() {
140
return array(
141
'name' => array(
142
'vector' => array('name', 'id'),
143
'name' => pht('Name'),
144
),
145
) + parent::getBuiltinOrders();
146
}
147
148
}
149
150