1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-22 10:18:48 +02:00
phorge-phorge/src/applications/calendar/controller/PhabricatorCalendarEventJoinController.php
epriestley 3a09bb577e Create separate "Accept" and "Decline" transactions for Calendar
Summary:
Ref T9275. Currently, there's a single "invite" transaction type for managing Calendar invites, and it takes a map of invitees to status.

This isn't great for EditEngine or API access, since it lets you set anyone else to any status and we can't reuse as much code as we can with a simpler API.

Make "Accept" and "Decline" separate actions which affect the actor's invite, so "invite" can be a simpler transaction which just invites or uninvites people.

Test Plan:
  - Joined/accepted/declined an event invitation.
  - Edited event invitees.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9275

Differential Revision: https://secure.phabricator.com/D16272
2016-07-13 07:41:58 -07:00

76 lines
2.1 KiB
PHP

<?php
final class PhabricatorCalendarEventJoinController
extends PhabricatorCalendarController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$id = $request->getURIData('id');
$event = id(new PhabricatorCalendarEventQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$event) {
return new Aphront404Response();
}
$cancel_uri = $event->getURI();
$action = $request->getURIData('action');
switch ($action) {
case 'accept':
$is_join = true;
break;
case 'decline':
$is_join = false;
break;
default:
$is_join = !$event->getIsUserAttending($viewer->getPHID());
break;
}
$validation_exception = null;
if ($request->isFormPost()) {
if ($is_join) {
$xaction_type = PhabricatorCalendarEventTransaction::TYPE_ACCEPT;
} else {
$xaction_type = PhabricatorCalendarEventTransaction::TYPE_DECLINE;
}
$xaction = id(new PhabricatorCalendarEventTransaction())
->setTransactionType($xaction_type)
->setNewValue(true);
$editor = id(new PhabricatorCalendarEventEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);
try {
$editor->applyTransactions($event, array($xaction));
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
}
}
if ($is_join) {
$title = pht('Join Event');
$paragraph = pht('Would you like to join this event?');
$submit = pht('Join');
} else {
$title = pht('Decline Event');
$paragraph = pht('Would you like to decline this event?');
$submit = pht('Decline');
}
return $this->newDialog()
->setTitle($title)
->setValidationException($validation_exception)
->appendParagraph($paragraph)
->addCancelButton($cancel_uri)
->addSubmitButton($submit);
}
}