Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/query/PhabricatorFileSearchEngine.php
<?php | <?php | ||||
final class PhabricatorFileSearchEngine | final class PhabricatorFileSearchEngine | ||||
extends PhabricatorApplicationSearchEngine { | extends PhabricatorApplicationSearchEngine { | ||||
public function getResultTypeDescription() { | public function getResultTypeDescription() { | ||||
return pht('Files'); | return pht('Files'); | ||||
} | } | ||||
public function getApplicationClassName() { | public function getApplicationClassName() { | ||||
return 'PhabricatorFilesApplication'; | return 'PhabricatorFilesApplication'; | ||||
} | } | ||||
public function buildSavedQueryFromRequest(AphrontRequest $request) { | public function newResultObject() { | ||||
$saved = new PhabricatorSavedQuery(); | return new PhabricatorFile(); | ||||
$saved->setParameter( | } | ||||
'authorPHIDs', | |||||
$this->readUsersFromRequest($request, 'authors')); | |||||
$saved->setParameter('explicit', $request->getBool('explicit')); | |||||
$saved->setParameter('createdStart', $request->getStr('createdStart')); | |||||
$saved->setParameter('createdEnd', $request->getStr('createdEnd')); | |||||
return $saved; | protected function buildCustomSearchFields() { | ||||
return array( | |||||
id(new PhabricatorSearchUsersField()) | |||||
->setKey('authorPHIDs') | |||||
->setAliases(array('author', 'authors')) | |||||
->setLabel(pht('Authors')), | |||||
id(new PhabricatorSearchThreeStateField()) | |||||
->setKey('explicit') | |||||
->setLabel(pht('Upload Source')) | |||||
->setOptions( | |||||
pht('(Show All)'), | |||||
pht('Show Only Manually Uploaded Files'), | |||||
pht('Hide Manually Uploaded Files')), | |||||
id(new PhabricatorSearchDateField()) | |||||
->setKey('createdStart') | |||||
->setLabel(pht('Created After')), | |||||
id(new PhabricatorSearchDateField()) | |||||
->setKey('createdEnd') | |||||
->setLabel(pht('Created Before')), | |||||
); | |||||
} | } | ||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { | public function buildQueryFromParameters(array $map) { | ||||
$query = id(new PhabricatorFileQuery()); | $query = id(new PhabricatorFileQuery()); | ||||
$author_phids = $saved->getParameter('authorPHIDs', array()); | if ($map['authorPHIDs']) { | ||||
if ($author_phids) { | $query->withAuthorPHIDs($map['authorPHIDs']); | ||||
$query->withAuthorPHIDs($author_phids); | |||||
} | } | ||||
if ($saved->getParameter('explicit')) { | if ($map['explicit'] !== null) { | ||||
$query->showOnlyExplicitUploads(true); | $query->showOnlyExplicitUploads($map['explicit']); | ||||
} | } | ||||
$start = $this->parseDateTime($saved->getParameter('createdStart')); | if ($map['createdStart']) { | ||||
$end = $this->parseDateTime($saved->getParameter('createdEnd')); | $query->withDateCreatedAfter($map['createdStart']); | ||||
if ($start) { | |||||
$query->withDateCreatedAfter($start); | |||||
} | } | ||||
if ($end) { | if ($map['createdEnd']) { | ||||
$query->withDateCreatedBefore($end); | $query->withDateCreatedBefore($map['createdEnd']); | ||||
} | } | ||||
return $query; | return $query; | ||||
} | } | ||||
public function buildSearchForm( | |||||
AphrontFormView $form, | |||||
PhabricatorSavedQuery $saved_query) { | |||||
$author_phids = $saved_query->getParameter('authorPHIDs', array()); | |||||
$explicit = $saved_query->getParameter('explicit'); | |||||
$form | |||||
->appendControl( | |||||
id(new AphrontFormTokenizerControl()) | |||||
->setDatasource(new PhabricatorPeopleDatasource()) | |||||
->setName('authors') | |||||
->setLabel(pht('Authors')) | |||||
->setValue($author_phids)) | |||||
->appendChild( | |||||
id(new AphrontFormCheckboxControl()) | |||||
->addCheckbox( | |||||
'explicit', | |||||
1, | |||||
pht('Show only manually uploaded files.'), | |||||
$explicit)); | |||||
$this->buildDateRange( | |||||
$form, | |||||
$saved_query, | |||||
'createdStart', | |||||
pht('Created After'), | |||||
'createdEnd', | |||||
pht('Created Before')); | |||||
} | |||||
protected function getURI($path) { | protected function getURI($path) { | ||||
return '/file/'.$path; | return '/file/'.$path; | ||||
} | } | ||||
protected function getBuiltinQueryNames() { | protected function getBuiltinQueryNames() { | ||||
$names = array(); | $names = array(); | ||||
if ($this->requireViewer()->isLoggedIn()) { | if ($this->requireViewer()->isLoggedIn()) { | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |