Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / almanac / query / AlmanacQuery.php
blobb5b6146c7f1e61225df80c8494a9b7acdb83620b
1 <?php
3 abstract class AlmanacQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $needProperties;
8 public function needProperties($need_properties) {
9 $this->needProperties = $need_properties;
10 return $this;
13 protected function getNeedProperties() {
14 return $this->needProperties;
17 protected function didFilterPage(array $objects) {
18 $has_properties = (head($objects) instanceof AlmanacPropertyInterface);
20 if ($has_properties && $this->needProperties) {
21 $property_query = id(new AlmanacPropertyQuery())
22 ->setViewer($this->getViewer())
23 ->setParentQuery($this)
24 ->withObjects($objects);
26 $properties = $property_query->execute();
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');
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();
39 $object_properties[$key] = id(new AlmanacProperty())
40 ->setObjectPHID($object->getPHID())
41 ->setFieldName($key)
42 ->setFieldValue($default_value);
46 foreach ($object_properties as $property) {
47 $property->attachObject($object);
50 $object->attachAlmanacProperties($object_properties);
54 return $objects;
57 public function getQueryApplicationClass() {
58 return 'PhabricatorAlmanacApplication';