3 final class PhrequentSearchEngine
extends PhabricatorApplicationSearchEngine
{
5 public function getResultTypeDescription() {
6 return pht('Phrequent Time');
9 public function getApplicationClassName() {
10 return 'PhabricatorPhrequentApplication';
13 public function getPageSize(PhabricatorSavedQuery
$saved) {
14 return $saved->getParameter('limit', 1000);
17 public function buildSavedQueryFromRequest(AphrontRequest
$request) {
18 $saved = new PhabricatorSavedQuery();
22 $this->readUsersFromRequest($request, 'users'));
24 $saved->setParameter('ended', $request->getStr('ended'));
26 $saved->setParameter('order', $request->getStr('order'));
31 public function buildQueryFromSavedQuery(PhabricatorSavedQuery
$saved) {
32 $query = id(new PhrequentUserTimeQuery())
33 ->needPreemptingEvents(true);
35 $user_phids = $saved->getParameter('userPHIDs');
37 $query->withUserPHIDs($user_phids);
40 $ended = $saved->getParameter('ended');
42 $query->withEnded($ended);
45 $order = $saved->getParameter('order');
47 $query->setOrder($order);
53 public function buildSearchForm(
54 AphrontFormView
$form,
55 PhabricatorSavedQuery
$saved_query) {
57 $user_phids = $saved_query->getParameter('userPHIDs', array());
58 $ended = $saved_query->getParameter(
59 'ended', PhrequentUserTimeQuery
::ENDED_ALL
);
60 $order = $saved_query->getParameter(
61 'order', PhrequentUserTimeQuery
::ORDER_ENDED_DESC
);
65 id(new AphrontFormTokenizerControl())
66 ->setDatasource(new PhabricatorPeopleDatasource())
68 ->setLabel(pht('Users'))
69 ->setValue($user_phids))
71 id(new AphrontFormSelectControl())
72 ->setLabel(pht('Ended'))
75 ->setOptions(PhrequentUserTimeQuery
::getEndedSearchOptions()))
77 id(new AphrontFormSelectControl())
78 ->setLabel(pht('Order'))
81 ->setOptions(PhrequentUserTimeQuery
::getOrderSearchOptions()));
84 protected function getURI($path) {
85 return '/phrequent/'.$path;
88 protected function getBuiltinQueryNames() {
90 'tracking' => pht('Currently Tracking'),
91 'all' => pht('All Tracked'),
95 public function buildSavedQueryFromBuiltin($query_key) {
96 $query = $this->newSavedQuery();
97 $query->setQueryKey($query_key);
102 ->setParameter('order', PhrequentUserTimeQuery
::ORDER_ENDED_DESC
);
105 ->setParameter('ended', PhrequentUserTimeQuery
::ENDED_NO
)
106 ->setParameter('order', PhrequentUserTimeQuery
::ORDER_ENDED_DESC
);
109 return parent
::buildSavedQueryFromBuiltin($query_key);
112 protected function getRequiredHandlePHIDsForResultList(
114 PhabricatorSavedQuery
$query) {
117 mpull($usertimes, 'getUserPHID'),
118 mpull($usertimes, 'getObjectPHID'),
122 protected function renderResultList(
124 PhabricatorSavedQuery
$query,
126 assert_instances_of($usertimes, 'PhrequentUserTime');
127 $viewer = $this->requireViewer();
129 $view = id(new PHUIObjectItemListView())
132 foreach ($usertimes as $usertime) {
133 $item = new PHUIObjectItemView();
134 if ($usertime->getObjectPHID() === null) {
135 $item->setHeader($usertime->getNote());
137 $obj = $handles[$usertime->getObjectPHID()];
138 $item->setHeader($obj->getLinkName());
139 $item->setHref($obj->getURI());
141 $item->setObject($usertime);
146 $handles[$usertime->getUserPHID()]->renderLink()));
148 $started_date = phabricator_date($usertime->getDateStarted(), $viewer);
149 $item->addIcon('none', $started_date);
151 $block = new PhrequentTimeBlock(array($usertime));
152 $time_spent = $block->getTimeSpentOnObject(
153 $usertime->getObjectPHID(),
154 PhabricatorTime
::getNow());
156 $time_spent = $time_spent == 0 ?
'none' :
157 phutil_format_relative_time_detailed($time_spent);
159 if ($usertime->getDateEnded() !== null) {
167 phabricator_datetime($usertime->getDateEnded(), $viewer)));
173 if ($usertime->getObjectPHID() !== null &&
174 $usertime->getUserPHID() === $viewer->getPHID()) {
176 id(new PHUIListItemView())
178 ->addSigil('phrequent-stop-tracking')
180 ->setRenderNameAsTooltip(true)
181 ->setName(pht('Stop'))
183 '/phrequent/track/stop/'.
184 $usertime->getObjectPHID().'/'));
186 $item->setStatusIcon('fa-clock-o green');
189 $view->addItem($item);
192 $result = new PhabricatorApplicationSearchResultView();
193 $result->setObjectList($view);