2014-02-06 19:10:18 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCalendarEventSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
2014-06-12 22:22:20 +02:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
return pht('Calendar Events');
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:47:48 +01:00
|
|
|
public function getApplicationClassName() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorCalendarApplication';
|
2014-05-08 18:18:02 +02:00
|
|
|
}
|
|
|
|
|
2014-02-06 19:10:18 +01:00
|
|
|
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());
|
|
|
|
|
|
|
|
$form
|
2015-03-31 23:10:32 +02:00
|
|
|
->appendControl(
|
2014-02-06 19:10:18 +01:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-18 00:44:18 +02:00
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
2014-02-06 19:10:18 +01:00
|
|
|
->setName('creators')
|
|
|
|
->setLabel(pht('Created By'))
|
2015-03-31 23:10:32 +02:00
|
|
|
->setValue($creator_phids))
|
|
|
|
->appendControl(
|
2014-02-06 19:10:18 +01:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-18 00:44:18 +02:00
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
2014-02-06 19:10:18 +01:00
|
|
|
->setName('invited')
|
|
|
|
->setLabel(pht('Invited'))
|
2015-03-31 23:10:32 +02:00
|
|
|
->setValue($invited_phids))
|
2014-02-06 19:10:18 +01:00
|
|
|
->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;
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:34:51 +01:00
|
|
|
protected function getBuiltinQueryNames() {
|
2014-02-06 19:10:18 +01:00
|
|
|
$names = array(
|
|
|
|
'upcoming' => pht('Upcoming Events'),
|
2014-07-23 02:03:09 +02:00
|
|
|
'all' => pht('All Events'),
|
2014-02-06 19:10:18 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-08-07 00:04:12 +02:00
|
|
|
protected function getRequiredHandlePHIDsForResultList(
|
|
|
|
array $objects,
|
|
|
|
PhabricatorSavedQuery $query) {
|
|
|
|
$phids = array();
|
|
|
|
foreach ($objects as $event) {
|
|
|
|
$phids[$event->getUserPHID()] = 1;
|
|
|
|
}
|
|
|
|
return array_keys($phids);
|
|
|
|
}
|
|
|
|
|
2014-05-08 18:18:02 +02:00
|
|
|
protected function renderResultList(
|
|
|
|
array $events,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
assert_instances_of($events, 'PhabricatorCalendarEvent');
|
|
|
|
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
|
|
|
$list = new PHUIObjectItemListView();
|
|
|
|
foreach ($events as $event) {
|
|
|
|
if ($event->getUserPHID() == $viewer->getPHID()) {
|
|
|
|
$href = $this->getApplicationURI('/event/edit/'.$event->getID().'/');
|
|
|
|
} else {
|
|
|
|
$from = $event->getDateFrom();
|
|
|
|
$month = phabricator_format_local_time($from, $viewer, 'm');
|
|
|
|
$year = phabricator_format_local_time($from, $viewer, 'Y');
|
|
|
|
$uri = new PhutilURI($this->getApplicationURI());
|
|
|
|
$uri->setQueryParams(
|
|
|
|
array(
|
|
|
|
'month' => $month,
|
|
|
|
'year' => $year,
|
|
|
|
));
|
|
|
|
$href = (string) $uri;
|
|
|
|
}
|
|
|
|
$from = phabricator_datetime($event->getDateFrom(), $viewer);
|
|
|
|
$to = phabricator_datetime($event->getDateTo(), $viewer);
|
2014-08-07 00:04:12 +02:00
|
|
|
$creator_handle = $handles[$event->getUserPHID()];
|
2014-05-08 18:18:02 +02:00
|
|
|
|
|
|
|
$color = ($event->getStatus() == PhabricatorCalendarEvent::STATUS_AWAY)
|
|
|
|
? 'red'
|
|
|
|
: 'yellow';
|
|
|
|
|
|
|
|
$item = id(new PHUIObjectItemView())
|
|
|
|
->setHeader($event->getTerseSummary($viewer))
|
|
|
|
->setHref($href)
|
|
|
|
->setBarColor($color)
|
2014-08-07 00:04:12 +02:00
|
|
|
->addByline(pht('Creator: %s', $creator_handle->renderLink()))
|
2014-05-08 18:18:02 +02:00
|
|
|
->addAttribute(pht('From %s to %s', $from, $to))
|
2014-08-30 00:15:13 +02:00
|
|
|
->addAttribute(id(new PhutilUTF8StringTruncator())
|
|
|
|
->setMaximumGlyphs(64)
|
|
|
|
->truncateString($event->getDescription()));
|
2014-05-08 18:18:02 +02:00
|
|
|
|
|
|
|
$list->addItem($item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
2014-02-06 19:10:18 +01:00
|
|
|
}
|