2015-04-30 03:18:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCalendarEventJoinController
|
|
|
|
extends PhabricatorCalendarController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
2015-04-30 04:48:46 +02:00
|
|
|
const ACTION_ACCEPT = 'accept';
|
|
|
|
const ACTION_DECLINE = 'decline';
|
|
|
|
const ACTION_JOIN = 'join';
|
|
|
|
|
2015-04-30 03:18:27 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$this->id = $request->getURIData('id');
|
2015-04-30 04:48:46 +02:00
|
|
|
$action = $request->getURIData('action');
|
|
|
|
|
2015-04-30 03:18:27 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$declined_status = PhabricatorCalendarEventInvitee::STATUS_DECLINED;
|
|
|
|
$attending_status = PhabricatorCalendarEventInvitee::STATUS_ATTENDING;
|
|
|
|
|
|
|
|
$event = id(new PhabricatorCalendarEventQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$event) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$cancel_uri = '/E'.$event->getID();
|
|
|
|
$validation_exception = null;
|
|
|
|
|
|
|
|
$is_attending = $event->getIsUserAttending($viewer->getPHID());
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$new_status = null;
|
|
|
|
|
2015-05-05 21:29:04 +02:00
|
|
|
switch ($action) {
|
|
|
|
case self::ACTION_ACCEPT:
|
|
|
|
$new_status = $attending_status;
|
|
|
|
break;
|
|
|
|
case self::ACTION_JOIN:
|
|
|
|
if ($is_attending) {
|
|
|
|
$new_status = $declined_status;
|
|
|
|
} else {
|
|
|
|
$new_status = $attending_status;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case self::ACTION_DECLINE:
|
|
|
|
$new_status = $declined_status;
|
|
|
|
break;
|
2015-04-30 03:18:27 +02:00
|
|
|
}
|
|
|
|
|
2015-05-05 21:29:04 +02:00
|
|
|
$new_status = array($viewer->getPHID() => $new_status);
|
|
|
|
|
2015-04-30 03:18:27 +02:00
|
|
|
$xaction = id(new PhabricatorCalendarEventTransaction())
|
2015-07-07 14:52:59 +02:00
|
|
|
->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_INVITE)
|
2015-04-30 03:18:27 +02:00
|
|
|
->setNewValue($new_status);
|
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 04:48:46 +02:00
|
|
|
if (($action == self::ACTION_JOIN && !$is_attending)
|
|
|
|
|| $action == self::ACTION_ACCEPT) {
|
2015-04-30 03:18:27 +02:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|