forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhrequentListController.php
108 lines (88 loc) · 3.09 KB
/
PhrequentListController.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
<?php
final class PhrequentListController extends PhrequentController
implements PhabricatorApplicationSearchResultsControllerInterface {
private $queryKey;
public function shouldAllowPublic() {
return true;
}
public function willProcessRequest(array $data) {
$this->queryKey = idx($data, 'queryKey');
}
public function processRequest() {
$request = $this->getRequest();
$controller = id(new PhabricatorApplicationSearchController($request))
->setQueryKey($this->queryKey)
->setSearchEngine(new PhrequentSearchEngine())
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);
}
public function renderResultsList(
array $usertimes,
PhabricatorSavedQuery $query) {
assert_instances_of($usertimes, 'PhrequentUserTime');
$viewer = $this->getRequest()->getUser();
$phids = array();
$phids[] = mpull($usertimes, 'getUserPHID');
$phids[] = mpull($usertimes, 'getObjectPHID');
$phids = array_mergev($phids);
$handles = $this->loadViewerHandles($phids);
$view = id(new PHUIObjectItemListView())
->setUser($viewer);
foreach ($usertimes as $usertime) {
$item = new PHUIObjectItemView();
if ($usertime->getObjectPHID() === null) {
$item->setHeader($usertime->getNote());
} else {
$obj = $handles[$usertime->getObjectPHID()];
$item->setHeader($obj->getLinkName());
$item->setHref($obj->getURI());
}
$item->setObject($usertime);
$item->addByline(
pht(
'Tracked: %s',
$handles[$usertime->getUserPHID()]->renderLink()));
$started_date = phabricator_date($usertime->getDateStarted(), $viewer);
$item->addIcon('none', $started_date);
if ($usertime->getDateEnded() !== null) {
$time_spent = $usertime->getDateEnded() - $usertime->getDateStarted();
$time_ended = phabricator_datetime($usertime->getDateEnded(), $viewer);
} else {
$time_spent = time() - $usertime->getDateStarted();
}
$time_spent = $time_spent == 0 ? 'none' :
phabricator_format_relative_time_detailed($time_spent);
if ($usertime->getDateEnded() !== null) {
$item->addAttribute(
pht(
'Tracked %s',
$time_spent));
$item->addAttribute(
pht(
'Ended on %s',
$time_ended));
} else {
$item->addAttribute(
pht(
'Tracked %s so far',
$time_spent));
if ($usertime->getObjectPHID() !== null &&
$usertime->getUserPHID() === $viewer->getPHID()) {
$item->addAction(
id(new PHUIListItemView())
->setIcon('history')
->addSigil('phrequent-stop-tracking')
->setWorkflow(true)
->setRenderNameAsTooltip(true)
->setName(pht("Stop"))
->setHref(
'/phrequent/track/stop/'.
$usertime->getObjectPHID().'/'));
}
$item->setBarColor('green');
}
$view->addItem($item);
}
return $view;
}
}