Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/calendar/controller/PhabricatorCalendarEventAvailabilityController.php
12256 views
1
<?php
2
3
final class PhabricatorCalendarEventAvailabilityController
4
extends PhabricatorCalendarController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $this->getViewer();
8
$id = $request->getURIData('id');
9
10
$event = id(new PhabricatorCalendarEventQuery())
11
->setViewer($viewer)
12
->withIDs(array($id))
13
->executeOne();
14
if (!$event) {
15
return new Aphront404Response();
16
}
17
18
$response = $this->newImportedEventResponse($event);
19
if ($response) {
20
return $response;
21
}
22
23
$cancel_uri = $event->getURI();
24
25
if (!$event->getIsUserAttending($viewer->getPHID())) {
26
return $this->newDialog()
27
->setTitle(pht('Not Attending Event'))
28
->appendParagraph(
29
pht(
30
'You can not change your display availability for events you '.
31
'are not attending.'))
32
->addCancelButton($cancel_uri);
33
}
34
35
// TODO: This endpoint currently only works via AJAX. It would be vaguely
36
// nice to provide a plain HTML version of the workflow where we return
37
// a dialog with a vanilla <select /> in it for cases where all the JS
38
// breaks.
39
$request->validateCSRF();
40
41
$invitee = $event->getInviteeForPHID($viewer->getPHID());
42
43
$map = PhabricatorCalendarEventInvitee::getAvailabilityMap();
44
$new_availability = $request->getURIData('availability');
45
if (isset($map[$new_availability])) {
46
$invitee
47
->setAvailability($new_availability)
48
->save();
49
50
// Invalidate the availability cache.
51
$viewer->writeAvailabilityCache(array(), null);
52
}
53
54
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
55
}
56
}
57
58