2014-02-06 19:10:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCalendarEventViewController
|
2014-02-18 01:08:50 +01:00
|
|
|
extends PhabricatorCalendarController {
|
2014-02-06 19:10:27 +01:00
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
2014-05-14 19:00:46 +02:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-06 19:10:27 +01:00
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
2015-05-29 02:27:25 +02:00
|
|
|
$sequence = $request->getURIData('sequence');
|
|
|
|
|
2014-02-06 19:10:27 +01:00
|
|
|
$event = id(new PhabricatorCalendarEventQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
|
|
|
if (!$event) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2015-05-29 02:27:25 +02:00
|
|
|
if ($sequence && $event->getIsRecurring()) {
|
|
|
|
$event = $event->generateNthGhost($sequence, $viewer);
|
|
|
|
} else if ($sequence) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2015-04-27 23:27:00 +02:00
|
|
|
$title = 'E'.$event->getID();
|
2015-04-28 17:34:26 +02:00
|
|
|
$page_title = $title.' '.$event->getName();
|
2014-02-06 19:10:27 +01:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2015-04-27 23:27:00 +02:00
|
|
|
$crumbs->addTextCrumb($title, '/E'.$event->getID());
|
2014-02-06 19:10:27 +01:00
|
|
|
|
2015-04-28 15:26:48 +02:00
|
|
|
$timeline = $this->buildTransactionTimeline(
|
|
|
|
$event,
|
|
|
|
new PhabricatorCalendarEventTransactionQuery());
|
|
|
|
|
2014-02-06 19:10:27 +01:00
|
|
|
$header = $this->buildHeaderView($event);
|
|
|
|
$actions = $this->buildActionView($event);
|
|
|
|
$properties = $this->buildPropertyView($event);
|
|
|
|
|
|
|
|
$properties->setActionList($actions);
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->addPropertyList($properties);
|
|
|
|
|
2015-05-01 02:38:04 +02:00
|
|
|
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
|
|
|
$add_comment_header = $is_serious
|
|
|
|
? pht('Add Comment')
|
|
|
|
: pht('Add To Plate');
|
|
|
|
$draft = PhabricatorDraft::newFromUserAndKey($viewer, $event->getPHID());
|
|
|
|
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObjectPHID($event->getPHID())
|
|
|
|
->setDraft($draft)
|
|
|
|
->setHeaderText($add_comment_header)
|
|
|
|
->setAction(
|
|
|
|
$this->getApplicationURI('/event/comment/'.$event->getID().'/'))
|
|
|
|
->setSubmitButtonName(pht('Add Comment'));
|
|
|
|
|
2014-02-06 19:10:27 +01:00
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$box,
|
2015-04-28 15:26:48 +02:00
|
|
|
$timeline,
|
2015-05-01 02:38:04 +02:00
|
|
|
$add_comment_form,
|
2014-02-06 19:10:27 +01:00
|
|
|
),
|
|
|
|
array(
|
2015-04-28 17:34:26 +02:00
|
|
|
'title' => $page_title,
|
2014-02-06 19:10:27 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildHeaderView(PhabricatorCalendarEvent $event) {
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
2015-04-30 04:48:46 +02:00
|
|
|
$id = $event->getID();
|
|
|
|
|
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 = $event->getIsCancelled();
|
|
|
|
$icon = $is_cancelled ? ('fa-times') : ('fa-calendar');
|
|
|
|
$color = $is_cancelled ? ('grey') : ('green');
|
2015-05-06 20:11:38 +02:00
|
|
|
$status = $is_cancelled ? pht('Cancelled') : pht('Active');
|
2014-02-06 19:10:27 +01:00
|
|
|
|
2015-04-30 04:48:46 +02:00
|
|
|
$invite_status = $event->getUserInviteStatus($viewer->getPHID());
|
|
|
|
$status_invited = PhabricatorCalendarEventInvitee::STATUS_INVITED;
|
|
|
|
$is_invite_pending = ($invite_status == $status_invited);
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
2014-02-06 19:10:27 +01:00
|
|
|
->setUser($viewer)
|
2015-04-28 17:34:26 +02:00
|
|
|
->setHeader($event->getName())
|
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
|
|
|
->setStatus($icon, $color, $status)
|
2014-02-06 19:10:27 +01:00
|
|
|
->setPolicyObject($event);
|
2015-04-30 04:48:46 +02:00
|
|
|
|
|
|
|
if ($is_invite_pending) {
|
|
|
|
$decline_button = id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setIcon(id(new PHUIIconView())
|
|
|
|
->setIconFont('fa-times grey'))
|
|
|
|
->setHref($this->getApplicationURI("/event/decline/{$id}/"))
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setText(pht('Decline'));
|
|
|
|
|
|
|
|
$accept_button = id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setIcon(id(new PHUIIconView())
|
|
|
|
->setIconFont('fa-check green'))
|
|
|
|
->setHref($this->getApplicationURI("/event/accept/{$id}/"))
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setText(pht('Accept'));
|
|
|
|
|
|
|
|
$header->addActionLink($decline_button)
|
|
|
|
->addActionLink($accept_button);
|
|
|
|
}
|
|
|
|
return $header;
|
2014-02-06 19:10:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function buildActionView(PhabricatorCalendarEvent $event) {
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
$id = $event->getID();
|
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 = $event->getIsCancelled();
|
2015-04-30 03:18:27 +02:00
|
|
|
$is_attending = $event->getIsUserAttending($viewer->getPHID());
|
2014-02-06 19:10:27 +01:00
|
|
|
|
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
|
|
->setObjectURI($this->getApplicationURI('event/'.$id.'/'))
|
2015-04-28 19:40:35 +02:00
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($event);
|
2014-02-06 19:10:27 +01:00
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$event,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
2015-06-01 00:04:48 +02:00
|
|
|
if (($event->getIsRecurring() && $event->getIsGhostEvent())) {
|
|
|
|
$index = $event->getSequenceIndex();
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit This Instance'))
|
|
|
|
->setIcon('fa-pencil')
|
|
|
|
->setHref($this->getApplicationURI("event/edit/{$id}/{$index}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$event->getIsRecurring() && !$event->getIsGhostEvent()) {
|
2015-05-29 02:27:25 +02:00
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit Event'))
|
|
|
|
->setIcon('fa-pencil')
|
|
|
|
->setHref($this->getApplicationURI("event/edit/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
}
|
2014-02-06 19:10:27 +01:00
|
|
|
|
2015-04-30 03:18:27 +02:00
|
|
|
if ($is_attending) {
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Decline Event'))
|
|
|
|
->setIcon('fa-user-times')
|
|
|
|
->setHref($this->getApplicationURI("event/join/{$id}/"))
|
|
|
|
->setWorkflow(true));
|
|
|
|
} else {
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Join Event'))
|
|
|
|
->setIcon('fa-user-plus')
|
|
|
|
->setHref($this->getApplicationURI("event/join/{$id}/"))
|
|
|
|
->setWorkflow(true));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
if ($is_cancelled) {
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Reinstate Event'))
|
|
|
|
->setIcon('fa-plus')
|
|
|
|
->setHref($this->getApplicationURI("event/cancel/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(true));
|
|
|
|
} else {
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Cancel Event'))
|
|
|
|
->setIcon('fa-times')
|
|
|
|
->setHref($this->getApplicationURI("event/cancel/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(true));
|
|
|
|
}
|
2014-02-06 19:10:27 +01:00
|
|
|
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPropertyView(PhabricatorCalendarEvent $event) {
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$properties = id(new PHUIPropertyListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($event);
|
|
|
|
|
2015-05-08 17:08:26 +02:00
|
|
|
if ($event->getIsAllDay()) {
|
|
|
|
$date_start = phabricator_date($event->getDateFrom(), $viewer);
|
|
|
|
$date_end = phabricator_date($event->getDateTo(), $viewer);
|
|
|
|
|
|
|
|
if ($date_start == $date_end) {
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Time'),
|
|
|
|
phabricator_date($event->getDateFrom(), $viewer));
|
|
|
|
} else {
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Starts'),
|
|
|
|
phabricator_date($event->getDateFrom(), $viewer));
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Ends'),
|
|
|
|
phabricator_date($event->getDateTo(), $viewer));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Starts'),
|
|
|
|
phabricator_datetime($event->getDateFrom(), $viewer));
|
2014-02-06 19:10:27 +01:00
|
|
|
|
2015-05-08 17:08:26 +02:00
|
|
|
$properties->addProperty(
|
|
|
|
pht('Ends'),
|
|
|
|
phabricator_datetime($event->getDateTo(), $viewer));
|
|
|
|
}
|
2014-02-06 19:10:27 +01:00
|
|
|
|
2015-05-29 02:27:25 +02:00
|
|
|
if ($event->getIsRecurring()) {
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Recurs'),
|
2015-05-29 22:58:53 +02:00
|
|
|
ucwords(idx($event->getRecurrenceFrequency(), 'rule')));
|
2015-06-01 00:04:48 +02:00
|
|
|
if ($event->getInstanceOfEventPHID()) {
|
2015-05-29 22:58:53 +02:00
|
|
|
$properties->addProperty(
|
|
|
|
pht('Recurrence of Event'),
|
|
|
|
$viewer->renderHandle($event->getInstanceOfEventPHID()));
|
|
|
|
}
|
2015-05-29 02:27:25 +02:00
|
|
|
}
|
|
|
|
|
2015-05-05 19:26:15 +02:00
|
|
|
$properties->addProperty(
|
|
|
|
pht('Host'),
|
|
|
|
$viewer->renderHandle($event->getUserPHID()));
|
|
|
|
|
2015-04-29 22:51:09 +02:00
|
|
|
$invitees = $event->getInvitees();
|
2015-05-05 19:26:15 +02:00
|
|
|
foreach ($invitees as $key => $invitee) {
|
2015-04-30 00:31:02 +02:00
|
|
|
if ($invitee->isUninvited()) {
|
2015-05-05 19:26:15 +02:00
|
|
|
unset($invitees[$key]);
|
2015-04-30 00:31:02 +02:00
|
|
|
}
|
2015-04-29 22:51:09 +02:00
|
|
|
}
|
|
|
|
|
2015-05-05 19:26:15 +02:00
|
|
|
if ($invitees) {
|
|
|
|
$invitee_list = new PHUIStatusListView();
|
2015-05-05 21:29:04 +02:00
|
|
|
|
|
|
|
$icon_invited = PHUIStatusItemView::ICON_OPEN;
|
|
|
|
$icon_attending = PHUIStatusItemView::ICON_ACCEPT;
|
|
|
|
$icon_declined = PHUIStatusItemView::ICON_REJECT;
|
|
|
|
|
|
|
|
$status_invited = PhabricatorCalendarEventInvitee::STATUS_INVITED;
|
|
|
|
$status_attending = PhabricatorCalendarEventInvitee::STATUS_ATTENDING;
|
|
|
|
$status_declined = PhabricatorCalendarEventInvitee::STATUS_DECLINED;
|
|
|
|
|
|
|
|
$icon_map = array(
|
|
|
|
$status_invited => $icon_invited,
|
|
|
|
$status_attending => $icon_attending,
|
|
|
|
$status_declined => $icon_declined,
|
|
|
|
);
|
|
|
|
|
|
|
|
$icon_color_map = array(
|
|
|
|
$status_invited => null,
|
|
|
|
$status_attending => 'green',
|
|
|
|
$status_declined => 'red',
|
|
|
|
);
|
|
|
|
|
2015-05-05 19:26:15 +02:00
|
|
|
foreach ($invitees as $invitee) {
|
|
|
|
$item = new PHUIStatusItemView();
|
|
|
|
$invitee_phid = $invitee->getInviteePHID();
|
2015-05-05 21:29:04 +02:00
|
|
|
$status = $invitee->getStatus();
|
2015-05-05 19:26:15 +02:00
|
|
|
$target = $viewer->renderHandle($invitee_phid);
|
2015-05-05 21:29:04 +02:00
|
|
|
$icon = $icon_map[$status];
|
|
|
|
$icon_color = $icon_color_map[$status];
|
|
|
|
|
|
|
|
$item->setIcon($icon, $icon_color)
|
2015-05-05 19:26:15 +02:00
|
|
|
->setTarget($target);
|
|
|
|
$invitee_list->addItem($item);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$invitee_list = phutil_tag(
|
|
|
|
'em',
|
|
|
|
array(),
|
|
|
|
pht('None'));
|
|
|
|
}
|
2015-05-04 00:29:42 +02:00
|
|
|
|
2015-04-29 22:51:09 +02:00
|
|
|
$properties->addProperty(
|
|
|
|
pht('Invitees'),
|
|
|
|
$invitee_list);
|
|
|
|
|
2015-04-28 19:40:35 +02:00
|
|
|
$properties->invokeWillRenderEvent();
|
|
|
|
|
2015-05-19 22:09:28 +02:00
|
|
|
$icon_display = PhabricatorCalendarIcon::renderIconForChooser(
|
|
|
|
$event->getIcon());
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Icon'),
|
|
|
|
$icon_display);
|
|
|
|
|
2014-02-18 01:08:25 +01:00
|
|
|
$properties->addSectionHeader(
|
|
|
|
pht('Description'),
|
|
|
|
PHUIPropertyListView::ICON_SUMMARY);
|
|
|
|
$properties->addTextContent($event->getDescription());
|
|
|
|
|
2014-02-06 19:10:27 +01:00
|
|
|
return $properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|