@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorCalendarEventJoinController
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 $action = $request->getURIData('action');
26 switch ($action) {
27 case 'accept':
28 $is_join = true;
29 break;
30 case 'decline':
31 $is_join = false;
32 break;
33 default:
34 $is_join = !$event->getIsUserAttending($viewer->getPHID());
35 break;
36 }
37
38 $validation_exception = null;
39 if ($request->isFormPost()) {
40 if ($is_join) {
41 $xaction_type =
42 PhabricatorCalendarEventAcceptTransaction::TRANSACTIONTYPE;
43 } else {
44 $xaction_type =
45 PhabricatorCalendarEventDeclineTransaction::TRANSACTIONTYPE;
46 }
47
48 $xaction = id(new PhabricatorCalendarEventTransaction())
49 ->setTransactionType($xaction_type)
50 ->setNewValue(true);
51
52 $editor = id(new PhabricatorCalendarEventEditor())
53 ->setActor($viewer)
54 ->setContentSourceFromRequest($request)
55 ->setContinueOnNoEffect(true)
56 ->setContinueOnMissingFields(true);
57
58 try {
59 $editor->applyTransactions($event, array($xaction));
60 return id(new AphrontRedirectResponse())->setURI($cancel_uri);
61 } catch (PhabricatorApplicationTransactionValidationException $ex) {
62 $validation_exception = $ex;
63 }
64 }
65
66 if ($is_join) {
67 $title = pht('Join Event');
68 $paragraph = pht('Would you like to join this event?');
69 $submit = pht('Join');
70 } else {
71 $title = pht('Decline Event');
72 $paragraph = pht('Would you like to decline this event?');
73 $submit = pht('Decline');
74 }
75
76 return $this->newDialog()
77 ->setTitle($title)
78 ->setValidationException($validation_exception)
79 ->appendParagraph($paragraph)
80 ->addCancelButton($cancel_uri)
81 ->addSubmitButton($submit);
82 }
83}