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