2011-02-16 22:14:09 -08:00
|
|
|
<?php
|
|
|
|
|
2012-03-09 15:46:25 -08:00
|
|
|
final class PhabricatorSearchSelectController
|
|
|
|
extends PhabricatorSearchBaseController {
|
2011-05-16 11:43:39 -07:00
|
|
|
|
2015-05-18 13:07:05 -07:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
2011-02-16 22:14:09 -08:00
|
|
|
$user = $request->getUser();
|
2015-05-18 13:07:05 -07:00
|
|
|
$type = $request->getURIData('type');
|
|
|
|
$action = $request->getURIData('action');
|
2011-02-16 22:14:09 -08:00
|
|
|
|
2014-02-03 12:51:08 -08:00
|
|
|
$query = new PhabricatorSavedQuery();
|
2011-04-05 22:32:37 -07:00
|
|
|
$query_str = $request->getStr('query');
|
|
|
|
|
2014-02-03 12:51:08 -08:00
|
|
|
$query->setEngineClassName('PhabricatorSearchApplicationSearchEngine');
|
|
|
|
$query->setParameter('query', $query_str);
|
2015-05-18 13:07:05 -07:00
|
|
|
$query->setParameter('types', array($type));
|
2011-02-16 22:14:09 -08:00
|
|
|
|
2014-02-11 07:45:33 -08:00
|
|
|
$status_open = PhabricatorSearchRelationship::RELATIONSHIP_OPEN;
|
|
|
|
|
2011-02-18 17:16:00 -08:00
|
|
|
switch ($request->getStr('filter')) {
|
|
|
|
case 'assigned':
|
2014-02-11 07:45:33 -08:00
|
|
|
$query->setParameter('ownerPHIDs', array($user->getPHID()));
|
|
|
|
$query->setParameter('statuses', array($status_open));
|
2011-02-18 17:16:00 -08:00
|
|
|
break;
|
|
|
|
case 'created';
|
2014-02-11 07:45:33 -08:00
|
|
|
$query->setParameter('authorPHIDs', array($user->getPHID()));
|
2013-07-19 15:59:29 -07:00
|
|
|
// TODO - if / when we allow pholio mocks to be archived, etc
|
|
|
|
// update this
|
2015-05-18 13:07:05 -07:00
|
|
|
if ($type != PholioMockPHIDType::TYPECONST) {
|
2014-02-11 07:45:33 -08:00
|
|
|
$query->setParameter('statuses', array($status_open));
|
2013-07-19 15:59:29 -07:00
|
|
|
}
|
2011-02-18 17:16:00 -08:00
|
|
|
break;
|
|
|
|
case 'open':
|
2014-02-11 07:45:33 -08:00
|
|
|
$query->setParameter('statuses', array($status_open));
|
2011-02-18 17:16:00 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-11 07:45:33 -08:00
|
|
|
$query->setParameter('excludePHIDs', array($request->getStr('exclude')));
|
2012-04-03 18:34:55 -07:00
|
|
|
|
2015-05-18 13:07:05 -07:00
|
|
|
$capabilities = array(PhabricatorPolicyCapability::CAN_VIEW);
|
|
|
|
switch ($action) {
|
|
|
|
case self::ACTION_MERGE:
|
|
|
|
$capabilities[] = PhabricatorPolicyCapability::CAN_EDIT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-11 07:45:33 -08:00
|
|
|
$results = id(new PhabricatorSearchDocumentQuery())
|
|
|
|
->setViewer($user)
|
2015-05-18 13:07:05 -07:00
|
|
|
->requireObjectCapabilities($capabilities)
|
2014-02-11 07:45:33 -08:00
|
|
|
->withSavedQuery($query)
|
|
|
|
->setOffset(0)
|
|
|
|
->setLimit(100)
|
|
|
|
->execute();
|
2011-02-17 14:32:01 -08:00
|
|
|
|
2014-02-11 07:45:33 -08:00
|
|
|
$phids = array_fill_keys(mpull($results, 'getPHID'), true);
|
2015-05-18 13:07:05 -07:00
|
|
|
$phids += $this->queryObjectNames($query_str, $capabilities);
|
2011-04-05 22:32:37 -07:00
|
|
|
|
|
|
|
$phids = array_keys($phids);
|
2012-09-04 19:02:56 -07:00
|
|
|
$handles = $this->loadViewerHandles($phids);
|
2011-02-16 22:14:09 -08:00
|
|
|
|
|
|
|
$data = array();
|
2011-02-17 14:32:01 -08:00
|
|
|
foreach ($handles as $handle) {
|
|
|
|
$view = new PhabricatorHandleObjectSelectorDataView($handle);
|
|
|
|
$data[] = $view->renderData();
|
2011-02-16 22:14:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())->setContent($data);
|
|
|
|
}
|
2011-05-16 11:43:39 -07:00
|
|
|
|
2015-05-18 13:07:05 -07:00
|
|
|
private function queryObjectNames($query, $capabilities) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
2011-05-16 11:43:39 -07:00
|
|
|
|
2013-10-02 13:11:44 -07:00
|
|
|
$objects = id(new PhabricatorObjectQuery())
|
|
|
|
->setViewer($viewer)
|
2015-05-18 13:07:05 -07:00
|
|
|
->requireCapabilities($capabilities)
|
|
|
|
->withTypes(array($request->getURIData('type')))
|
2013-10-02 13:11:44 -07:00
|
|
|
->withNames(array($query))
|
|
|
|
->execute();
|
2011-05-16 11:43:39 -07:00
|
|
|
|
2013-10-02 13:11:44 -07:00
|
|
|
return mpull($objects, 'getPHID');
|
2011-05-16 11:43:39 -07:00
|
|
|
}
|
|
|
|
|
2011-02-16 22:14:09 -08:00
|
|
|
}
|