2015-04-30 03:18:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCalendarEventJoinController
|
|
|
|
extends PhabricatorCalendarController {
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
2016-07-12 00:08:53 +02:00
|
|
|
$viewer = $this->getViewer();
|
2015-08-02 00:43:14 +02:00
|
|
|
$id = $request->getURIData('id');
|
2015-04-30 03:18:27 +02:00
|
|
|
|
|
|
|
$event = id(new PhabricatorCalendarEventQuery())
|
|
|
|
->setViewer($viewer)
|
2015-08-02 00:43:14 +02:00
|
|
|
->withIDs(array($id))
|
2015-04-30 03:18:27 +02:00
|
|
|
->executeOne();
|
|
|
|
if (!$event) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
Generate "stub" events earlier, so more infrastructure works with Calendar
Summary:
Ref T9275. When you create a recurring event which recurs forever, we want to avoid writing an infinite number of rows to the database.
Currently, we write a row to the database right before you edit the event. Until then, we refer to it as `E123/999` or whatever ("instance 999 of event 123").
This creates a big mess with trying to make recurring events work with EditEngine, Subscriptions, Projects, Flags, Tokens, etc -- all of this stuff assumes that whatever you're working with has a PHID.
I poked at letting this stuff work without a PHID a little bit, but that looked like a gigantic mess.
Instead, generate an event "stub" a little sooner (when you look at the event detail page). This is basically just an ID/PHID to refer to the instance.
Then, when you edit the stub, "materialize" it into a real event.
This still has some issues, but I think it's more promising than the other approach was.
Also:
- Removes dead user profile calendar controller.
- Replaces comments with EditEngine comments.
Test Plan:
- Commented on a recurring event.
- Awarded tokens to a recurring event.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T9275
Differential Revision: https://secure.phabricator.com/D16248
2016-07-07 16:19:58 +02:00
|
|
|
$cancel_uri = $event->getURI();
|
2015-04-30 03:18:27 +02:00
|
|
|
|
2016-07-12 00:08:53 +02:00
|
|
|
$action = $request->getURIData('action');
|
|
|
|
switch ($action) {
|
|
|
|
case 'accept':
|
|
|
|
$is_join = true;
|
|
|
|
break;
|
|
|
|
case 'decline':
|
|
|
|
$is_join = false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$is_join = !$event->getIsUserAttending($viewer->getPHID());
|
|
|
|
break;
|
|
|
|
}
|
2015-04-30 03:18:27 +02:00
|
|
|
|
2016-07-12 00:08:53 +02:00
|
|
|
$validation_exception = null;
|
2015-04-30 03:18:27 +02:00
|
|
|
if ($request->isFormPost()) {
|
2016-07-12 00:08:53 +02:00
|
|
|
if ($is_join) {
|
|
|
|
$xaction_type = PhabricatorCalendarEventTransaction::TYPE_ACCEPT;
|
|
|
|
} else {
|
|
|
|
$xaction_type = PhabricatorCalendarEventTransaction::TYPE_DECLINE;
|
2015-04-30 03:18:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$xaction = id(new PhabricatorCalendarEventTransaction())
|
2016-07-12 00:08:53 +02:00
|
|
|
->setTransactionType($xaction_type)
|
|
|
|
->setNewValue(true);
|
2015-04-30 03:18:27 +02:00
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-12 00:08:53 +02:00
|
|
|
if ($is_join) {
|
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);
|
|
|
|
}
|
|
|
|
}
|