Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/nuance/query/NuanceSourceQuery.php
12256 views
1
<?php
2
3
final class NuanceSourceQuery
4
extends NuanceQuery {
5
6
private $ids;
7
private $phids;
8
private $types;
9
private $isDisabled;
10
private $hasCursors;
11
12
public function withIDs(array $ids) {
13
$this->ids = $ids;
14
return $this;
15
}
16
17
public function withPHIDs(array $phids) {
18
$this->phids = $phids;
19
return $this;
20
}
21
22
public function withTypes($types) {
23
$this->types = $types;
24
return $this;
25
}
26
27
public function withIsDisabled($disabled) {
28
$this->isDisabled = $disabled;
29
return $this;
30
}
31
32
public function withHasImportCursors($has_cursors) {
33
$this->hasCursors = $has_cursors;
34
return $this;
35
}
36
37
public function withNameNgrams($ngrams) {
38
return $this->withNgramsConstraint(
39
new NuanceSourceNameNgrams(),
40
$ngrams);
41
}
42
43
public function newResultObject() {
44
return new NuanceSource();
45
}
46
47
protected function getPrimaryTableAlias() {
48
return 'source';
49
}
50
51
protected function willFilterPage(array $sources) {
52
$all_types = NuanceSourceDefinition::getAllDefinitions();
53
54
foreach ($sources as $key => $source) {
55
$definition = idx($all_types, $source->getType());
56
if (!$definition) {
57
$this->didRejectResult($source);
58
unset($sources[$key]);
59
continue;
60
}
61
$source->attachDefinition($definition);
62
}
63
64
return $sources;
65
}
66
67
68
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
69
$where = parent::buildWhereClauseParts($conn);
70
71
if ($this->types !== null) {
72
$where[] = qsprintf(
73
$conn,
74
'source.type IN (%Ls)',
75
$this->types);
76
}
77
78
if ($this->ids !== null) {
79
$where[] = qsprintf(
80
$conn,
81
'source.id IN (%Ld)',
82
$this->ids);
83
}
84
85
if ($this->phids !== null) {
86
$where[] = qsprintf(
87
$conn,
88
'source.phid IN (%Ls)',
89
$this->phids);
90
}
91
92
if ($this->isDisabled !== null) {
93
$where[] = qsprintf(
94
$conn,
95
'source.isDisabled = %d',
96
(int)$this->isDisabled);
97
}
98
99
if ($this->hasCursors !== null) {
100
$cursor_types = array();
101
102
$definitions = NuanceSourceDefinition::getAllDefinitions();
103
foreach ($definitions as $key => $definition) {
104
if ($definition->hasImportCursors()) {
105
$cursor_types[] = $key;
106
}
107
}
108
109
if ($this->hasCursors) {
110
if (!$cursor_types) {
111
throw new PhabricatorEmptyQueryException();
112
} else {
113
$where[] = qsprintf(
114
$conn,
115
'source.type IN (%Ls)',
116
$cursor_types);
117
}
118
} else {
119
if (!$cursor_types) {
120
// Apply no constraint.
121
} else {
122
$where[] = qsprintf(
123
$conn,
124
'source.type NOT IN (%Ls)',
125
$cursor_types);
126
}
127
}
128
}
129
130
return $where;
131
}
132
133
}
134
135