diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2036,6 +2036,7 @@ 'PhabricatorCalendarEventEndDateTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php', 'PhabricatorCalendarEventFrequencyTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventFrequencyTransaction.php', 'PhabricatorCalendarEventFulltextEngine' => 'applications/calendar/search/PhabricatorCalendarEventFulltextEngine.php', + 'PhabricatorCalendarEventHostTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventHostTransaction.php', 'PhabricatorCalendarEventIconTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventIconTransaction.php', 'PhabricatorCalendarEventInviteTransaction' => 'applications/calendar/xaction/PhabricatorCalendarEventInviteTransaction.php', 'PhabricatorCalendarEventInvitee' => 'applications/calendar/storage/PhabricatorCalendarEventInvitee.php', @@ -6663,6 +6664,7 @@ 'PhabricatorCalendarEventEndDateTransaction' => 'PhabricatorCalendarEventDateTransaction', 'PhabricatorCalendarEventFrequencyTransaction' => 'PhabricatorCalendarEventTransactionType', 'PhabricatorCalendarEventFulltextEngine' => 'PhabricatorFulltextEngine', + 'PhabricatorCalendarEventHostTransaction' => 'PhabricatorCalendarEventTransactionType', 'PhabricatorCalendarEventIconTransaction' => 'PhabricatorCalendarEventTransactionType', 'PhabricatorCalendarEventInviteTransaction' => 'PhabricatorCalendarEventTransactionType', 'PhabricatorCalendarEventInvitee' => array( diff --git a/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php b/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php --- a/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php +++ b/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php @@ -23,8 +23,7 @@ protected function newEditableObject() { return PhabricatorCalendarEvent::initializeNewCalendarEvent( - $this->getViewer(), - $mode = null); + $this->getViewer()); } protected function newObjectQuery() { @@ -106,6 +105,17 @@ ->setConduitDescription(pht('Cancel or restore the event.')) ->setConduitTypeDescription(pht('True to cancel the event.')) ->setValue($object->getIsCancelled()), + id(new PhabricatorUsersEditField()) + ->setKey('hostPHID') + ->setAliases(array('host')) + ->setLabel(pht('Host')) + ->setDescription(pht('Host of the event.')) + ->setTransactionType( + PhabricatorCalendarEventHostTransaction::TRANSACTIONTYPE) + ->setIsConduitOnly($this->getIsCreate()) + ->setConduitDescription(pht('Change the host of the event.')) + ->setConduitTypeDescription(pht('New event host.')) + ->setSingleValue($object->getHostPHID()), id(new PhabricatorDatasourceEditField()) ->setKey('inviteePHIDs') ->setAliases(array('invite', 'invitee', 'invitees', 'inviteePHID')) @@ -141,7 +151,7 @@ ->setDescription(pht('Recurring event frequency.')) ->setConduitDescription(pht('Change the event frequency.')) ->setConduitTypeDescription(pht('New event frequency.')) - ->setValue($object->getFrequencyUnit()); + ->setValue($object->getFrequencyRule()); } if ($this->getIsCreate() || $object->getIsRecurring()) { diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -39,8 +39,6 @@ protected $spacePHID; - const DEFAULT_ICON = 'fa-calendar'; - private $parentEvent = self::ATTACHABLE; private $invitees = self::ATTACHABLE; @@ -53,24 +51,13 @@ const FREQUENCY_MONTHLY = 'monthly'; const FREQUENCY_YEARLY = 'yearly'; - public static function initializeNewCalendarEvent( - PhabricatorUser $actor, - $mode) { + public static function initializeNewCalendarEvent(PhabricatorUser $actor) { $app = id(new PhabricatorApplicationQuery()) ->setViewer($actor) ->withClasses(array('PhabricatorCalendarApplication')) ->executeOne(); - $view_policy = null; - $is_recurring = 0; - - if ($mode == 'public') { - $view_policy = PhabricatorPolicies::getMostOpenPolicy(); - } - - if ($mode == 'recurring') { - $is_recurring = true; - } + $view_policy = PhabricatorPolicies::getMostOpenPolicy(); $start = new DateTime('@'.PhabricatorTime::getNow()); $start->setTimeZone($actor->getTimeZone()); @@ -82,13 +69,19 @@ $epoch_min = $start->format('U'); $epoch_max = $end->format('U'); + $default_icon = 'fa-calendar'; + return id(new PhabricatorCalendarEvent()) ->setHostPHID($actor->getPHID()) ->setIsCancelled(0) ->setIsAllDay(0) ->setIsStub(0) - ->setIsRecurring($is_recurring) - ->setIcon(self::DEFAULT_ICON) + ->setIsRecurring(0) + ->setRecurrenceFrequency( + array( + 'rule' => self::FREQUENCY_WEEKLY, + )) + ->setIcon($default_icon) ->setViewPolicy($view_policy) ->setEditPolicy($actor->getPHID()) ->setSpacePHID($actor->getDefaultSpacePHID()) @@ -396,8 +389,12 @@ return $this; } + public function getFrequencyRule() { + return idx($this->recurrenceFrequency, 'rule'); + } + public function getFrequencyUnit() { - $frequency = idx($this->recurrenceFrequency, 'rule'); + $frequency = $this->getFrequencyRule(); switch ($frequency) { case 'daily': diff --git a/src/applications/calendar/xaction/PhabricatorCalendarEventFrequencyTransaction.php b/src/applications/calendar/xaction/PhabricatorCalendarEventFrequencyTransaction.php --- a/src/applications/calendar/xaction/PhabricatorCalendarEventFrequencyTransaction.php +++ b/src/applications/calendar/xaction/PhabricatorCalendarEventFrequencyTransaction.php @@ -6,7 +6,7 @@ const TRANSACTIONTYPE = 'calendar.frequency'; public function generateOldValue($object) { - return $object->getFrequencyUnit(); + return $object->getFrequencyRule(); } public function applyInternalEffects($object, $value) { @@ -17,7 +17,7 @@ } public function getTitle() { - $frequency = $this->getFrequencyUnit($this->getNewValue()); + $frequency = $this->getFrequencyRule($this->getNewValue()); switch ($frequency) { case PhabricatorCalendarEvent::FREQUENCY_DAILY: return pht( @@ -39,7 +39,7 @@ } public function getTitleForFeed() { - $frequency = $this->getFrequencyUnit($this->getNewValue()); + $frequency = $this->getFrequencyRule($this->getNewValue()); switch ($frequency) { case PhabricatorCalendarEvent::FREQUENCY_DAILY: return pht( @@ -64,7 +64,7 @@ } } - private function getFrequencyUnit($value) { + private function getFrequencyRule($value) { if (is_array($value)) { $value = idx($value, 'rule'); } else { diff --git a/src/applications/calendar/xaction/PhabricatorCalendarEventHostTransaction.php b/src/applications/calendar/xaction/PhabricatorCalendarEventHostTransaction.php new file mode 100644 --- /dev/null +++ b/src/applications/calendar/xaction/PhabricatorCalendarEventHostTransaction.php @@ -0,0 +1,59 @@ +getHostPHID(); + } + + public function applyInternalEffects($object, $value) { + $object->setHostPHID($value); + } + + public function getTitle() { + return pht( + '%s changed the host of this event from %s to %s.', + $this->renderAuthor(), + $this->renderOldHandle(), + $this->renderNewHandle()); + } + + public function getTitleForFeed() { + return pht( + '%s changed the host of %s from %s to %s.', + $this->renderAuthor(), + $this->renderObject(), + $this->renderOldHandle(), + $this->renderNewHandle()); + } + + public function validateTransactions($object, array $xactions) { + $errors = array(); + + foreach ($xactions as $xaction) { + $host_phid = $xaction->getNewValue(); + if (!$host_phid) { + $errors[] = $this->newRequiredError( + pht('Event host is required.')); + continue; + } + + $user = id(new PhabricatorPeopleQuery()) + ->setViewer($this->getActor()) + ->withPHIDs(array($host_phid)) + ->executeOne(); + if (!$user) { + $errors[] = $this->newInvalidError( + pht( + 'Host PHID "%s" is not a valid user PHID.', + $host_phid)); + } + } + + return $errors; + } + +} diff --git a/src/applications/transactions/storage/PhabricatorModularTransactionType.php b/src/applications/transactions/storage/PhabricatorModularTransactionType.php --- a/src/applications/transactions/storage/PhabricatorModularTransactionType.php +++ b/src/applications/transactions/storage/PhabricatorModularTransactionType.php @@ -148,6 +148,14 @@ return $display; } + final protected function renderOldHandle() { + return $this->renderHandle($this->getOldValue()); + } + + final protected function renderNewHandle() { + return $this->renderHandle($this->getNewValue()); + } + final protected function renderHandleList(array $phids) { $viewer = $this->getViewer(); $display = $viewer->renderHandleList($phids)