forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorApplicationQuery.php
159 lines (131 loc) · 3.49 KB
/
PhabricatorApplicationQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
final class PhabricatorApplicationQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $installed;
private $beta;
private $firstParty;
private $nameContains;
private $unlisted;
private $classes;
private $launchable;
private $phids;
const ORDER_APPLICATION = 'order:application';
const ORDER_NAME = 'order:name';
private $order = self::ORDER_APPLICATION;
public function withNameContains($name_contains) {
$this->nameContains = $name_contains;
return $this;
}
public function withInstalled($installed) {
$this->installed = $installed;
return $this;
}
public function withBeta($beta) {
$this->beta = $beta;
return $this;
}
public function withFirstParty($first_party) {
$this->firstParty = $first_party;
return $this;
}
public function withUnlisted($unlisted) {
$this->unlisted = $unlisted;
return $this;
}
public function withLaunchable($launchable) {
$this->launchable = $launchable;
return $this;
}
public function withClasses(array $classes) {
$this->classes = $classes;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function setOrder($order) {
$this->order = $order;
return $this;
}
public function loadPage() {
$apps = PhabricatorApplication::getAllApplications();
if ($this->classes) {
$classes = array_fuse($this->classes);
foreach ($apps as $key => $app) {
if (empty($classes[get_class($app)])) {
unset($apps[$key]);
}
}
}
if ($this->phids) {
$phids = array_fuse($this->phids);
foreach ($apps as $key => $app) {
if (empty($phids[$app->getPHID()])) {
unset($apps[$key]);
}
}
}
if (strlen($this->nameContains)) {
foreach ($apps as $key => $app) {
if (stripos($app->getName(), $this->nameContains) === false) {
unset($apps[$key]);
}
}
}
if ($this->installed !== null) {
foreach ($apps as $key => $app) {
if ($app->isInstalled() != $this->installed) {
unset($apps[$key]);
}
}
}
if ($this->beta !== null) {
foreach ($apps as $key => $app) {
if ($app->isBeta() != $this->beta) {
unset($apps[$key]);
}
}
}
if ($this->firstParty !== null) {
foreach ($apps as $key => $app) {
if ($app->isFirstParty() != $this->firstParty) {
unset($apps[$key]);
}
}
}
if ($this->unlisted !== null) {
foreach ($apps as $key => $app) {
if ($app->isUnlisted() != $this->unlisted) {
unset($apps[$key]);
}
}
}
if ($this->launchable !== null) {
foreach ($apps as $key => $app) {
if ($app->isLaunchable() != $this->launchable) {
unset($apps[$key]);
}
}
}
switch ($this->order) {
case self::ORDER_NAME:
$apps = msort($apps, 'getName');
break;
case self::ORDER_APPLICATION:
$apps = $apps;
break;
default:
throw new Exception(
pht('Unknown order "%s"!', $this->order));
}
return $apps;
}
public function getQueryApplicationClass() {
// NOTE: Although this belongs to the "Applications" application, trying
// to filter its results just leaves us recursing indefinitely. Users
// always have access to applications regardless of other policy settings
// anyway.
return null;
}
}