mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-03 04:02:43 +01:00
164 lines
4.2 KiB
PHP
164 lines
4.2 KiB
PHP
|
<?php
|
||
|
|
||
|
final class PhabricatorCalendarEventSearchEngine
|
||
|
extends PhabricatorApplicationSearchEngine {
|
||
|
|
||
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||
|
$saved = new PhabricatorSavedQuery();
|
||
|
|
||
|
$saved->setParameter(
|
||
|
'rangeStart',
|
||
|
$this->readDateFromRequest($request, 'rangeStart'));
|
||
|
|
||
|
$saved->setParameter(
|
||
|
'rangeEnd',
|
||
|
$this->readDateFromRequest($request, 'rangeEnd'));
|
||
|
|
||
|
$saved->setParameter(
|
||
|
'upcoming',
|
||
|
$this->readBoolFromRequest($request, 'upcoming'));
|
||
|
|
||
|
$saved->setParameter(
|
||
|
'invitedPHIDs',
|
||
|
$this->readUsersFromRequest($request, 'invited'));
|
||
|
|
||
|
$saved->setParameter(
|
||
|
'creatorPHIDs',
|
||
|
$this->readUsersFromRequest($request, 'creators'));
|
||
|
|
||
|
return $saved;
|
||
|
}
|
||
|
|
||
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||
|
$query = id(new PhabricatorCalendarEventQuery());
|
||
|
|
||
|
$min_range = null;
|
||
|
$max_range = null;
|
||
|
|
||
|
if ($saved->getParameter('rangeStart')) {
|
||
|
$min_range = $saved->getParameter('rangeStart');
|
||
|
}
|
||
|
|
||
|
if ($saved->getParameter('rangeEnd')) {
|
||
|
$max_range = $saved->getParameter('rangeEnd');
|
||
|
}
|
||
|
|
||
|
if ($saved->getParameter('upcoming')) {
|
||
|
if ($min_range) {
|
||
|
$min_range = max(time(), $min_range);
|
||
|
} else {
|
||
|
$min_range = time();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ($min_range || $max_range) {
|
||
|
$query->withDateRange($min_range, $max_range);
|
||
|
}
|
||
|
|
||
|
$invited_phids = $saved->getParameter('invitedPHIDs');
|
||
|
if ($invited_phids) {
|
||
|
$query->withInvitedPHIDs($invited_phids);
|
||
|
}
|
||
|
|
||
|
$creator_phids = $saved->getParameter('creatorPHIDs');
|
||
|
if ($creator_phids) {
|
||
|
$query->withCreatorPHIDs($creator_phids);
|
||
|
}
|
||
|
|
||
|
return $query;
|
||
|
}
|
||
|
|
||
|
public function buildSearchForm(
|
||
|
AphrontFormView $form,
|
||
|
PhabricatorSavedQuery $saved) {
|
||
|
|
||
|
$range_start = $saved->getParameter('rangeStart');
|
||
|
$range_end = $saved->getParameter('rangeEnd');
|
||
|
$upcoming = $saved->getParameter('upcoming');
|
||
|
|
||
|
$invited_phids = $saved->getParameter('invitedPHIDs', array());
|
||
|
$creator_phids = $saved->getParameter('creatorPHIDs', array());
|
||
|
|
||
|
$all_phids = array_merge(
|
||
|
$invited_phids,
|
||
|
$creator_phids);
|
||
|
|
||
|
if ($all_phids) {
|
||
|
$handles = id(new PhabricatorHandleQuery())
|
||
|
->setViewer($this->requireViewer())
|
||
|
->withPHIDs($all_phids)
|
||
|
->execute();
|
||
|
} else {
|
||
|
$handles = array();
|
||
|
}
|
||
|
|
||
|
$invited_handles = array_select_keys($handles, $invited_phids);
|
||
|
$creator_handles = array_select_keys($handles, $creator_phids);
|
||
|
|
||
|
$form
|
||
|
->appendChild(
|
||
|
id(new AphrontFormTokenizerControl())
|
||
|
->setDatasource('/typeahead/common/accounts/')
|
||
|
->setName('creators')
|
||
|
->setLabel(pht('Created By'))
|
||
|
->setValue($creator_handles))
|
||
|
->appendChild(
|
||
|
id(new AphrontFormTokenizerControl())
|
||
|
->setDatasource('/typeahead/common/accounts/')
|
||
|
->setName('invited')
|
||
|
->setLabel(pht('Invited'))
|
||
|
->setValue($invited_handles))
|
||
|
->appendChild(
|
||
|
id(new AphrontFormDateControl())
|
||
|
->setLabel(pht('Occurs After'))
|
||
|
->setUser($this->requireViewer())
|
||
|
->setName('rangeStart')
|
||
|
->setAllowNull(true)
|
||
|
->setValue($range_start))
|
||
|
->appendChild(
|
||
|
id(new AphrontFormDateControl())
|
||
|
->setLabel(pht('Occurs Before'))
|
||
|
->setUser($this->requireViewer())
|
||
|
->setName('rangeEnd')
|
||
|
->setAllowNull(true)
|
||
|
->setValue($range_end))
|
||
|
->appendChild(
|
||
|
id(new AphrontFormCheckboxControl())
|
||
|
->addCheckbox(
|
||
|
'upcoming',
|
||
|
1,
|
||
|
pht('Show only upcoming events.'),
|
||
|
$upcoming));
|
||
|
|
||
|
}
|
||
|
|
||
|
protected function getURI($path) {
|
||
|
return '/calendar/event/'.$path;
|
||
|
}
|
||
|
|
||
|
public function getBuiltinQueryNames() {
|
||
|
$names = array(
|
||
|
'upcoming' => pht('Upcoming Events'),
|
||
|
'all' => pht('All Events'),
|
||
|
);
|
||
|
|
||
|
return $names;
|
||
|
}
|
||
|
|
||
|
public function buildSavedQueryFromBuiltin($query_key) {
|
||
|
|
||
|
$query = $this->newSavedQuery();
|
||
|
$query->setQueryKey($query_key);
|
||
|
|
||
|
switch ($query_key) {
|
||
|
case 'upcoming':
|
||
|
return $query->setParameter('upcoming', true);
|
||
|
case 'all':
|
||
|
return $query;
|
||
|
}
|
||
|
|
||
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
||
|
}
|
||
|
|
||
|
}
|