@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * @extends AlmanacQuery<AlmanacNamespace>
5 */
6final class AlmanacNamespaceQuery
7 extends AlmanacQuery {
8
9 private $ids;
10 private $phids;
11 private $names;
12
13 public function withIDs(array $ids) {
14 $this->ids = $ids;
15 return $this;
16 }
17
18 public function withPHIDs(array $phids) {
19 $this->phids = $phids;
20 return $this;
21 }
22
23 public function withNames(array $names) {
24 $this->names = $names;
25 return $this;
26 }
27
28 public function withNameNgrams($ngrams) {
29 return $this->withNgramsConstraint(
30 new AlmanacNamespaceNameNgrams(),
31 $ngrams);
32 }
33
34 public function newResultObject() {
35 return new AlmanacNamespace();
36 }
37
38 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
39 $where = parent::buildWhereClauseParts($conn);
40
41 if ($this->ids !== null) {
42 $where[] = qsprintf(
43 $conn,
44 'namespace.id IN (%Ld)',
45 $this->ids);
46 }
47
48 if ($this->phids !== null) {
49 $where[] = qsprintf(
50 $conn,
51 'namespace.phid IN (%Ls)',
52 $this->phids);
53 }
54
55 if ($this->names !== null) {
56 $where[] = qsprintf(
57 $conn,
58 'namespace.name IN (%Ls)',
59 $this->names);
60 }
61
62 return $where;
63 }
64
65 protected function getPrimaryTableAlias() {
66 return 'namespace';
67 }
68
69 public function getOrderableColumns() {
70 return parent::getOrderableColumns() + array(
71 'name' => array(
72 'table' => $this->getPrimaryTableAlias(),
73 'column' => 'name',
74 'type' => 'string',
75 'unique' => true,
76 'reverse' => true,
77 ),
78 );
79 }
80
81 protected function newPagingMapFromPartialObject($object) {
82 return array(
83 'id' => (int)$object->getID(),
84 'name' => $object->getName(),
85 );
86 }
87
88 public function getBuiltinOrders() {
89 return array(
90 'name' => array(
91 'vector' => array('name'),
92 'name' => pht('Namespace Name'),
93 ),
94 ) + parent::getBuiltinOrders();
95 }
96
97 public function getQueryApplicationClass() {
98 return PhabricatorAlmanacApplication::class;
99 }
100
101}