@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 PhabricatorCursorPagedPolicyAwareQuery<PhabricatorBadgesBadge>
5 */
6final class PhabricatorBadgesQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $phids;
11 private $qualities;
12 private $statuses;
13
14 public function withIDs(array $ids) {
15 $this->ids = $ids;
16 return $this;
17 }
18
19 public function withPHIDs(array $phids) {
20 $this->phids = $phids;
21 return $this;
22 }
23
24 public function withQualities(array $qualities) {
25 $this->qualities = $qualities;
26 return $this;
27 }
28
29 public function withStatuses(array $statuses) {
30 $this->statuses = $statuses;
31 return $this;
32 }
33
34 public function withNameNgrams($ngrams) {
35 return $this->withNgramsConstraint(
36 id(new PhabricatorBadgesBadgeNameNgrams()),
37 $ngrams);
38 }
39
40 protected function getPrimaryTableAlias() {
41 return 'badges';
42 }
43
44 public function newResultObject() {
45 return new PhabricatorBadgesBadge();
46 }
47
48 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
49 $where = parent::buildWhereClauseParts($conn);
50
51 if ($this->ids !== null) {
52 $where[] = qsprintf(
53 $conn,
54 'badges.id IN (%Ld)',
55 $this->ids);
56 }
57
58 if ($this->phids !== null) {
59 $where[] = qsprintf(
60 $conn,
61 'badges.phid IN (%Ls)',
62 $this->phids);
63 }
64
65 if ($this->qualities !== null) {
66 $where[] = qsprintf(
67 $conn,
68 'badges.quality IN (%Ls)',
69 $this->qualities);
70 }
71
72 if ($this->statuses !== null) {
73 $where[] = qsprintf(
74 $conn,
75 'badges.status IN (%Ls)',
76 $this->statuses);
77 }
78
79 return $where;
80 }
81
82 public function getQueryApplicationClass() {
83 return PhabricatorBadgesApplication::class;
84 }
85
86 public function getBuiltinOrders() {
87 return array(
88 'quality' => array(
89 'vector' => array('quality', 'id'),
90 'name' => pht('Rarity (Rarest First)'),
91 ),
92 'shoddiness' => array(
93 'vector' => array('-quality', '-id'),
94 'name' => pht('Rarity (Most Common First)'),
95 ),
96 ) + parent::getBuiltinOrders();
97 }
98
99 public function getOrderableColumns() {
100 return array(
101 'quality' => array(
102 'table' => $this->getPrimaryTableAlias(),
103 'column' => 'quality',
104 'reverse' => true,
105 'type' => 'int',
106 ),
107 ) + parent::getOrderableColumns();
108 }
109
110
111 protected function newPagingMapFromPartialObject($object) {
112 return array(
113 'id' => (int)$object->getID(),
114 'quality' => $object->getQuality(),
115 );
116 }
117
118}