1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-13 10:22:42 +01:00
phorge-phorge/src/applications/calendar/controller/PhabricatorCalendarEventCancelController.php

130 lines
3.9 KiB
PHP
Raw Normal View History

<?php
final class PhabricatorCalendarEventCancelController
extends PhabricatorCalendarController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$sequence = $request->getURIData('sequence');
$event = id(new PhabricatorCalendarEventQuery())
->setViewer($user)
->withIDs(array($this->id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if ($sequence) {
$parent_event = $event;
$event = $parent_event->generateNthGhost($sequence, $user);
$event->attachParentEvent($parent_event);
}
if (!$event) {
return new Aphront404Response();
}
if (!$sequence) {
$cancel_uri = '/E'.$event->getID();
} else {
$cancel_uri = '/E'.$event->getID().'/'.$sequence;
}
$is_cancelled = $event->getIsCancelled();
$is_parent_cancelled = $event->getIsParentCancelled();
$is_parent = $event->getIsRecurrenceParent();
$validation_exception = null;
if ($request->isFormPost()) {
if ($is_cancelled && $sequence) {
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
} else if ($sequence) {
$event = $this->createEventFromGhost(
$user,
$event,
$sequence);
$event->applyViewerTimezone($user);
}
$xactions = array();
$xaction = id(new PhabricatorCalendarEventTransaction())
->setTransactionType(
PhabricatorCalendarEventTransaction::TYPE_CANCEL)
->setNewValue(!$is_cancelled);
$editor = id(new PhabricatorCalendarEventEditor())
->setActor($user)
->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_cancelled) {
if ($sequence || $is_parent_cancelled) {
$title = pht('Cannot Reinstate Instance');
$paragraph = pht('Cannot reinstate an instance of a ' .
'cancelled recurring event.');
$cancel = pht('Cancel');
$submit = null;
} else if ($is_parent) {
$title = pht('Reinstate Recurrence');
$paragraph = pht('Reinstate the entire series ' .
'of recurring events?');
$cancel = pht('Don\'t Reinstate Recurrence');
$submit = pht('Reinstate Recurrence');
} else {
$title = pht('Reinstate Event');
$paragraph = pht('Reinstate this event?');
$cancel = pht('Don\'t Reinstate Event');
$submit = pht('Reinstate Event');
}
} else {
if ($sequence) {
$title = pht('Cancel Instance');
$paragraph = pht('Cancel just this instance ' .
'of a recurring event.');
$cancel = pht('Don\'t Cancel Instance');
$submit = pht('Cancel Instance');
} else if ($is_parent) {
$title = pht('Cancel Recurrence');
$paragraph = pht('Cancel the entire series ' .
'of recurring events?');
$cancel = pht('Don\'t Cancel Recurrence');
$submit = pht('Cancel Recurrence');
} else {
$title = pht('Cancel Event');
$paragraph = pht('You can always reinstate ' .
'the event later.');
$cancel = pht('Don\'t Cancel Event');
$submit = pht('Cancel Event');
}
}
return $this->newDialog()
->setTitle($title)
->setValidationException($validation_exception)
->appendParagraph($paragraph)
->addCancelButton($cancel_uri, $cancel)
->addSubmitButton($submit);
}
}