Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/query/AlmanacQuery.php
12256 views
1
<?php
2
3
abstract class AlmanacQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $needProperties;
7
8
public function needProperties($need_properties) {
9
$this->needProperties = $need_properties;
10
return $this;
11
}
12
13
protected function getNeedProperties() {
14
return $this->needProperties;
15
}
16
17
protected function didFilterPage(array $objects) {
18
$has_properties = (head($objects) instanceof AlmanacPropertyInterface);
19
20
if ($has_properties && $this->needProperties) {
21
$property_query = id(new AlmanacPropertyQuery())
22
->setViewer($this->getViewer())
23
->setParentQuery($this)
24
->withObjects($objects);
25
26
$properties = $property_query->execute();
27
28
$properties = mgroup($properties, 'getObjectPHID');
29
foreach ($objects as $object) {
30
$object_properties = idx($properties, $object->getPHID(), array());
31
$object_properties = mpull($object_properties, null, 'getFieldName');
32
33
// Create synthetic properties for defaults on the object itself.
34
$specs = $object->getAlmanacPropertyFieldSpecifications();
35
foreach ($specs as $key => $spec) {
36
if (empty($object_properties[$key])) {
37
$default_value = $spec->getValueForTransaction();
38
39
$object_properties[$key] = id(new AlmanacProperty())
40
->setObjectPHID($object->getPHID())
41
->setFieldName($key)
42
->setFieldValue($default_value);
43
}
44
}
45
46
foreach ($object_properties as $property) {
47
$property->attachObject($object);
48
}
49
50
$object->attachAlmanacProperties($object_properties);
51
}
52
}
53
54
return $objects;
55
}
56
57
public function getQueryApplicationClass() {
58
return 'PhabricatorAlmanacApplication';
59
}
60
61
}
62
63