Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/countdown/query/PhabricatorCountdownSearchEngine.php
12256 views
1
<?php
2
3
final class PhabricatorCountdownSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
public function getResultTypeDescription() {
7
return pht('Countdowns');
8
}
9
10
public function getApplicationClassName() {
11
return 'PhabricatorCountdownApplication';
12
}
13
14
public function newQuery() {
15
return new PhabricatorCountdownQuery();
16
}
17
18
protected function buildQueryFromParameters(array $map) {
19
$query = $this->newQuery();
20
21
if ($map['authorPHIDs']) {
22
$query->withAuthorPHIDs($map['authorPHIDs']);
23
}
24
25
if ($map['upcoming'] && $map['upcoming'][0] == 'upcoming') {
26
$query->withUpcoming();
27
}
28
29
return $query;
30
}
31
32
protected function buildCustomSearchFields() {
33
return array(
34
id(new PhabricatorUsersSearchField())
35
->setLabel(pht('Authors'))
36
->setKey('authorPHIDs')
37
->setAliases(array('author', 'authors')),
38
id(new PhabricatorSearchCheckboxesField())
39
->setKey('upcoming')
40
->setOptions(
41
array(
42
'upcoming' => pht('Show only upcoming countdowns.'),
43
)),
44
);
45
}
46
47
protected function getURI($path) {
48
return '/countdown/'.$path;
49
}
50
51
protected function getBuiltinQueryNames() {
52
$names = array(
53
'upcoming' => pht('Upcoming'),
54
'all' => pht('All'),
55
);
56
57
if ($this->requireViewer()->getPHID()) {
58
$names['authored'] = pht('Authored');
59
}
60
61
return $names;
62
}
63
64
public function buildSavedQueryFromBuiltin($query_key) {
65
$query = $this->newSavedQuery();
66
$query->setQueryKey($query_key);
67
68
switch ($query_key) {
69
case 'all':
70
return $query;
71
case 'authored':
72
return $query->setParameter(
73
'authorPHIDs',
74
array($this->requireViewer()->getPHID()));
75
case 'upcoming':
76
return $query->setParameter('upcoming', array('upcoming'));
77
}
78
79
return parent::buildSavedQueryFromBuiltin($query_key);
80
}
81
82
protected function getRequiredHandlePHIDsForResultList(
83
array $countdowns,
84
PhabricatorSavedQuery $query) {
85
86
return mpull($countdowns, 'getAuthorPHID');
87
}
88
89
protected function renderResultList(
90
array $countdowns,
91
PhabricatorSavedQuery $query,
92
array $handles) {
93
94
assert_instances_of($countdowns, 'PhabricatorCountdown');
95
96
$viewer = $this->requireViewer();
97
98
$list = new PHUIObjectItemListView();
99
$list->setUser($viewer);
100
foreach ($countdowns as $countdown) {
101
$id = $countdown->getID();
102
$ended = false;
103
$epoch = $countdown->getEpoch();
104
if ($epoch <= PhabricatorTime::getNow()) {
105
$ended = true;
106
}
107
108
$item = id(new PHUIObjectItemView())
109
->setUser($viewer)
110
->setObject($countdown)
111
->setObjectName($countdown->getMonogram())
112
->setHeader($countdown->getTitle())
113
->setHref($countdown->getURI())
114
->addByline(
115
pht(
116
'Created by %s',
117
$handles[$countdown->getAuthorPHID()]->renderLink()));
118
119
if ($ended) {
120
$item->addAttribute(
121
pht('Launched on %s', phabricator_datetime($epoch, $viewer)));
122
$item->setDisabled(true);
123
} else {
124
$time_left = ($epoch - PhabricatorTime::getNow());
125
$num = round($time_left / (60 * 60 * 24));
126
$noun = pht('Days');
127
if ($num < 1) {
128
$num = round($time_left / (60 * 60), 1);
129
$noun = pht('Hours');
130
}
131
$item->setCountdown($num, $noun);
132
$item->addAttribute(
133
phabricator_datetime($epoch, $viewer));
134
}
135
136
$list->addItem($item);
137
}
138
139
$result = new PhabricatorApplicationSearchResultView();
140
$result->setObjectList($list);
141
$result->setNoDataString(pht('No countdowns found.'));
142
143
return $result;
144
}
145
146
protected function getNewUserBody() {
147
$create_button = id(new PHUIButtonView())
148
->setTag('a')
149
->setText(pht('Create a Countdown'))
150
->setHref('/countdown/edit/')
151
->setColor(PHUIButtonView::GREEN);
152
153
$icon = $this->getApplication()->getIcon();
154
$app_name = $this->getApplication()->getName();
155
$view = id(new PHUIBigInfoView())
156
->setIcon($icon)
157
->setTitle(pht('Welcome to %s', $app_name))
158
->setDescription(
159
pht('Keep track of upcoming launch dates with '.
160
'embeddable counters.'))
161
->addAction($create_button);
162
163
return $view;
164
}
165
166
}
167
168