mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-01 03:02:43 +01:00
79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
|
<?php
|
||
|
|
||
|
final class PholioMockSearchEngine
|
||
|
extends PhabricatorApplicationSearchEngine {
|
||
|
|
||
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||
|
$saved = new PhabricatorSavedQuery();
|
||
|
$saved->setParameter(
|
||
|
'authorPHIDs',
|
||
|
array_values($request->getArr('authors')));
|
||
|
|
||
|
return $saved;
|
||
|
}
|
||
|
|
||
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||
|
$query = id(new PholioMockQuery())
|
||
|
->needCoverFiles(true)
|
||
|
->needImages(true)
|
||
|
->needTokenCounts(true)
|
||
|
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
|
||
|
|
||
|
return $query;
|
||
|
}
|
||
|
|
||
|
public function buildSearchForm(
|
||
|
AphrontFormView $form,
|
||
|
PhabricatorSavedQuery $saved_query) {
|
||
|
|
||
|
$phids = $saved_query->getParameter('authorPHIDs', array());
|
||
|
$handles = id(new PhabricatorObjectHandleData($phids))
|
||
|
->setViewer($this->requireViewer())
|
||
|
->loadHandles();
|
||
|
$author_tokens = mpull($handles, 'getFullName', 'getPHID');
|
||
|
|
||
|
$form
|
||
|
->appendChild(
|
||
|
id(new AphrontFormTokenizerControl())
|
||
|
->setDatasource('/typeahead/common/users/')
|
||
|
->setName('authors')
|
||
|
->setLabel(pht('Authors'))
|
||
|
->setValue($author_tokens));
|
||
|
|
||
|
}
|
||
|
|
||
|
protected function getURI($path) {
|
||
|
return '/pholio/'.$path;
|
||
|
}
|
||
|
|
||
|
public function getBuiltinQueryNames() {
|
||
|
$names = array(
|
||
|
'all' => pht('All Mocks'),
|
||
|
);
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
}
|