Generate file attachment transactions for explicit Remarkup attachments on common...
[phabricator.git] / src / applications / almanac / query / AlmanacPropertyQuery.php
blob17f1e87c0700d78d03aa758203d3e46ddc860835
1 <?php
3 final class AlmanacPropertyQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $objectPHIDs;
8 private $objects;
9 private $names;
11 public function withIDs(array $ids) {
12 $this->ids = $ids;
13 return $this;
16 public function withObjectPHIDs(array $phids) {
17 $this->objectPHIDs = $phids;
18 return $this;
21 public function withObjects(array $objects) {
22 $this->objects = mpull($objects, null, 'getPHID');
23 $this->objectPHIDs = array_keys($this->objects);
24 return $this;
27 public function withNames(array $names) {
28 $this->names = $names;
29 return $this;
32 public function newResultObject() {
33 return new AlmanacProperty();
36 protected function loadPage() {
37 return $this->loadStandardPage($this->newResultObject());
40 protected function willFilterPage(array $properties) {
41 $object_phids = mpull($properties, 'getObjectPHID');
43 $object_phids = array_fuse($object_phids);
45 if ($this->objects !== null) {
46 $object_phids = array_diff_key($object_phids, $this->objects);
49 if ($object_phids) {
50 $objects = id(new PhabricatorObjectQuery())
51 ->setViewer($this->getViewer())
52 ->setParentQuery($this)
53 ->withPHIDs($object_phids)
54 ->execute();
55 $objects = mpull($objects, null, 'getPHID');
56 } else {
57 $objects = array();
60 $objects += $this->objects;
62 foreach ($properties as $key => $property) {
63 $object = idx($objects, $property->getObjectPHID());
64 if (!$object) {
65 unset($properties[$key]);
66 continue;
68 $property->attachObject($object);
71 return $properties;
74 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
75 $where = parent::buildWhereClauseParts($conn);
77 if ($this->ids !== null) {
78 $where[] = qsprintf(
79 $conn,
80 'id IN (%Ld)',
81 $this->ids);
84 if ($this->objectPHIDs !== null) {
85 $where[] = qsprintf(
86 $conn,
87 'objectPHID IN (%Ls)',
88 $this->objectPHIDs);
91 if ($this->names !== null) {
92 $hashes = array();
93 foreach ($this->names as $name) {
94 $hashes[] = PhabricatorHash::digestForIndex($name);
96 $where[] = qsprintf(
97 $conn,
98 'fieldIndex IN (%Ls)',
99 $hashes);
102 return $where;
105 public function getQueryApplicationClass() {
106 return 'PhabricatorAlmanacApplication';