Path: blob/master/src/applications/calendar/controller/PhabricatorCalendarEventJoinController.php
12256 views
<?php12final class PhabricatorCalendarEventJoinController3extends PhabricatorCalendarController {45public function handleRequest(AphrontRequest $request) {6$viewer = $this->getViewer();7$id = $request->getURIData('id');89$event = id(new PhabricatorCalendarEventQuery())10->setViewer($viewer)11->withIDs(array($id))12->executeOne();13if (!$event) {14return new Aphront404Response();15}1617$response = $this->newImportedEventResponse($event);18if ($response) {19return $response;20}2122$cancel_uri = $event->getURI();2324$action = $request->getURIData('action');25switch ($action) {26case 'accept':27$is_join = true;28break;29case 'decline':30$is_join = false;31break;32default:33$is_join = !$event->getIsUserAttending($viewer->getPHID());34break;35}3637$validation_exception = null;38if ($request->isFormPost()) {39if ($is_join) {40$xaction_type =41PhabricatorCalendarEventAcceptTransaction::TRANSACTIONTYPE;42} else {43$xaction_type =44PhabricatorCalendarEventDeclineTransaction::TRANSACTIONTYPE;45}4647$xaction = id(new PhabricatorCalendarEventTransaction())48->setTransactionType($xaction_type)49->setNewValue(true);5051$editor = id(new PhabricatorCalendarEventEditor())52->setActor($viewer)53->setContentSourceFromRequest($request)54->setContinueOnNoEffect(true)55->setContinueOnMissingFields(true);5657try {58$editor->applyTransactions($event, array($xaction));59return id(new AphrontRedirectResponse())->setURI($cancel_uri);60} catch (PhabricatorApplicationTransactionValidationException $ex) {61$validation_exception = $ex;62}63}6465if ($is_join) {66$title = pht('Join Event');67$paragraph = pht('Would you like to join this event?');68$submit = pht('Join');69} else {70$title = pht('Decline Event');71$paragraph = pht('Would you like to decline this event?');72$submit = pht('Decline');73}7475return $this->newDialog()76->setTitle($title)77->setValidationException($validation_exception)78->appendParagraph($paragraph)79->addCancelButton($cancel_uri)80->addSubmitButton($submit);81}82}838485