3 final class PhabricatorSearchRelationshipSourceController
4 extends PhabricatorSearchBaseController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $request->getViewer();
9 $object = $this->loadRelationshipObject();
11 return new Aphront404Response();
14 $relationship = $this->loadRelationship($object);
16 return new Aphront404Response();
19 $source = $relationship->newSource();
20 $query = new PhabricatorSavedQuery();
22 $action = $request->getURIData('action');
23 $query_str = $request->getStr('query');
24 $filter = $request->getStr('filter');
26 $query->setEngineClassName('PhabricatorSearchApplicationSearchEngine');
27 $query->setParameter('query', $query_str);
29 $types = $source->getResultPHIDTypes();
30 $query->setParameter('types', $types);
32 $status_open = PhabricatorSearchRelationship
::RELATIONSHIP_OPEN
;
36 $query->setParameter('ownerPHIDs', array($viewer->getPHID()));
37 $query->setParameter('statuses', array($status_open));
40 $query->setParameter('authorPHIDs', array($viewer->getPHID()));
41 $query->setParameter('statuses', array($status_open));
44 $query->setParameter('statuses', array($status_open));
48 $query->setParameter('excludePHIDs', array($request->getStr('exclude')));
50 $capabilities = $relationship->getRequiredRelationshipCapabilities();
52 $results = id(new PhabricatorSearchDocumentQuery())
54 ->requireObjectCapabilities($capabilities)
55 ->withSavedQuery($query)
60 $phids = array_fill_keys(mpull($results, 'getPHID'), true);
61 $phids = $this->queryObjectNames($query, $capabilities) +
$phids;
63 $phids = array_keys($phids);
64 $handles = $viewer->loadHandles($phids);
67 foreach ($handles as $handle) {
68 $view = new PhabricatorHandleObjectSelectorDataView($handle);
69 $data[] = $view->renderData();
72 return id(new AphrontAjaxResponse())->setContent($data);
75 private function queryObjectNames(
76 PhabricatorSavedQuery
$query,
77 array $capabilities) {
79 $request = $this->getRequest();
80 $viewer = $request->getUser();
82 $types = $query->getParameter('types');
83 $match = $query->getParameter('query');
85 $objects = id(new PhabricatorObjectQuery())
87 ->requireCapabilities($capabilities)
88 ->withTypes($query->getParameter('types'))
89 ->withNames(array($match))
92 return mpull($objects, 'getPHID');