Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / phrequent / query / PhrequentSearchEngine.php
blobd137c40b64833873e7ff35c19327321fce633894
1 <?php
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();
20 $saved->setParameter(
21 'userPHIDs',
22 $this->readUsersFromRequest($request, 'users'));
24 $saved->setParameter('ended', $request->getStr('ended'));
26 $saved->setParameter('order', $request->getStr('order'));
28 return $saved;
31 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
32 $query = id(new PhrequentUserTimeQuery())
33 ->needPreemptingEvents(true);
35 $user_phids = $saved->getParameter('userPHIDs');
36 if ($user_phids) {
37 $query->withUserPHIDs($user_phids);
40 $ended = $saved->getParameter('ended');
41 if ($ended != null) {
42 $query->withEnded($ended);
45 $order = $saved->getParameter('order');
46 if ($order != null) {
47 $query->setOrder($order);
50 return $query;
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);
63 $form
64 ->appendControl(
65 id(new AphrontFormTokenizerControl())
66 ->setDatasource(new PhabricatorPeopleDatasource())
67 ->setName('users')
68 ->setLabel(pht('Users'))
69 ->setValue($user_phids))
70 ->appendChild(
71 id(new AphrontFormSelectControl())
72 ->setLabel(pht('Ended'))
73 ->setName('ended')
74 ->setValue($ended)
75 ->setOptions(PhrequentUserTimeQuery::getEndedSearchOptions()))
76 ->appendChild(
77 id(new AphrontFormSelectControl())
78 ->setLabel(pht('Order'))
79 ->setName('order')
80 ->setValue($order)
81 ->setOptions(PhrequentUserTimeQuery::getOrderSearchOptions()));
84 protected function getURI($path) {
85 return '/phrequent/'.$path;
88 protected function getBuiltinQueryNames() {
89 return array(
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);
99 switch ($query_key) {
100 case 'all':
101 return $query
102 ->setParameter('order', PhrequentUserTimeQuery::ORDER_ENDED_DESC);
103 case 'tracking':
104 return $query
105 ->setParameter('ended', PhrequentUserTimeQuery::ENDED_NO)
106 ->setParameter('order', PhrequentUserTimeQuery::ORDER_ENDED_DESC);
109 return parent::buildSavedQueryFromBuiltin($query_key);
112 protected function getRequiredHandlePHIDsForResultList(
113 array $usertimes,
114 PhabricatorSavedQuery $query) {
115 return array_mergev(
116 array(
117 mpull($usertimes, 'getUserPHID'),
118 mpull($usertimes, 'getObjectPHID'),
122 protected function renderResultList(
123 array $usertimes,
124 PhabricatorSavedQuery $query,
125 array $handles) {
126 assert_instances_of($usertimes, 'PhrequentUserTime');
127 $viewer = $this->requireViewer();
129 $view = id(new PHUIObjectItemListView())
130 ->setUser($viewer);
132 foreach ($usertimes as $usertime) {
133 $item = new PHUIObjectItemView();
134 if ($usertime->getObjectPHID() === null) {
135 $item->setHeader($usertime->getNote());
136 } else {
137 $obj = $handles[$usertime->getObjectPHID()];
138 $item->setHeader($obj->getLinkName());
139 $item->setHref($obj->getURI());
141 $item->setObject($usertime);
143 $item->addByline(
144 pht(
145 'Tracked: %s',
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) {
160 $item->addAttribute(
161 pht(
162 'Tracked %s',
163 $time_spent));
164 $item->addAttribute(
165 pht(
166 'Ended on %s',
167 phabricator_datetime($usertime->getDateEnded(), $viewer)));
168 } else {
169 $item->addAttribute(
170 pht(
171 'Tracked %s so far',
172 $time_spent));
173 if ($usertime->getObjectPHID() !== null &&
174 $usertime->getUserPHID() === $viewer->getPHID()) {
175 $item->addAction(
176 id(new PHUIListItemView())
177 ->setIcon('fa-stop')
178 ->addSigil('phrequent-stop-tracking')
179 ->setWorkflow(true)
180 ->setRenderNameAsTooltip(true)
181 ->setName(pht('Stop'))
182 ->setHref(
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);
195 return $result;