mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-26 11:10:16 +01:00
Summary: Ref T2625. We currently hard-code the URI; instead, derive it from the Engine. I weakened the strength of getQueryResultsPageURI to let it build from a NamedQuery or a SavedQuery, because constructing a SavedQuery for a builtin NamedQuery is a bit of a pain. Test Plan: Clicked links on the saved queries page, got query results. Reviewers: btrahan, blc Reviewed By: btrahan CC: aran Maniphest Tasks: T2625 Differential Revision: https://secure.phabricator.com/D6060
120 lines
3.1 KiB
PHP
120 lines
3.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Provides search functionality for the paste application.
|
|
*
|
|
* @group search
|
|
*/
|
|
final class PhabricatorPasteSearchEngine
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
/**
|
|
* Create a saved query object from the request.
|
|
*
|
|
* @param AphrontRequest The search request.
|
|
* @return The saved query that is built.
|
|
*/
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
$saved = new PhabricatorSavedQuery();
|
|
$saved->setParameter(
|
|
'authorPHIDs',
|
|
array_values($request->getArr('set_users')));
|
|
|
|
try {
|
|
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
|
$saved->save();
|
|
unset($unguarded);
|
|
} catch (AphrontQueryDuplicateKeyException $ex) {
|
|
// Ignore, this is just a repeated search.
|
|
}
|
|
|
|
return $saved;
|
|
}
|
|
|
|
/**
|
|
* Executes the saved query.
|
|
*
|
|
* @param PhabricatorSavedQuery
|
|
* @return The result of the query.
|
|
*/
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
$query = id(new PhabricatorPasteQuery())
|
|
->withIDs($saved->getParameter('ids', array()))
|
|
->withPHIDs($saved->getParameter('phids', array()))
|
|
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()))
|
|
->withParentPHIDs($saved->getParameter('parentPHIDs', array()));
|
|
|
|
return $query;
|
|
}
|
|
|
|
/**
|
|
* Builds the search form using the request.
|
|
*
|
|
* @param PhabricatorSavedQuery The query to populate the form with.
|
|
* @return AphrontFormView The built form.
|
|
*/
|
|
public function buildSearchForm(PhabricatorSavedQuery $saved_query) {
|
|
$phids = $saved_query->getParameter('authorPHIDs', array());
|
|
$handles = id(new PhabricatorObjectHandleData($phids))
|
|
->setViewer($this->requireViewer())
|
|
->loadHandles();
|
|
$users_searched = mpull($handles, 'getFullName', 'getPHID');
|
|
|
|
$form = id(new AphrontFormView())
|
|
->setUser($this->requireViewer());
|
|
|
|
$form->appendChild(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setDatasource('/typeahead/common/searchowner/')
|
|
->setName('set_users')
|
|
->setLabel(pht('Users'))
|
|
->setValue($users_searched));
|
|
|
|
$form->appendChild(
|
|
id(new AphrontFormSubmitControl())
|
|
->setValue(pht('Query'))
|
|
->addCancelButton(
|
|
'/search/edit/'.$saved_query->getQueryKey().'/',
|
|
pht('Save Custom Query...')));
|
|
|
|
return $form;
|
|
}
|
|
|
|
public function getQueryResultsPageURI($query_key) {
|
|
return '/paste/query/'.$query_key.'/';
|
|
}
|
|
|
|
public function getQueryManagementURI() {
|
|
return '/paste/savedqueries/';
|
|
}
|
|
|
|
public function getBuiltinQueryNames() {
|
|
$names = array(
|
|
'all' => pht('All Pastes'),
|
|
);
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
$names['authored'] = pht('Authored');
|
|
}
|
|
|
|
return $names;
|
|
}
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
$query = $this->newSavedQuery();
|
|
$query->setQueryKey($query_key);
|
|
|
|
switch ($query_key) {
|
|
case 'all':
|
|
return $query;
|
|
case 'authored':
|
|
return $query->setParameter(
|
|
'authorPHIDs',
|
|
array($this->requireViewer()->getPHID()));
|
|
}
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
}
|
|
|
|
}
|