mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-03 20:22:46 +01:00
b902005bed
Summary: Ref T603. Killing this class is cool because the classes that replace it are policy-aware. Tried to keep my wits about me as I did this and fixed a few random things along the way. (Ones I remember right now are pulling a query outside of a foreach loop in Releeph and fixing the text in UIExample to note that the ace of hearts if "a powerful" card and not the "most powerful" card (Q of spades gets that honor IMO)) Test Plan: tested the first few changes (execute, executeOne X handle, object) then got real mechanical / careful with the other changes. Reviewers: epriestley Reviewed By: epriestley CC: Korvin, aran, FacebookPOC Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D6941
117 lines
2.9 KiB
PHP
117 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group file
|
|
*/
|
|
final class PhabricatorFileSearchEngine
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
$saved = new PhabricatorSavedQuery();
|
|
$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;
|
|
}
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
$query = id(new PhabricatorFileQuery())
|
|
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
|
|
|
|
if ($saved->getParameter('explicit')) {
|
|
$query->showOnlyExplicitUploads(true);
|
|
}
|
|
|
|
$start = $this->parseDateTime($saved->getParameter('createdStart'));
|
|
$end = $this->parseDateTime($saved->getParameter('createdEnd'));
|
|
|
|
if ($start) {
|
|
$query->withDateCreatedAfter($start);
|
|
}
|
|
|
|
if ($end) {
|
|
$query->withDateCreatedBefore($end);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function buildSearchForm(
|
|
AphrontFormView $form,
|
|
PhabricatorSavedQuery $saved_query) {
|
|
|
|
$phids = $saved_query->getParameter('authorPHIDs', array());
|
|
$handles = id(new PhabricatorHandleQuery())
|
|
->setViewer($this->requireViewer())
|
|
->withPHIDs($phids)
|
|
->execute();
|
|
$author_tokens = mpull($handles, 'getFullName', 'getPHID');
|
|
|
|
$explicit = $saved_query->getParameter('explicit');
|
|
|
|
$form
|
|
->appendChild(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setDatasource('/typeahead/common/users/')
|
|
->setName('authors')
|
|
->setLabel(pht('Authors'))
|
|
->setValue($author_tokens))
|
|
->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) {
|
|
return '/file/'.$path;
|
|
}
|
|
|
|
public function getBuiltinQueryNames() {
|
|
$names = array();
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
$names['authored'] = pht('Authored');
|
|
}
|
|
|
|
$names += array(
|
|
'all' => pht('All'),
|
|
);
|
|
|
|
return $names;
|
|
}
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
$query = $this->newSavedQuery();
|
|
$query->setQueryKey($query_key);
|
|
|
|
switch ($query_key) {
|
|
case 'all':
|
|
return $query;
|
|
case 'authored':
|
|
$author_phid = array($this->requireViewer()->getPHID());
|
|
return $query
|
|
->setParameter('authorPHIDs', $author_phid)
|
|
->setParameter('explicit', true);
|
|
}
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
}
|
|
|
|
}
|