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;
     }
     $exec = new PhabricatorSearchMySQLExecutor();
     $results = $exec->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 processRequest()
 {
     $executor = new PhabricatorSearchMySQLExecutor();
     $document = $executor->reconstructDocument($this->phid);
     if (!$document) {
         return new Aphront404Response();
     }
     $panels = array();
     $panel = new AphrontPanelView();
     $panel->setHeader('Abstract Document Index');
     $props = array('PHID' => phutil_escape_html($document->getPHID()), 'Title' => phutil_escape_html($document->getDocumentTitle()), 'Type' => phutil_escape_html($document->getDocumentType()));
     $rows = array();
     foreach ($props as $name => $value) {
         $rows[] = array($name, $value);
     }
     $table = new AphrontTableView($rows);
     $table->setColumnClasses(array('header', ''));
     $panel->appendChild($table);
     $panels[] = $panel;
     $panel = new AphrontPanelView();
     $panel->setHeader('Document Fields');
     $fields = $document->getFieldData();
     $rows = array();
     foreach ($fields as $field) {
         list($name, $corpus, $aux_phid) = $field;
         $rows[] = array(phutil_escape_html($name), phutil_escape_html(nonempty($aux_phid, null)), str_replace("\n", '<br />', phutil_escape_html($corpus)));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Field', 'Aux PHID', 'Corpus'));
     $table->setColumnClasses(array('', '', 'wide'));
     $panel->appendChild($table);
     $panels[] = $panel;
     $panel = new AphrontPanelView();
     $panel->setHeader('Document Relationships');
     $relationships = $document->getRelationshipData();
     $phids = ipull($relationships, 1);
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $rows = array();
     foreach ($relationships as $relationship) {
         list($type, $phid, $rtype, $time) = $relationship;
         $rows[] = array(phutil_escape_html($type), phutil_escape_html($phid), phutil_escape_html($rtype), $handles[$phid]->renderLink());
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Relationship', 'Related PHID', 'Related Type', 'Related Handle'));
     $table->setColumnClasses(array('', '', '', 'wide'));
     $panel->appendChild($table);
     $panels[] = $panel;
     return $this->buildStandardPageResponse($panels, array('title' => 'Raw Index'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     if ($this->username) {
         $user = id(new PhabricatorUser())->loadOneWhere('username = %s', $this->username);
     } else {
         $user = $request->getUser();
     }
     $content = array();
     if (!$user) {
         $error_view = new AphrontErrorView();
         $error_view->setSeverity(AphrontErrorView::SEVERITY_ERROR);
         $error_body = 'User name ' . '<b>' . phutil_escape_html($this->username) . '</b>' . ' doesn\'t exist.';
         $error_view->setTitle("Error");
         $error_view->appendChild('<p>' . $error_body . '</p>');
         $content[] = $error_view;
     } else {
         $pager = new AphrontPagerView();
         $pager->setOffset($request->getInt('offset'));
         $pager->setURI($request->getRequestURI(), 'offset');
         $query = new PhabricatorSearchQuery();
         $query->setParameter('type', PhabricatorPHIDConstants::PHID_TYPE_CMIT);
         $query->setParameter('author', array($user->getPHID()));
         $query->setParameter('limit', $pager->getPageSize() + 1);
         $query->setParameter('offset', $pager->getOffset());
         $user_link = phutil_render_tag('a', array('href' => '/p/' . $user->getUsername() . '/'), phutil_escape_html($user->getUsername()));
         $executor = new PhabricatorSearchMySQLExecutor();
         $results = $executor->executeSearch($query);
         $results = $pager->sliceResults($results);
         $result_phids = ipull($results, 'phid');
         $commit_table = self::createCommitTable($result_phids, $user);
         $list_panel = new AphrontPanelView();
         $list_panel->setHeader('Commits by ' . $user_link);
         $list_panel->appendChild($commit_table);
         $list_panel->appendChild($pager);
         $content[] = $list_panel;
     }
     return $this->buildStandardPageResponse($content, array('title' => 'Commit List'));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($this->id) {
         $query = id(new PhabricatorSearchQuery())->load($this->id);
         if (!$query) {
             return new Aphront404Response();
         }
     } else {
         $query = new PhabricatorSearchQuery();
         if ($request->isFormPost()) {
             $query->setQuery($request->getStr('query'));
             if (strlen($request->getStr('type'))) {
                 $query->setParameter('type', $request->getStr('type'));
             }
             if ($request->getArr('author')) {
                 $query->setParameter('author', $request->getArr('author'));
             }
             if ($request->getArr('owner')) {
                 $query->setParameter('owner', $request->getArr('owner'));
             }
             if ($request->getInt('open')) {
                 $query->setParameter('open', $request->getInt('open'));
             }
             if ($request->getArr('project')) {
                 $query->setParameter('project', $request->getArr('project'));
             }
             $query->save();
             return id(new AphrontRedirectResponse())->setURI('/search/' . $query->getID() . '/');
         }
     }
     $more = PhabricatorEnv::getEnvConfig('search.more-document-types', array());
     $options = array('' => 'All Documents', PhabricatorPHIDConstants::PHID_TYPE_DREV => 'Differential Revisions', PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'Repository Commits', PhabricatorPHIDConstants::PHID_TYPE_TASK => 'Maniphest Tasks', PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Documents', PhabricatorPHIDConstants::PHID_TYPE_USER => 'Phabricator Users') + $more;
     $status_options = array(0 => 'Open and Closed Documents', 1 => 'Open Documents');
     $phids = array_merge($query->getParameter('author', array()), $query->getParameter('owner', array()), $query->getParameter('project', array()));
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $author_value = array_select_keys($handles, $query->getParameter('author', array()));
     $author_value = mpull($author_value, 'getFullName', 'getPHID');
     $owner_value = array_select_keys($handles, $query->getParameter('owner', array()));
     $owner_value = mpull($owner_value, 'getFullName', 'getPHID');
     $project_value = array_select_keys($handles, $query->getParameter('project', array()));
     $project_value = mpull($project_value, 'getFullName', 'getPHID');
     $search_form = new AphrontFormView();
     $search_form->setUser($user)->setAction('/search/')->appendChild(id(new AphrontFormTextControl())->setLabel('Search')->setName('query')->setValue($query->getQuery()))->appendChild(id(new AphrontFormSelectControl())->setLabel('Document Type')->setName('type')->setOptions($options)->setValue($query->getParameter('type')))->appendChild(id(new AphrontFormSelectControl())->setLabel('Document Status')->setName('open')->setOptions($status_options)->setValue($query->getParameter('open')))->appendChild(id(new AphrontFormTokenizerControl())->setName('author')->setLabel('Author')->setDatasource('/typeahead/common/users/')->setValue($author_value))->appendChild(id(new AphrontFormTokenizerControl())->setName('owner')->setLabel('Owner')->setDatasource('/typeahead/common/searchowner/')->setValue($owner_value)->setCaption('Tip: search for "Up For Grabs" to find unowned documents.'))->appendChild(id(new AphrontFormTokenizerControl())->setName('project')->setLabel('Project')->setDatasource('/typeahead/common/projects/')->setValue($project_value))->appendChild(id(new AphrontFormSubmitControl())->setValue('Search'));
     $search_panel = new AphrontPanelView();
     $search_panel->setHeader('Search Phabricator');
     $search_panel->appendChild($search_form);
     require_celerity_resource('phabricator-search-results-css');
     if ($query->getID()) {
         $limit = 20;
         $pager = new AphrontPagerView();
         $pager->setURI($request->getRequestURI(), 'page');
         $pager->setPageSize($limit);
         $pager->setOffset($request->getInt('page'));
         $query->setParameter('limit', $limit + 1);
         $query->setParameter('offset', $pager->getOffset());
         $executor = new PhabricatorSearchMySQLExecutor();
         $results = $executor->executeSearch($query);
         $results = ipull($results, 'phid');
         $results = $pager->sliceResults($results);
         if ($results) {
             $loader = new PhabricatorObjectHandleData($results);
             $handles = $loader->loadHandles();
             $objects = $loader->loadObjects();
             $results = array();
             foreach ($handles as $phid => $handle) {
                 $view = new PhabricatorSearchResultView();
                 $view->setHandle($handle);
                 $view->setQuery($query);
                 $view->setObject($objects[$phid]);
                 $results[] = $view->render();
             }
             $results = '<div class="phabricator-search-result-list">' . implode("\n", $results) . '<div class="search-results-pager">' . $pager->render() . '</div>' . '</div>';
         } else {
             $results = '<div class="phabricator-search-result-list">' . '<p class="phabricator-search-no-results">No search results.</p>' . '</div>';
         }
     } else {
         $results = null;
     }
     return $this->buildStandardPageResponse(array($search_panel, $results), array('title' => 'Results: what'));
 }