Path: blob/master/src/applications/calendar/controller/PhabricatorCalendarEventCancelController.php
12256 views
<?php12final class PhabricatorCalendarEventCancelController3extends PhabricatorCalendarController {45public function handleRequest(AphrontRequest $request) {6$viewer = $request->getViewer();7$id = $request->getURIData('id');89// Just check CAN_VIEW first. Then we'll check if this is an import so10// we can raise a better error.11$event = id(new PhabricatorCalendarEventQuery())12->setViewer($viewer)13->withIDs(array($id))14->executeOne();15if (!$event) {16return new Aphront404Response();17}1819$response = $this->newImportedEventResponse($event);20if ($response) {21return $response;22}2324// Now that we've done the import check, check for CAN_EDIT.25PhabricatorPolicyFilter::requireCapability(26$viewer,27$event,28PhabricatorPolicyCapability::CAN_EDIT);2930$cancel_uri = $event->getURI();3132$is_parent = $event->isParentEvent();33$is_child = $event->isChildEvent();3435$is_cancelled = $event->getIsCancelled();36$is_recurring = $event->getIsRecurring();3738$validation_exception = null;39if ($request->isFormPost()) {4041$targets = array($event);42if ($is_recurring) {43$mode = $request->getStr('mode');44$is_future = ($mode == 'future');4546// We need to fork the event if we're cancelling just the parent, or47// are cancelling a child and all future events.48$must_fork = ($is_child && $is_future) ||49($is_parent && !$is_future);50if ($must_fork) {51$fork_target = $event->loadForkTarget($viewer);52if ($fork_target) {53$xactions = array();5455$xaction = id(new PhabricatorCalendarEventTransaction())56->setTransactionType(57PhabricatorCalendarEventForkTransaction::TRANSACTIONTYPE)58->setNewValue(true);5960$editor = id(new PhabricatorCalendarEventEditor())61->setActor($viewer)62->setContentSourceFromRequest($request)63->setContinueOnNoEffect(true)64->setContinueOnMissingFields(true);6566$editor->applyTransactions($fork_target, array($xaction));67}68}6970if ($is_future) {71$future = $event->loadFutureEvents($viewer);72foreach ($future as $future_event) {73$targets[] = $future_event;74}75}76}7778foreach ($targets as $target) {79$xactions = array();8081$xaction = id(new PhabricatorCalendarEventTransaction())82->setTransactionType(83PhabricatorCalendarEventCancelTransaction::TRANSACTIONTYPE)84->setNewValue(!$is_cancelled);8586$editor = id(new PhabricatorCalendarEventEditor())87->setActor($viewer)88->setContentSourceFromRequest($request)89->setContinueOnNoEffect(true)90->setContinueOnMissingFields(true);9192try {93$editor->applyTransactions($target, array($xaction));94} catch (PhabricatorApplicationTransactionValidationException $ex) {95$validation_exception = $ex;96break;97}9899}100101if (!$validation_exception) {102return id(new AphrontRedirectResponse())->setURI($cancel_uri);103}104}105106if ($is_cancelled) {107$title = pht('Reinstate Event');108if ($is_recurring) {109$body = pht(110'This event is part of a series. Which events do you want to '.111'reinstate?');112$show_control = true;113} else {114$body = pht('Reinstate this event?');115$show_control = false;116}117$submit = pht('Reinstate Event');118} else {119$title = pht('Cancel Event');120if ($is_recurring) {121$body = pht(122'This event is part of a series. Which events do you want to '.123'cancel?');124$show_control = true;125} else {126$body = pht('Cancel this event?');127$show_control = false;128}129$submit = pht('Cancel Event');130}131132$dialog = $this->newDialog()133->setTitle($title)134->setValidationException($validation_exception)135->appendParagraph($body)136->addCancelButton($cancel_uri, pht('Back'))137->addSubmitButton($submit);138139if ($show_control) {140$start_time = phutil_tag(141'strong',142array(),143phabricator_datetime($event->getStartDateTimeEpoch(), $viewer));144145if ($is_cancelled) {146$this_name = pht('Reinstate Only This Event');147$this_caption = pht(148'Reinstate only the event which occurs on %s.',149$start_time);150151$future_name = pht('Reinstate This And All Later Events');152$future_caption = pht(153'Reinstate this event and all events in the series which occur '.154'on or after %s.',155$start_time);156} else {157$this_name = pht('Cancel Only This Event');158$this_caption = pht(159'Cancel only the event which occurs on %s.',160$start_time);161162$future_name = pht('Cancel This And All Later Events');163$future_caption = pht(164'Cancel this event and all events in the series which occur '.165'on or after %s.',166$start_time);167}168169170$form = id(new AphrontFormView())171->setViewer($viewer)172->appendControl(173id(new AphrontFormRadioButtonControl())174->setName('mode')175->setValue(PhabricatorCalendarEventEditEngine::MODE_THIS)176->addButton(177PhabricatorCalendarEventEditEngine::MODE_THIS,178$this_name,179$this_caption)180->addButton(181PhabricatorCalendarEventEditEngine::MODE_FUTURE,182$future_name,183$future_caption));184185$dialog186->setWidth(AphrontDialogView::WIDTH_FORM)187->appendForm($form);188}189190return $dialog;191}192}193194195