public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $query = new PhabricatorSearchQuery(); $query_str = $request->getStr('query'); $matches = array(); $query->setQuery($query_str); $query->setParameter('type', $this->type); switch ($request->getStr('filter')) { case 'assigned': $query->setParameter('owner', array($user->getPHID())); $query->setParameter('open', 1); break; case 'created': $query->setParameter('author', array($user->getPHID())); $query->setParameter('open', 1); break; case 'open': $query->setParameter('open', 1); break; } $engine = PhabricatorSearchEngineSelector::newSelector()->newEngine(); $results = $engine->executeSearch($query); $phids = array_fill_keys(ipull($results, 'phid'), true); $phids += $this->queryObjectNames($query_str); $phids = array_keys($phids); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $data = array(); foreach ($handles as $handle) { $view = new PhabricatorHandleObjectSelectorDataView($handle); $data[] = $view->renderData(); } return id(new AphrontAjaxResponse())->setContent($data); }
public function handleRequest(AphrontRequest $request) { $user = $request->getUser(); $type = $request->getURIData('type'); $action = $request->getURIData('action'); $query = new PhabricatorSavedQuery(); $query_str = $request->getStr('query'); $query->setEngineClassName('PhabricatorSearchApplicationSearchEngine'); $query->setParameter('query', $query_str); $query->setParameter('types', array($type)); $status_open = PhabricatorSearchRelationship::RELATIONSHIP_OPEN; switch ($request->getStr('filter')) { case 'assigned': $query->setParameter('ownerPHIDs', array($user->getPHID())); $query->setParameter('statuses', array($status_open)); break; case 'created': $query->setParameter('authorPHIDs', array($user->getPHID())); // TODO - if / when we allow pholio mocks to be archived, etc // update this if ($type != PholioMockPHIDType::TYPECONST) { $query->setParameter('statuses', array($status_open)); } break; case 'open': $query->setParameter('statuses', array($status_open)); break; } $query->setParameter('excludePHIDs', array($request->getStr('exclude'))); $capabilities = array(PhabricatorPolicyCapability::CAN_VIEW); switch ($action) { case self::ACTION_MERGE: $capabilities[] = PhabricatorPolicyCapability::CAN_EDIT; break; default: break; } $results = id(new PhabricatorSearchDocumentQuery())->setViewer($user)->requireObjectCapabilities($capabilities)->withSavedQuery($query)->setOffset(0)->setLimit(100)->execute(); $phids = array_fill_keys(mpull($results, 'getPHID'), true); $phids += $this->queryObjectNames($query_str, $capabilities); $phids = array_keys($phids); $handles = $this->loadViewerHandles($phids); $data = array(); foreach ($handles as $handle) { $view = new PhabricatorHandleObjectSelectorDataView($handle); $data[] = $view->renderData(); } return id(new AphrontAjaxResponse())->setContent($data); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $object = $this->loadRelationshipObject(); if (!$object) { return new Aphront404Response(); } $relationship = $this->loadRelationship($object); if (!$relationship) { return new Aphront404Response(); } $source = $relationship->newSource(); $query = new PhabricatorSavedQuery(); $action = $request->getURIData('action'); $query_str = $request->getStr('query'); $filter = $request->getStr('filter'); $query->setEngineClassName('PhabricatorSearchApplicationSearchEngine'); $query->setParameter('query', $query_str); $types = $source->getResultPHIDTypes(); $query->setParameter('types', $types); $status_open = PhabricatorSearchRelationship::RELATIONSHIP_OPEN; switch ($filter) { case 'assigned': $query->setParameter('ownerPHIDs', array($viewer->getPHID())); $query->setParameter('statuses', array($status_open)); break; case 'created': $query->setParameter('authorPHIDs', array($viewer->getPHID())); $query->setParameter('statuses', array($status_open)); break; case 'open': $query->setParameter('statuses', array($status_open)); break; } $query->setParameter('excludePHIDs', array($request->getStr('exclude'))); $capabilities = $relationship->getRequiredRelationshipCapabilities(); $results = id(new PhabricatorSearchDocumentQuery())->setViewer($viewer)->requireObjectCapabilities($capabilities)->withSavedQuery($query)->setOffset(0)->setLimit(100)->execute(); $phids = array_fill_keys(mpull($results, 'getPHID'), true); $phids = $this->queryObjectNames($query, $capabilities) + $phids; $phids = array_keys($phids); $handles = $viewer->loadHandles($phids); $data = array(); foreach ($handles as $handle) { $view = new PhabricatorHandleObjectSelectorDataView($handle); $data[] = $view->renderData(); } return id(new AphrontAjaxResponse())->setContent($data); }
public function buildDialog() { $user = $this->user; $filter_id = celerity_generate_unique_node_id(); $query_id = celerity_generate_unique_node_id(); $results_id = celerity_generate_unique_node_id(); $current_id = celerity_generate_unique_node_id(); $search_id = celerity_generate_unique_node_id(); $form_id = celerity_generate_unique_node_id(); require_celerity_resource('phabricator-object-selector-css'); $options = array(); foreach ($this->filters as $key => $label) { $options[] = phutil_tag('option', array('value' => $key, 'selected' => $key == $this->selectedFilter ? 'selected' : null), $label); } $instructions = null; if ($this->instructions) { $instructions = phutil_tag('p', array('class' => 'phabricator-object-selector-instructions'), $this->instructions); } $search_box = phabricator_form($user, array('method' => 'POST', 'action' => $this->submitURI, 'id' => $search_id), phutil_tag('table', array('class' => 'phabricator-object-selector-search'), phutil_tag('tr', array(), array(phutil_tag('td', array('class' => 'phabricator-object-selector-search-filter'), phutil_tag('select', array('id' => $filter_id), $options)), phutil_tag('td', array('class' => 'phabricator-object-selector-search-text'), phutil_tag('input', array('id' => $query_id, 'type' => 'text'))))))); $result_box = phutil_tag('div', array('class' => 'phabricator-object-selector-results', 'id' => $results_id), ''); $attached_box = phutil_tag_div('phabricator-object-selector-current', phutil_tag_div('phabricator-object-selector-currently-attached', array(phutil_tag_div('phabricator-object-selector-header', $this->header), phutil_tag('div', array('id' => $current_id)), $instructions))); $dialog = new AphrontDialogView(); $dialog->setUser($this->user)->setTitle($this->title)->setClass('phabricator-object-selector-dialog')->appendChild($search_box)->appendChild($result_box)->appendChild($attached_box)->setRenderDialogAsDiv()->setFormID($form_id)->addSubmitButton($this->buttonText); if ($this->cancelURI) { $dialog->addCancelButton($this->cancelURI); } $handle_views = array(); foreach ($this->handles as $handle) { $phid = $handle->getPHID(); $view = new PhabricatorHandleObjectSelectorDataView($handle); $handle_views[$phid] = $view->renderData(); } $dialog->addHiddenInput('phids', implode(';', array_keys($this->handles))); Javelin::initBehavior('phabricator-object-selector', array('filter' => $filter_id, 'query' => $query_id, 'search' => $search_id, 'results' => $results_id, 'current' => $current_id, 'form' => $form_id, 'exclude' => $this->excluded, 'uri' => $this->searchURI, 'handles' => $handle_views)); return $dialog; }
public function buildDialog() { $user = $this->user; $filter_id = celerity_generate_unique_node_id(); $query_id = celerity_generate_unique_node_id(); $results_id = celerity_generate_unique_node_id(); $current_id = celerity_generate_unique_node_id(); $search_id = celerity_generate_unique_node_id(); $form_id = celerity_generate_unique_node_id(); require_celerity_resource('phabricator-object-selector-css'); $options = array(); foreach ($this->filters as $key => $label) { $options[] = phutil_render_tag('option', array('value' => $key, 'selected' => $key == $this->selectedFilter ? 'selected' : null), $label); } $options = implode("\n", $options); $instructions = null; if ($this->instructions) { $instructions = '<p class="phabricator-object-selector-instructions">' . $this->instructions . '</p>'; } $search_box = phabricator_render_form($user, array('method' => 'POST', 'action' => $this->submitURI, 'id' => $search_id), '<table class="phabricator-object-selector-search"> <tr> <td class="phabricator-object-selector-search-filter"> <select id="' . $filter_id . '">' . $options . '</select> </td> <td class="phabricator-object-selector-search-text"> <input type="text" id="' . $query_id . '" /> </td> </tr> </table>'); $result_box = '<div class="phabricator-object-selector-results" id="' . $results_id . '">' . '</div>'; $attached_box = '<div class="phabricator-object-selector-current">' . '<div class="phabricator-object-selector-currently-attached">' . '<div class="phabricator-object-selector-header">' . phutil_escape_html($this->header) . '</div>' . '<div id="' . $current_id . '">' . '</div>' . $instructions . '</div>' . '</div>'; $dialog = new AphrontDialogView(); $dialog->setUser($this->user)->setTitle($this->title)->setClass('phabricator-object-selector-dialog')->appendChild($search_box)->appendChild($result_box)->appendChild($attached_box)->setRenderDialogAsDiv()->setFormID($form_id)->addSubmitButton($this->buttonText); if ($this->cancelURI) { $dialog->addCancelButton($this->cancelURI); } $handle_views = array(); foreach ($this->handles as $handle) { $phid = $handle->getPHID(); $view = new PhabricatorHandleObjectSelectorDataView($handle); $handle_views[$phid] = $view->renderData(); } $dialog->addHiddenInput('phids', implode(';', array_keys($this->handles))); Javelin::initBehavior('phabricator-object-selector', array('filter' => $filter_id, 'query' => $query_id, 'search' => $search_id, 'results' => $results_id, 'current' => $current_id, 'form' => $form_id, 'exclude' => $this->excluded, 'uri' => $this->searchURI, 'handles' => $handle_views)); return $dialog; }