[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class ManiphestTaskSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 private $showBatchControls; 7 private $baseURI; 8 private $isBoardView; 9 10 public function setIsBoardView($is_board_view) { 11 $this->isBoardView = $is_board_view; 12 return $this; 13 } 14 15 public function getIsBoardView() { 16 return $this->isBoardView; 17 } 18 19 public function setBaseURI($base_uri) { 20 $this->baseURI = $base_uri; 21 return $this; 22 } 23 24 public function getBaseURI() { 25 return $this->baseURI; 26 } 27 28 public function setShowBatchControls($show_batch_controls) { 29 $this->showBatchControls = $show_batch_controls; 30 return $this; 31 } 32 33 public function getResultTypeDescription() { 34 return pht('Tasks'); 35 } 36 37 public function getApplicationClassName() { 38 return 'PhabricatorManiphestApplication'; 39 } 40 41 public function getCustomFieldObject() { 42 return new ManiphestTask(); 43 } 44 45 public function buildSavedQueryFromRequest(AphrontRequest $request) { 46 $saved = new PhabricatorSavedQuery(); 47 48 $saved->setParameter( 49 'assignedPHIDs', 50 $this->readUsersFromRequest($request, 'assigned')); 51 52 $saved->setParameter('withUnassigned', $request->getBool('withUnassigned')); 53 54 $saved->setParameter( 55 'authorPHIDs', 56 $this->readUsersFromRequest($request, 'authors')); 57 58 $saved->setParameter( 59 'subscriberPHIDs', 60 $this->readPHIDsFromRequest($request, 'subscribers')); 61 62 $saved->setParameter( 63 'statuses', 64 $this->readListFromRequest($request, 'statuses')); 65 66 $saved->setParameter( 67 'priorities', 68 $this->readListFromRequest($request, 'priorities')); 69 70 $saved->setParameter('group', $request->getStr('group')); 71 $saved->setParameter('order', $request->getStr('order')); 72 73 $ids = $request->getStrList('ids'); 74 foreach ($ids as $key => $id) { 75 $id = trim($id, ' Tt'); 76 if (!$id || !is_numeric($id)) { 77 unset($ids[$key]); 78 } else { 79 $ids[$key] = $id; 80 } 81 } 82 $saved->setParameter('ids', $ids); 83 84 $saved->setParameter('fulltext', $request->getStr('fulltext')); 85 86 $saved->setParameter( 87 'allProjectPHIDs', 88 $this->readPHIDsFromRequest($request, 'allProjects')); 89 90 $saved->setParameter( 91 'withNoProject', 92 $request->getBool('withNoProject')); 93 94 $saved->setParameter( 95 'anyProjectPHIDs', 96 $this->readPHIDsFromRequest($request, 'anyProjects')); 97 98 $saved->setParameter( 99 'excludeProjectPHIDs', 100 $this->readPHIDsFromRequest($request, 'excludeProjects')); 101 102 $saved->setParameter( 103 'userProjectPHIDs', 104 $this->readUsersFromRequest($request, 'userProjects')); 105 106 $saved->setParameter('createdStart', $request->getStr('createdStart')); 107 $saved->setParameter('createdEnd', $request->getStr('createdEnd')); 108 $saved->setParameter('modifiedStart', $request->getStr('modifiedStart')); 109 $saved->setParameter('modifiedEnd', $request->getStr('modifiedEnd')); 110 111 $limit = $request->getInt('limit'); 112 if ($limit > 0) { 113 $saved->setParameter('limit', $limit); 114 } 115 116 $this->readCustomFieldsFromRequest($request, $saved); 117 118 return $saved; 119 } 120 121 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 122 $query = id(new ManiphestTaskQuery()); 123 124 $author_phids = $saved->getParameter('authorPHIDs'); 125 if ($author_phids) { 126 $query->withAuthors($author_phids); 127 } 128 129 $subscriber_phids = $saved->getParameter('subscriberPHIDs'); 130 if ($subscriber_phids) { 131 $query->withSubscribers($subscriber_phids); 132 } 133 134 $with_unassigned = $saved->getParameter('withUnassigned'); 135 if ($with_unassigned) { 136 $query->withOwners(array(null)); 137 } else { 138 $assigned_phids = $saved->getParameter('assignedPHIDs', array()); 139 if ($assigned_phids) { 140 $query->withOwners($assigned_phids); 141 } 142 } 143 144 $statuses = $saved->getParameter('statuses'); 145 if ($statuses) { 146 $query->withStatuses($statuses); 147 } 148 149 $priorities = $saved->getParameter('priorities'); 150 if ($priorities) { 151 $query->withPriorities($priorities); 152 } 153 154 $this->applyOrderByToQuery( 155 $query, 156 $this->getOrderValues(), 157 $saved->getParameter('order')); 158 159 $group = $saved->getParameter('group'); 160 $group = idx($this->getGroupValues(), $group); 161 if ($group) { 162 $query->setGroupBy($group); 163 } else { 164 $query->setGroupBy(head($this->getGroupValues())); 165 } 166 167 $ids = $saved->getParameter('ids'); 168 if ($ids) { 169 $query->withIDs($ids); 170 } 171 172 $fulltext = $saved->getParameter('fulltext'); 173 if (strlen($fulltext)) { 174 $query->withFullTextSearch($fulltext); 175 } 176 177 $with_no_project = $saved->getParameter('withNoProject'); 178 if ($with_no_project) { 179 $query->withAllProjects(array(ManiphestTaskOwner::PROJECT_NO_PROJECT)); 180 } else { 181 $project_phids = $saved->getParameter('allProjectPHIDs'); 182 if ($project_phids) { 183 $query->withAllProjects($project_phids); 184 } 185 } 186 187 $any_project_phids = $saved->getParameter('anyProjectPHIDs'); 188 if ($any_project_phids) { 189 $query->withAnyProjects($any_project_phids); 190 } 191 192 $exclude_project_phids = $saved->getParameter('excludeProjectPHIDs'); 193 if ($exclude_project_phids) { 194 $query->withoutProjects($exclude_project_phids); 195 } 196 197 $user_project_phids = $saved->getParameter('userProjectPHIDs'); 198 if ($user_project_phids) { 199 $query->withAnyUserProjects($user_project_phids); 200 } 201 202 $start = $this->parseDateTime($saved->getParameter('createdStart')); 203 $end = $this->parseDateTime($saved->getParameter('createdEnd')); 204 205 if ($start) { 206 $query->withDateCreatedAfter($start); 207 } 208 209 if ($end) { 210 $query->withDateCreatedBefore($end); 211 } 212 213 $mod_start = $this->parseDateTime($saved->getParameter('modifiedStart')); 214 $mod_end = $this->parseDateTime($saved->getParameter('modifiedEnd')); 215 216 if ($mod_start) { 217 $query->withDateModifiedAfter($mod_start); 218 } 219 220 if ($mod_end) { 221 $query->withDateModifiedBefore($mod_end); 222 } 223 224 $this->applyCustomFieldsToQuery($query, $saved); 225 226 return $query; 227 } 228 229 public function buildSearchForm( 230 AphrontFormView $form, 231 PhabricatorSavedQuery $saved) { 232 233 $assigned_phids = $saved->getParameter('assignedPHIDs', array()); 234 $author_phids = $saved->getParameter('authorPHIDs', array()); 235 $all_project_phids = $saved->getParameter( 236 'allProjectPHIDs', 237 array()); 238 $any_project_phids = $saved->getParameter( 239 'anyProjectPHIDs', 240 array()); 241 $exclude_project_phids = $saved->getParameter( 242 'excludeProjectPHIDs', 243 array()); 244 $user_project_phids = $saved->getParameter( 245 'userProjectPHIDs', 246 array()); 247 $subscriber_phids = $saved->getParameter('subscriberPHIDs', array()); 248 249 $all_phids = array_merge( 250 $assigned_phids, 251 $author_phids, 252 $all_project_phids, 253 $any_project_phids, 254 $exclude_project_phids, 255 $user_project_phids, 256 $subscriber_phids); 257 258 if ($all_phids) { 259 $handles = id(new PhabricatorHandleQuery()) 260 ->setViewer($this->requireViewer()) 261 ->withPHIDs($all_phids) 262 ->execute(); 263 } else { 264 $handles = array(); 265 } 266 267 $assigned_handles = array_select_keys($handles, $assigned_phids); 268 $author_handles = array_select_keys($handles, $author_phids); 269 $all_project_handles = array_select_keys($handles, $all_project_phids); 270 $any_project_handles = array_select_keys($handles, $any_project_phids); 271 $exclude_project_handles = array_select_keys( 272 $handles, 273 $exclude_project_phids); 274 $user_project_handles = array_select_keys($handles, $user_project_phids); 275 $subscriber_handles = array_select_keys($handles, $subscriber_phids); 276 277 $with_unassigned = $saved->getParameter('withUnassigned'); 278 $with_no_projects = $saved->getParameter('withNoProject'); 279 280 $statuses = $saved->getParameter('statuses', array()); 281 $statuses = array_fuse($statuses); 282 $status_control = id(new AphrontFormCheckboxControl()) 283 ->setLabel(pht('Status')); 284 foreach (ManiphestTaskStatus::getTaskStatusMap() as $status => $name) { 285 $status_control->addCheckbox( 286 'statuses[]', 287 $status, 288 $name, 289 isset($statuses[$status])); 290 } 291 292 $priorities = $saved->getParameter('priorities', array()); 293 $priorities = array_fuse($priorities); 294 $priority_control = id(new AphrontFormCheckboxControl()) 295 ->setLabel(pht('Priority')); 296 foreach (ManiphestTaskPriority::getTaskPriorityMap() as $pri => $name) { 297 $priority_control->addCheckbox( 298 'priorities[]', 299 $pri, 300 $name, 301 isset($priorities[$pri])); 302 } 303 304 $ids = $saved->getParameter('ids', array()); 305 306 $builtin_orders = $this->getOrderOptions(); 307 $custom_orders = $this->getCustomFieldOrderOptions(); 308 $all_orders = $builtin_orders + $custom_orders; 309 310 $form 311 ->appendChild( 312 id(new AphrontFormTokenizerControl()) 313 ->setDatasource(new PhabricatorPeopleDatasource()) 314 ->setName('assigned') 315 ->setLabel(pht('Assigned To')) 316 ->setValue($assigned_handles)) 317 ->appendChild( 318 id(new AphrontFormCheckboxControl()) 319 ->addCheckbox( 320 'withUnassigned', 321 1, 322 pht('Show only unassigned tasks.'), 323 $with_unassigned)) 324 ->appendChild( 325 id(new AphrontFormTokenizerControl()) 326 ->setDatasource(new PhabricatorProjectDatasource()) 327 ->setName('allProjects') 328 ->setLabel(pht('In All Projects')) 329 ->setValue($all_project_handles)); 330 331 if (!$this->getIsBoardView()) { 332 $form 333 ->appendChild( 334 id(new AphrontFormCheckboxControl()) 335 ->addCheckbox( 336 'withNoProject', 337 1, 338 pht('Show only tasks with no projects.'), 339 $with_no_projects)); 340 } 341 342 $form 343 ->appendChild( 344 id(new AphrontFormTokenizerControl()) 345 ->setDatasource(new PhabricatorProjectDatasource()) 346 ->setName('anyProjects') 347 ->setLabel(pht('In Any Project')) 348 ->setValue($any_project_handles)) 349 ->appendChild( 350 id(new AphrontFormTokenizerControl()) 351 ->setDatasource(new PhabricatorProjectDatasource()) 352 ->setName('excludeProjects') 353 ->setLabel(pht('Not In Projects')) 354 ->setValue($exclude_project_handles)) 355 ->appendChild( 356 id(new AphrontFormTokenizerControl()) 357 ->setDatasource(new PhabricatorPeopleDatasource()) 358 ->setName('userProjects') 359 ->setLabel(pht('In Users\' Projects')) 360 ->setValue($user_project_handles)) 361 ->appendChild( 362 id(new AphrontFormTokenizerControl()) 363 ->setDatasource(new PhabricatorPeopleDatasource()) 364 ->setName('authors') 365 ->setLabel(pht('Authors')) 366 ->setValue($author_handles)) 367 ->appendChild( 368 id(new AphrontFormTokenizerControl()) 369 ->setDatasource(new PhabricatorMetaMTAMailableDatasource()) 370 ->setName('subscribers') 371 ->setLabel(pht('Subscribers')) 372 ->setValue($subscriber_handles)) 373 ->appendChild($status_control) 374 ->appendChild($priority_control); 375 376 if (!$this->getIsBoardView()) { 377 $form 378 ->appendChild( 379 id(new AphrontFormSelectControl()) 380 ->setName('group') 381 ->setLabel(pht('Group By')) 382 ->setValue($saved->getParameter('group')) 383 ->setOptions($this->getGroupOptions())) 384 ->appendChild( 385 id(new AphrontFormSelectControl()) 386 ->setName('order') 387 ->setLabel(pht('Order By')) 388 ->setValue($saved->getParameter('order')) 389 ->setOptions($all_orders)); 390 } 391 392 $form 393 ->appendChild( 394 id(new AphrontFormTextControl()) 395 ->setName('fulltext') 396 ->setLabel(pht('Contains Words')) 397 ->setValue($saved->getParameter('fulltext'))) 398 ->appendChild( 399 id(new AphrontFormTextControl()) 400 ->setName('ids') 401 ->setLabel(pht('Task IDs')) 402 ->setValue(implode(', ', $ids))); 403 404 $this->appendCustomFieldsToForm($form, $saved); 405 406 $this->buildDateRange( 407 $form, 408 $saved, 409 'createdStart', 410 pht('Created After'), 411 'createdEnd', 412 pht('Created Before')); 413 414 $this->buildDateRange( 415 $form, 416 $saved, 417 'modifiedStart', 418 pht('Updated After'), 419 'modifiedEnd', 420 pht('Updated Before')); 421 422 if (!$this->getIsBoardView()) { 423 $form 424 ->appendChild( 425 id(new AphrontFormTextControl()) 426 ->setName('limit') 427 ->setLabel(pht('Page Size')) 428 ->setValue($saved->getParameter('limit', 100))); 429 } 430 } 431 432 protected function getURI($path) { 433 if ($this->baseURI) { 434 return $this->baseURI.$path; 435 } 436 return '/maniphest/'.$path; 437 } 438 439 public function getBuiltinQueryNames() { 440 $names = array(); 441 442 if ($this->requireViewer()->isLoggedIn()) { 443 $names['assigned'] = pht('Assigned'); 444 $names['authored'] = pht('Authored'); 445 $names['subscribed'] = pht('Subscribed'); 446 } 447 448 $names['open'] = pht('Open Tasks'); 449 $names['all'] = pht('All Tasks'); 450 451 return $names; 452 } 453 454 public function buildSavedQueryFromBuiltin($query_key) { 455 456 $query = $this->newSavedQuery(); 457 $query->setQueryKey($query_key); 458 459 $viewer_phid = $this->requireViewer()->getPHID(); 460 461 switch ($query_key) { 462 case 'all': 463 return $query; 464 case 'assigned': 465 return $query 466 ->setParameter('assignedPHIDs', array($viewer_phid)) 467 ->setParameter( 468 'statuses', 469 ManiphestTaskStatus::getOpenStatusConstants()); 470 case 'subscribed': 471 return $query 472 ->setParameter('subscriberPHIDs', array($viewer_phid)) 473 ->setParameter( 474 'statuses', 475 ManiphestTaskStatus::getOpenStatusConstants()); 476 case 'open': 477 return $query 478 ->setParameter( 479 'statuses', 480 ManiphestTaskStatus::getOpenStatusConstants()); 481 case 'authored': 482 return $query 483 ->setParameter('authorPHIDs', array($viewer_phid)) 484 ->setParameter('order', 'created') 485 ->setParameter('group', 'none'); 486 } 487 488 return parent::buildSavedQueryFromBuiltin($query_key); 489 } 490 491 private function getOrderOptions() { 492 return array( 493 'priority' => pht('Priority'), 494 'updated' => pht('Date Updated'), 495 'created' => pht('Date Created'), 496 'title' => pht('Title'), 497 ); 498 } 499 500 private function getOrderValues() { 501 return array( 502 'priority' => ManiphestTaskQuery::ORDER_PRIORITY, 503 'updated' => ManiphestTaskQuery::ORDER_MODIFIED, 504 'created' => ManiphestTaskQuery::ORDER_CREATED, 505 'title' => ManiphestTaskQuery::ORDER_TITLE, 506 ); 507 } 508 509 private function getGroupOptions() { 510 return array( 511 'priority' => pht('Priority'), 512 'assigned' => pht('Assigned'), 513 'status' => pht('Status'), 514 'project' => pht('Project'), 515 'none' => pht('None'), 516 ); 517 } 518 519 private function getGroupValues() { 520 return array( 521 'priority' => ManiphestTaskQuery::GROUP_PRIORITY, 522 'assigned' => ManiphestTaskQuery::GROUP_OWNER, 523 'status' => ManiphestTaskQuery::GROUP_STATUS, 524 'project' => ManiphestTaskQuery::GROUP_PROJECT, 525 'none' => ManiphestTaskQuery::GROUP_NONE, 526 ); 527 } 528 529 protected function renderResultList( 530 array $tasks, 531 PhabricatorSavedQuery $saved, 532 array $handles) { 533 534 $viewer = $this->requireViewer(); 535 536 if ($this->isPanelContext()) { 537 $can_edit_priority = false; 538 $can_bulk_edit = false; 539 } else { 540 $can_edit_priority = PhabricatorPolicyFilter::hasCapability( 541 $viewer, 542 $this->getApplication(), 543 ManiphestEditPriorityCapability::CAPABILITY); 544 545 $can_bulk_edit = PhabricatorPolicyFilter::hasCapability( 546 $viewer, 547 $this->getApplication(), 548 ManiphestBulkEditCapability::CAPABILITY); 549 } 550 551 return id(new ManiphestTaskResultListView()) 552 ->setUser($viewer) 553 ->setTasks($tasks) 554 ->setSavedQuery($saved) 555 ->setCanEditPriority($can_edit_priority) 556 ->setCanBatchEdit($can_bulk_edit) 557 ->setShowBatchControls($this->showBatchControls); 558 } 559 560 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |