2013-07-03 20:15:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group legalpad
|
|
|
|
*/
|
|
|
|
final class LegalpadDocumentSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
$saved->setParameter(
|
|
|
|
'creatorPHIDs',
|
|
|
|
array_values($request->getArr('creators')));
|
|
|
|
|
2013-07-08 22:37:36 +02:00
|
|
|
$saved->setParameter(
|
|
|
|
'contributorPHIDs',
|
|
|
|
array_values($request->getArr('contributors')));
|
|
|
|
|
2013-07-03 20:15:45 +02:00
|
|
|
$saved->setParameter('createdStart', $request->getStr('createdStart'));
|
|
|
|
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
|
|
|
|
|
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
|
|
$query = id(new LegalpadDocumentQuery())
|
2013-07-08 22:37:36 +02:00
|
|
|
->withCreatorPHIDs($saved->getParameter('creatorPHIDs', array()))
|
|
|
|
->withContributorPHIDs($saved->getParameter('contributorPHIDs', array()));
|
2013-07-03 20:15:45 +02:00
|
|
|
|
|
|
|
$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) {
|
2013-07-08 22:37:36 +02:00
|
|
|
|
|
|
|
$creator_phids = $saved_query->getParameter('creatorPHIDs', array());
|
|
|
|
$contributor_phids = $saved_query->getParameter(
|
|
|
|
'contributorPHIDs', array());
|
|
|
|
$phids = array_merge($creator_phids, $contributor_phids);
|
2013-07-03 20:15:45 +02:00
|
|
|
$handles = id(new PhabricatorObjectHandleData($phids))
|
|
|
|
->setViewer($this->requireViewer())
|
|
|
|
->loadHandles();
|
2013-07-08 22:37:36 +02:00
|
|
|
$tokens = mpull($handles, 'getFullName', 'getPHID');
|
2013-07-03 20:15:45 +02:00
|
|
|
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setDatasource('/typeahead/common/users/')
|
|
|
|
->setName('creators')
|
|
|
|
->setLabel(pht('Creators'))
|
2013-07-08 22:37:36 +02:00
|
|
|
->setValue(array_select_keys($tokens, $creator_phids)))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setDatasource('/typeahead/common/users/')
|
|
|
|
->setName('contributors')
|
|
|
|
->setLabel(pht('Contributors'))
|
|
|
|
->setValue(array_select_keys($tokens, $contributor_phids)));
|
2013-07-03 20:15:45 +02:00
|
|
|
|
|
|
|
$this->buildDateRange(
|
|
|
|
$form,
|
|
|
|
$saved_query,
|
|
|
|
'createdStart',
|
|
|
|
pht('Created After'),
|
|
|
|
'createdEnd',
|
|
|
|
pht('Created Before'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return '/legalpad/'.$path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBuiltinQueryNames() {
|
|
|
|
$names = array(
|
|
|
|
'all' => pht('All Documents'),
|
|
|
|
);
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
case 'all':
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|