Differential D16272 Diff 39165 src/applications/calendar/controller/PhabricatorCalendarEventJoinController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/calendar/controller/PhabricatorCalendarEventJoinController.php
<?php | <?php | ||||
final class PhabricatorCalendarEventJoinController | final class PhabricatorCalendarEventJoinController | ||||
extends PhabricatorCalendarController { | extends PhabricatorCalendarController { | ||||
const ACTION_ACCEPT = 'accept'; | |||||
const ACTION_DECLINE = 'decline'; | |||||
const ACTION_JOIN = 'join'; | |||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $this->getViewer(); | |||||
$id = $request->getURIData('id'); | $id = $request->getURIData('id'); | ||||
$action = $request->getURIData('action'); | |||||
$request = $this->getRequest(); | |||||
$viewer = $request->getViewer(); | |||||
$declined_status = PhabricatorCalendarEventInvitee::STATUS_DECLINED; | |||||
$attending_status = PhabricatorCalendarEventInvitee::STATUS_ATTENDING; | |||||
$event = id(new PhabricatorCalendarEventQuery()) | $event = id(new PhabricatorCalendarEventQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($id)) | ->withIDs(array($id)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$event) { | if (!$event) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$cancel_uri = $event->getURI(); | $cancel_uri = $event->getURI(); | ||||
$validation_exception = null; | |||||
$is_attending = $event->getIsUserAttending($viewer->getPHID()); | |||||
if ($request->isFormPost()) { | |||||
$new_status = null; | |||||
$action = $request->getURIData('action'); | |||||
switch ($action) { | switch ($action) { | ||||
case self::ACTION_ACCEPT: | case 'accept': | ||||
$new_status = $attending_status; | $is_join = true; | ||||
break; | break; | ||||
case self::ACTION_JOIN: | case 'decline': | ||||
if ($is_attending) { | $is_join = false; | ||||
$new_status = $declined_status; | |||||
} else { | |||||
$new_status = $attending_status; | |||||
} | |||||
break; | break; | ||||
case self::ACTION_DECLINE: | default: | ||||
$new_status = $declined_status; | $is_join = !$event->getIsUserAttending($viewer->getPHID()); | ||||
break; | break; | ||||
} | } | ||||
$new_status = array($viewer->getPHID() => $new_status); | $validation_exception = null; | ||||
if ($request->isFormPost()) { | |||||
if ($is_join) { | |||||
$xaction_type = PhabricatorCalendarEventTransaction::TYPE_ACCEPT; | |||||
} else { | |||||
$xaction_type = PhabricatorCalendarEventTransaction::TYPE_DECLINE; | |||||
} | |||||
$xaction = id(new PhabricatorCalendarEventTransaction()) | $xaction = id(new PhabricatorCalendarEventTransaction()) | ||||
->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_INVITE) | ->setTransactionType($xaction_type) | ||||
->setNewValue($new_status); | ->setNewValue(true); | ||||
$editor = id(new PhabricatorCalendarEventEditor()) | $editor = id(new PhabricatorCalendarEventEditor()) | ||||
->setActor($viewer) | ->setActor($viewer) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->setContinueOnMissingFields(true); | ->setContinueOnMissingFields(true); | ||||
try { | try { | ||||
$editor->applyTransactions($event, array($xaction)); | $editor->applyTransactions($event, array($xaction)); | ||||
return id(new AphrontRedirectResponse())->setURI($cancel_uri); | return id(new AphrontRedirectResponse())->setURI($cancel_uri); | ||||
} catch (PhabricatorApplicationTransactionValidationException $ex) { | } catch (PhabricatorApplicationTransactionValidationException $ex) { | ||||
$validation_exception = $ex; | $validation_exception = $ex; | ||||
} | } | ||||
} | } | ||||
if (($action == self::ACTION_JOIN && !$is_attending) | if ($is_join) { | ||||
|| $action == self::ACTION_ACCEPT) { | |||||
$title = pht('Join Event'); | $title = pht('Join Event'); | ||||
$paragraph = pht('Would you like to join this event?'); | $paragraph = pht('Would you like to join this event?'); | ||||
$submit = pht('Join'); | $submit = pht('Join'); | ||||
} else { | } else { | ||||
$title = pht('Decline Event'); | $title = pht('Decline Event'); | ||||
$paragraph = pht('Would you like to decline this event?'); | $paragraph = pht('Would you like to decline this event?'); | ||||
$submit = pht('Decline'); | $submit = pht('Decline'); | ||||
} | } | ||||
Show All 9 Lines |