2014-02-06 19:10:18 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCalendarEventSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
2015-05-03 01:17:05 +02:00
|
|
|
private $calendarYear;
|
|
|
|
private $calendarMonth;
|
2015-05-04 01:57:18 +02:00
|
|
|
private $calendarDay;
|
2015-05-03 01:17:05 +02:00
|
|
|
|
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'));
|
|
|
|
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
$saved->setParameter(
|
|
|
|
'isCancelled',
|
|
|
|
$request->getStr('isCancelled'));
|
|
|
|
|
2015-05-03 00:27:33 +02:00
|
|
|
$saved->setParameter(
|
|
|
|
'display',
|
|
|
|
$request->getStr('display'));
|
|
|
|
|
2014-02-06 19:10:18 +01:00
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
|
|
$query = id(new PhabricatorCalendarEventQuery());
|
2015-05-03 01:17:05 +02:00
|
|
|
$viewer = $this->requireViewer();
|
2015-05-06 01:04:00 +02:00
|
|
|
$timezone = new DateTimeZone($viewer->getTimezoneIdentifier());
|
2014-02-06 19:10:18 +01:00
|
|
|
|
2015-05-04 19:08:49 +02:00
|
|
|
$min_range = $this->getDateFrom($saved)->getEpoch();
|
|
|
|
$max_range = $this->getDateTo($saved)->getEpoch();
|
2014-02-06 19:10:18 +01:00
|
|
|
|
2015-05-06 01:04:00 +02:00
|
|
|
if ($saved->getParameter('display') == 'month' ||
|
|
|
|
$saved->getParameter('display') == 'day') {
|
|
|
|
list($start_year, $start_month, $start_day) =
|
2015-05-05 21:51:32 +02:00
|
|
|
$this->getDisplayYearAndMonthAndDay($saved);
|
2015-05-06 01:04:00 +02:00
|
|
|
|
|
|
|
$start_day = new DateTime(
|
|
|
|
"{$start_year}-{$start_month}-{$start_day}",
|
|
|
|
$timezone);
|
|
|
|
$next = clone $start_day;
|
|
|
|
|
|
|
|
if ($saved->getParameter('display') == 'month') {
|
|
|
|
$next->modify('+1 month');
|
|
|
|
} else if ($saved->getParameter('display') == 'day') {
|
2015-05-07 03:41:48 +02:00
|
|
|
$next->modify('+6 day');
|
2015-05-06 01:04:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$display_start = $start_day->format('U');
|
|
|
|
$display_end = $next->format('U');
|
|
|
|
|
|
|
|
if (!$min_range || ($min_range < $display_start)) {
|
|
|
|
$min_range = $display_start;
|
2015-05-03 01:17:05 +02:00
|
|
|
}
|
2015-05-06 01:04:00 +02:00
|
|
|
if (!$max_range || ($max_range > $display_end)) {
|
|
|
|
$max_range = $display_end;
|
2015-05-03 01:17:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-06 19:10:18 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
$is_cancelled = $saved->getParameter('isCancelled');
|
|
|
|
switch ($is_cancelled) {
|
|
|
|
case 'active':
|
|
|
|
$query->withIsCancelled(false);
|
|
|
|
break;
|
|
|
|
case 'cancelled':
|
|
|
|
$query->withIsCancelled(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-06 19:10:18 +01:00
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
AphrontFormView $form,
|
|
|
|
PhabricatorSavedQuery $saved) {
|
|
|
|
|
2015-05-04 19:08:49 +02:00
|
|
|
$range_start = $this->getDateFrom($saved);
|
|
|
|
$e_start = null;
|
|
|
|
|
|
|
|
$range_end = $this->getDateTo($saved);
|
|
|
|
$e_end = null;
|
|
|
|
|
|
|
|
if (!$range_start->isValid()) {
|
|
|
|
$this->addError(pht('Start date is not valid.'));
|
|
|
|
$e_start = pht('Invalid');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$range_end->isValid()) {
|
|
|
|
$this->addError(pht('End date is not valid.'));
|
|
|
|
$e_end = pht('Invalid');
|
|
|
|
}
|
|
|
|
|
|
|
|
$start_epoch = $range_start->getEpoch();
|
|
|
|
$end_epoch = $range_end->getEpoch();
|
|
|
|
|
|
|
|
if ($start_epoch && $end_epoch && ($start_epoch > $end_epoch)) {
|
|
|
|
$this->addError(pht('End date must be after start date.'));
|
|
|
|
$e_start = pht('Invalid');
|
|
|
|
$e_end = pht('Invalid');
|
|
|
|
}
|
|
|
|
|
2014-02-06 19:10:18 +01:00
|
|
|
$upcoming = $saved->getParameter('upcoming');
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
$is_cancelled = $saved->getParameter('isCancelled', 'active');
|
2015-05-03 00:27:33 +02:00
|
|
|
$display = $saved->getParameter('display', 'month');
|
2014-02-06 19:10:18 +01:00
|
|
|
|
|
|
|
$invited_phids = $saved->getParameter('invitedPHIDs', array());
|
|
|
|
$creator_phids = $saved->getParameter('creatorPHIDs', array());
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
$resolution_types = array(
|
|
|
|
'active' => pht('Active Events Only'),
|
|
|
|
'cancelled' => pht('Cancelled Events Only'),
|
|
|
|
'both' => pht('Both Cancelled and Active Events'),
|
|
|
|
);
|
2015-05-03 00:27:33 +02:00
|
|
|
$display_options = array(
|
|
|
|
'month' => pht('Month View'),
|
2015-05-04 01:57:18 +02:00
|
|
|
'day' => pht('Day View (beta)'),
|
2015-05-03 00:27:33 +02:00
|
|
|
'list' => pht('List View'),
|
|
|
|
);
|
2014-02-06 19:10:18 +01:00
|
|
|
|
|
|
|
$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')
|
2015-05-04 19:08:49 +02:00
|
|
|
->setError($e_start)
|
2014-02-06 19:10:18 +01:00
|
|
|
->setValue($range_start))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormDateControl())
|
|
|
|
->setLabel(pht('Occurs Before'))
|
|
|
|
->setUser($this->requireViewer())
|
|
|
|
->setName('rangeEnd')
|
2015-05-04 19:08:49 +02:00
|
|
|
->setError($e_end)
|
2014-02-06 19:10:18 +01:00
|
|
|
->setValue($range_end))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormCheckboxControl())
|
|
|
|
->addCheckbox(
|
|
|
|
'upcoming',
|
|
|
|
1,
|
|
|
|
pht('Show only upcoming events.'),
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
$upcoming))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel(pht('Cancelled Events'))
|
|
|
|
->setName('isCancelled')
|
|
|
|
->setValue($is_cancelled)
|
2015-05-03 00:27:33 +02:00
|
|
|
->setOptions($resolution_types))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel(pht('Display Options'))
|
|
|
|
->setName('display')
|
|
|
|
->setValue($display)
|
|
|
|
->setOptions($display_options));
|
2014-02-06 19:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
2015-05-03 00:27:33 +02:00
|
|
|
return '/calendar/'.$path;
|
2014-02-06 19:10:18 +01:00
|
|
|
}
|
|
|
|
|
2015-01-06 21:34:51 +01:00
|
|
|
protected function getBuiltinQueryNames() {
|
2014-02-06 19:10:18 +01:00
|
|
|
$names = array(
|
2015-05-03 00:27:33 +02:00
|
|
|
'month' => pht('Month View'),
|
2015-05-08 06:18:48 +02:00
|
|
|
'day' => pht('Day View'),
|
2014-02-06 19:10:18 +01:00
|
|
|
'upcoming' => pht('Upcoming Events'),
|
2015-05-03 00:27:33 +02:00
|
|
|
'all' => pht('All Events'),
|
2014-02-06 19:10:18 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
}
|
|
|
|
|
2015-05-05 21:51:32 +02:00
|
|
|
public function setCalendarYearAndMonthAndDay($year, $month, $day = null) {
|
2015-05-03 01:17:05 +02:00
|
|
|
$this->calendarYear = $year;
|
|
|
|
$this->calendarMonth = $month;
|
2015-05-05 21:51:32 +02:00
|
|
|
$this->calendarDay = $day;
|
2015-05-03 01:17:05 +02:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-02-06 19:10:18 +01:00
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
switch ($query_key) {
|
2015-05-03 00:27:33 +02:00
|
|
|
case 'month':
|
|
|
|
return $query->setParameter('display', 'month');
|
2015-05-08 06:18:48 +02:00
|
|
|
case 'day':
|
|
|
|
return $query->setParameter('display', 'day');
|
2014-02-06 19:10:18 +01:00
|
|
|
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) {
|
2015-05-03 00:27:33 +02:00
|
|
|
|
|
|
|
if ($query->getParameter('display') == 'month') {
|
|
|
|
return $this->buildCalendarView($events, $query, $handles);
|
2015-05-04 01:57:18 +02:00
|
|
|
} else if ($query->getParameter('display') == 'day') {
|
|
|
|
return $this->buildCalendarDayView($events, $query, $handles);
|
2015-05-03 00:27:33 +02:00
|
|
|
}
|
|
|
|
|
2014-05-08 18:18:02 +02:00
|
|
|
assert_instances_of($events, 'PhabricatorCalendarEvent');
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
$list = new PHUIObjectItemListView();
|
|
|
|
foreach ($events as $event) {
|
2015-04-30 22:22:13 +02:00
|
|
|
$href = '/E'.$event->getID();
|
2014-05-08 18:18:02 +02:00
|
|
|
$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
|
|
|
|
2015-04-30 22:22:13 +02:00
|
|
|
$name = (strlen($event->getName())) ?
|
|
|
|
$event->getName() : $event->getTerseSummary($viewer);
|
|
|
|
|
2014-05-08 18:18:02 +02:00
|
|
|
$color = ($event->getStatus() == PhabricatorCalendarEvent::STATUS_AWAY)
|
|
|
|
? 'red'
|
|
|
|
: 'yellow';
|
|
|
|
|
|
|
|
$item = id(new PHUIObjectItemView())
|
2015-04-30 22:22:13 +02:00
|
|
|
->setHeader($name)
|
2014-05-08 18:18:02 +02:00
|
|
|
->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;
|
|
|
|
}
|
|
|
|
|
2015-05-03 00:27:33 +02:00
|
|
|
private function buildCalendarView(
|
|
|
|
array $statuses,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
$now = time();
|
|
|
|
|
2015-05-05 21:51:32 +02:00
|
|
|
list($start_year, $start_month) =
|
|
|
|
$this->getDisplayYearAndMonthAndDay($query);
|
2015-05-03 00:27:33 +02:00
|
|
|
|
|
|
|
$now_year = phabricator_format_local_time($now, $viewer, 'Y');
|
|
|
|
$now_month = phabricator_format_local_time($now, $viewer, 'm');
|
|
|
|
$now_day = phabricator_format_local_time($now, $viewer, 'j');
|
|
|
|
|
2015-05-03 01:17:05 +02:00
|
|
|
if ($start_month == $now_month && $start_year == $now_year) {
|
|
|
|
$month_view = new PHUICalendarMonthView(
|
|
|
|
$start_month,
|
|
|
|
$start_year,
|
|
|
|
$now_day);
|
2015-05-03 00:27:33 +02:00
|
|
|
} else {
|
2015-05-03 01:17:05 +02:00
|
|
|
$month_view = new PHUICalendarMonthView(
|
|
|
|
$start_month,
|
|
|
|
$start_year);
|
2015-05-03 00:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$month_view->setUser($viewer);
|
|
|
|
|
|
|
|
$phids = mpull($statuses, 'getUserPHID');
|
|
|
|
|
|
|
|
/* Assign Colors */
|
|
|
|
$unique = array_unique($phids);
|
|
|
|
$allblue = false;
|
|
|
|
$calcolors = CalendarColors::getColors();
|
|
|
|
if (count($unique) > count($calcolors)) {
|
|
|
|
$allblue = true;
|
|
|
|
}
|
|
|
|
$i = 0;
|
|
|
|
$eventcolor = array();
|
|
|
|
foreach ($unique as $phid) {
|
|
|
|
if ($allblue) {
|
|
|
|
$eventcolor[$phid] = CalendarColors::COLOR_SKY;
|
|
|
|
} else {
|
|
|
|
$eventcolor[$phid] = $calcolors[$i];
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($statuses as $status) {
|
|
|
|
$event = new AphrontCalendarEventView();
|
|
|
|
$event->setEpochRange($status->getDateFrom(), $status->getDateTo());
|
|
|
|
|
|
|
|
$name_text = $handles[$status->getUserPHID()]->getName();
|
|
|
|
$status_text = $status->getHumanStatus();
|
|
|
|
$event->setUserPHID($status->getUserPHID());
|
|
|
|
$event->setDescription(pht('%s (%s)', $name_text, $status_text));
|
|
|
|
$event->setName($status_text);
|
|
|
|
$event->setEventID($status->getID());
|
|
|
|
$event->setColor($eventcolor[$status->getUserPHID()]);
|
|
|
|
$month_view->addEvent($event);
|
|
|
|
}
|
|
|
|
|
2015-05-03 01:17:05 +02:00
|
|
|
$month_view->setBrowseURI(
|
|
|
|
$this->getURI('query/'.$query->getQueryKey().'/'));
|
|
|
|
|
2015-05-03 00:27:33 +02:00
|
|
|
return $month_view;
|
2015-05-03 01:17:05 +02:00
|
|
|
}
|
|
|
|
|
2015-05-04 01:57:18 +02:00
|
|
|
private function buildCalendarDayView(
|
|
|
|
array $statuses,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
$viewer = $this->requireViewer();
|
2015-05-05 21:51:32 +02:00
|
|
|
list($start_year, $start_month, $start_day) =
|
|
|
|
$this->getDisplayYearAndMonthAndDay($query);
|
2015-05-04 01:57:18 +02:00
|
|
|
|
|
|
|
$day_view = new PHUICalendarDayView(
|
|
|
|
$start_year,
|
2015-05-05 21:51:32 +02:00
|
|
|
$start_month,
|
2015-05-04 01:57:18 +02:00
|
|
|
$start_day);
|
|
|
|
|
|
|
|
$day_view->setUser($viewer);
|
|
|
|
|
|
|
|
$phids = mpull($statuses, 'getUserPHID');
|
|
|
|
|
|
|
|
foreach ($statuses as $status) {
|
2015-05-07 04:19:14 +02:00
|
|
|
$event = new AphrontCalendarEventView();
|
2015-05-05 06:23:18 +02:00
|
|
|
$event->setEventID($status->getID());
|
2015-05-04 01:57:18 +02:00
|
|
|
$event->setEpochRange($status->getDateFrom(), $status->getDateTo());
|
|
|
|
|
|
|
|
$event->setName($status->getName());
|
2015-05-04 03:13:48 +02:00
|
|
|
$event->setURI('/'.$status->getMonogram());
|
2015-05-04 01:57:18 +02:00
|
|
|
$day_view->addEvent($event);
|
|
|
|
}
|
|
|
|
|
2015-05-05 21:51:32 +02:00
|
|
|
$day_view->setBrowseURI(
|
|
|
|
$this->getURI('query/'.$query->getQueryKey().'/'));
|
|
|
|
|
2015-05-04 01:57:18 +02:00
|
|
|
return $day_view;
|
|
|
|
}
|
|
|
|
|
2015-05-05 21:51:32 +02:00
|
|
|
private function getDisplayYearAndMonthAndDay(
|
2015-05-03 01:17:05 +02:00
|
|
|
PhabricatorSavedQuery $query) {
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
if ($this->calendarYear && $this->calendarMonth) {
|
|
|
|
$start_year = $this->calendarYear;
|
|
|
|
$start_month = $this->calendarMonth;
|
2015-05-05 21:51:32 +02:00
|
|
|
$start_day = $this->calendarDay ? $this->calendarDay : 1;
|
2015-05-04 01:57:18 +02:00
|
|
|
} else {
|
2015-05-04 20:38:21 +02:00
|
|
|
$epoch = $this->getDateFrom($query)->getEpoch();
|
2015-05-04 01:57:18 +02:00
|
|
|
if (!$epoch) {
|
2015-05-04 20:38:21 +02:00
|
|
|
$epoch = $this->getDateTo($query)->getEpoch();
|
2015-05-04 01:57:18 +02:00
|
|
|
if (!$epoch) {
|
|
|
|
$epoch = time();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$start_year = phabricator_format_local_time($epoch, $viewer, 'Y');
|
|
|
|
$start_month = phabricator_format_local_time($epoch, $viewer, 'm');
|
|
|
|
$start_day = phabricator_format_local_time($epoch, $viewer, 'd');
|
|
|
|
}
|
|
|
|
return array($start_year, $start_month, $start_day);
|
|
|
|
}
|
|
|
|
|
2015-05-03 01:17:05 +02:00
|
|
|
public function getPageSize(PhabricatorSavedQuery $saved) {
|
|
|
|
return $saved->getParameter('limit', 1000);
|
2015-05-03 00:27:33 +02:00
|
|
|
}
|
|
|
|
|
2015-05-04 19:08:49 +02:00
|
|
|
private function getDateFrom(PhabricatorSavedQuery $saved) {
|
|
|
|
return $this->getDate($saved, 'rangeStart');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getDateTo(PhabricatorSavedQuery $saved) {
|
|
|
|
return $this->getDate($saved, 'rangeEnd');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getDate(PhabricatorSavedQuery $saved, $key) {
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
|
|
|
$wild = $saved->getParameter($key);
|
|
|
|
if ($wild) {
|
|
|
|
$value = AphrontFormDateControlValue::newFromWild($viewer, $wild);
|
|
|
|
} else {
|
|
|
|
$value = AphrontFormDateControlValue::newFromEpoch(
|
|
|
|
$viewer,
|
2015-05-07 03:41:48 +02:00
|
|
|
PhabricatorTime::getTodayMidnightDateTime($viewer)->format('U'));
|
2015-05-04 19:08:49 +02:00
|
|
|
$value->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
$value->setOptional(true);
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2014-02-06 19:10:18 +01:00
|
|
|
}
|