Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/query/AlmanacPropertyQuery.php
12256 views
1
<?php
2
3
final class AlmanacPropertyQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $objectPHIDs;
8
private $objects;
9
private $names;
10
11
public function withIDs(array $ids) {
12
$this->ids = $ids;
13
return $this;
14
}
15
16
public function withObjectPHIDs(array $phids) {
17
$this->objectPHIDs = $phids;
18
return $this;
19
}
20
21
public function withObjects(array $objects) {
22
$this->objects = mpull($objects, null, 'getPHID');
23
$this->objectPHIDs = array_keys($this->objects);
24
return $this;
25
}
26
27
public function withNames(array $names) {
28
$this->names = $names;
29
return $this;
30
}
31
32
public function newResultObject() {
33
return new AlmanacProperty();
34
}
35
36
protected function willFilterPage(array $properties) {
37
$object_phids = mpull($properties, 'getObjectPHID');
38
39
$object_phids = array_fuse($object_phids);
40
41
if ($this->objects !== null) {
42
$object_phids = array_diff_key($object_phids, $this->objects);
43
}
44
45
if ($object_phids) {
46
$objects = id(new PhabricatorObjectQuery())
47
->setViewer($this->getViewer())
48
->setParentQuery($this)
49
->withPHIDs($object_phids)
50
->execute();
51
$objects = mpull($objects, null, 'getPHID');
52
} else {
53
$objects = array();
54
}
55
56
$objects += $this->objects;
57
58
foreach ($properties as $key => $property) {
59
$object = idx($objects, $property->getObjectPHID());
60
if (!$object) {
61
unset($properties[$key]);
62
continue;
63
}
64
$property->attachObject($object);
65
}
66
67
return $properties;
68
}
69
70
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
71
$where = parent::buildWhereClauseParts($conn);
72
73
if ($this->ids !== null) {
74
$where[] = qsprintf(
75
$conn,
76
'id IN (%Ld)',
77
$this->ids);
78
}
79
80
if ($this->objectPHIDs !== null) {
81
$where[] = qsprintf(
82
$conn,
83
'objectPHID IN (%Ls)',
84
$this->objectPHIDs);
85
}
86
87
if ($this->names !== null) {
88
$hashes = array();
89
foreach ($this->names as $name) {
90
$hashes[] = PhabricatorHash::digestForIndex($name);
91
}
92
$where[] = qsprintf(
93
$conn,
94
'fieldIndex IN (%Ls)',
95
$hashes);
96
}
97
98
return $where;
99
}
100
101
public function getQueryApplicationClass() {
102
return 'PhabricatorAlmanacApplication';
103
}
104
105
}
106
107