diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php b/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php index 0b1be3860f..01875351b6 100644 --- a/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarEventEditController.php @@ -19,7 +19,6 @@ final class PhabricatorCalendarEventEditController $user_phid = $user->getPHID(); $error_name = true; $validation_exception = null; - $invitees = null; $start_time = id(new AphrontFormDateControl()) ->setUser($user) @@ -42,9 +41,7 @@ final class PhabricatorCalendarEventEditController $page_title = pht('Create Event'); $redirect = 'created'; $subscribers = array(); - $invitees = array( - $user_phid => PhabricatorCalendarEventInvitee::STATUS_ATTENDING, - ); + $invitees = array($user_phid); } else { $event = id(new PhabricatorCalendarEventQuery()) ->setViewer($user) @@ -68,6 +65,14 @@ final class PhabricatorCalendarEventEditController $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( $event->getPHID()); + $invitees = array(); + foreach ($event->getInvitees() as $invitee) { + if ($invitee->isUninvited()) { + continue; + } else { + $invitees[] = $invitee->getInviteePHID(); + } + } } $errors = array(); @@ -79,6 +84,16 @@ final class PhabricatorCalendarEventEditController $end_value = $end_time->readValueFromRequest($request); $description = $request->getStr('description'); $subscribers = $request->getArr('subscribers'); + $invitees = $request->getArr('invitees'); + $new_invitees = $this->getNewInviteeList($invitees, $event); + + if ($this->isCreate()) { + $status = idx($new_invitees, $user->getPHID()); + $status_attending = PhabricatorCalendarEventInvitee::STATUS_ATTENDING; + if ($status) { + $new_invitees[$user->getPHID()] = $status_attending; + } + } if ($start_time->getError()) { $errors[] = pht('Invalid start time; reset to default.'); @@ -112,19 +127,16 @@ final class PhabricatorCalendarEventEditController PhabricatorTransactions::TYPE_SUBSCRIBERS) ->setNewValue(array('=' => array_fuse($subscribers))); + $xactions[] = id(new PhabricatorCalendarEventTransaction()) + ->setTransactionType( + PhabricatorCalendarEventTransaction::TYPE_INVITE) + ->setNewValue($new_invitees); + $xactions[] = id(new PhabricatorCalendarEventTransaction()) ->setTransactionType( PhabricatorCalendarEventTransaction::TYPE_DESCRIPTION) ->setNewValue($description); - if ($invitees) { - $xactions[] = id(new PhabricatorCalendarEventTransaction()) - ->setTransactionType( - PhabricatorCalendarEventTransaction::TYPE_INVITE) - ->setNewValue($invitees); - } - - $editor = id(new PhabricatorCalendarEventEditor()) ->setActor($user) ->setContentSourceFromRequest($request) @@ -173,6 +185,13 @@ final class PhabricatorCalendarEventEditController ->setUser($user) ->setDatasource(new PhabricatorMetaMTAMailableDatasource()); + $invitees = id(new AphrontFormTokenizerControl()) + ->setLabel(pht('Invitees')) + ->setName('invitees') + ->setValue($invitees) + ->setUser($user) + ->setDatasource(new PhabricatorMetaMTAMailableDatasource()); + $form = id(new AphrontFormView()) ->setUser($user) ->appendChild($name) @@ -180,6 +199,7 @@ final class PhabricatorCalendarEventEditController ->appendChild($start_time) ->appendChild($end_time) ->appendControl($subscribers) + ->appendControl($invitees) ->appendChild($description); $submit = id(new AphrontFormSubmitControl()) @@ -226,4 +246,34 @@ final class PhabricatorCalendarEventEditController )); } + + public function getNewInviteeList(array $phids, $event) { + $invitees = $event->getInvitees(); + $invitees = mpull($invitees, null, 'getInviteePHID'); + $invited_status = PhabricatorCalendarEventInvitee::STATUS_INVITED; + $uninvited_status = PhabricatorCalendarEventInvitee::STATUS_UNINVITED; + $phids = array_fuse($phids); + + $new = array(); + foreach ($phids as $phid) { + $old_invitee = idx($invitees, $phid); + if ($old_invitee) { + $old_status = $old_invitee->getStatus(); + if ($old_status != $uninvited_status) { + continue; + } + } + $new[$phid] = $invited_status; + } + + foreach ($invitees as $invitee) { + $deleted_invitee = !idx($phids, $invitee->getInviteePHID()); + if ($deleted_invitee) { + $new[$invitee->getInviteePHID()] = $uninvited_status; + } + } + + return $new; + } + } diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php b/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php index fa7ef9cc33..e0c82edb5c 100644 --- a/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php @@ -130,9 +130,13 @@ final class PhabricatorCalendarEventViewController $invitees = $event->getInvitees(); $invitee_list = new PHUIStatusListView(); foreach ($invitees as $invitee) { + if ($invitee->isUninvited()) { + continue; + } $item = new PHUIStatusItemView(); $invitee_phid = $invitee->getInviteePHID(); $target = $viewer->renderHandle($invitee_phid); + $item->setNote($invitee->getStatus()); $item->setTarget($target); $invitee_list->addItem($item); } diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php index 81bd5fd59d..42dd48d8fc 100644 --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -31,7 +31,8 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO return id(new PhabricatorCalendarEvent()) ->setUserPHID($actor->getPHID()) - ->setIsCancelled(0); + ->setIsCancelled(0) + ->attachInvitees(array()); } private static $statusTexts = array( diff --git a/src/applications/calendar/storage/PhabricatorCalendarEventInvitee.php b/src/applications/calendar/storage/PhabricatorCalendarEventInvitee.php index 8b7f9a063a..9701a782e7 100644 --- a/src/applications/calendar/storage/PhabricatorCalendarEventInvitee.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEventInvitee.php @@ -38,6 +38,14 @@ final class PhabricatorCalendarEventInvitee extends PhabricatorCalendarDAO ) + parent::getConfiguration(); } + public function isUninvited() { + if ($this->getStatus() == self::STATUS_UNINVITED) { + return true; + } else { + return false; + } + } + /* -( PhabricatorPolicyInterface )----------------------------------------- */