diff --git a/src/applications/calendar/editor/PhabricatorCalendarEditEngine.php b/src/applications/calendar/editor/PhabricatorCalendarEditEngine.php --- a/src/applications/calendar/editor/PhabricatorCalendarEditEngine.php +++ b/src/applications/calendar/editor/PhabricatorCalendarEditEngine.php @@ -68,6 +68,13 @@ $invitee_phids = $object->getInviteePHIDsForEdit(); } + $frequency_options = array( + PhabricatorCalendarEvent::FREQUENCY_DAILY => pht('Daily'), + PhabricatorCalendarEvent::FREQUENCY_WEEKLY => pht('Weekly'), + PhabricatorCalendarEvent::FREQUENCY_MONTHLY => pht('Monthly'), + PhabricatorCalendarEvent::FREQUENCY_YEARLY => pht('Yearly'), + ); + $fields = array( id(new PhabricatorTextEditField()) ->setKey('name') @@ -109,7 +116,76 @@ ->setConduitTypeDescription(pht('New event invitees.')) ->setValue($invitee_phids) ->setCommentActionLabel(pht('Change Invitees')), - id(new PhabricatorIconSetEditField()) + ); + + if ($this->getIsCreate()) { + $fields[] = id(new PhabricatorBoolEditField()) + ->setKey('isRecurring') + ->setLabel(pht('Recurring')) + ->setOptions(pht('One-Time Event'), pht('Recurring Event')) + ->setTransactionType( + PhabricatorCalendarEventTransaction::TYPE_RECURRING) + ->setDescription(pht('One time or recurring event.')) + ->setConduitDescription(pht('Make the event recurring.')) + ->setConduitTypeDescription(pht('Mark the event as a recurring event.')) + ->setValue($object->getIsRecurring()); + + $fields[] = id(new PhabricatorSelectEditField()) + ->setKey('frequency') + ->setLabel(pht('Frequency')) + ->setOptions($frequency_options) + ->setTransactionType( + PhabricatorCalendarEventTransaction::TYPE_FREQUENCY) + ->setDescription(pht('Recurring event frequency.')) + ->setConduitDescription(pht('Change the event frequency.')) + ->setConduitTypeDescription(pht('New event frequency.')) + ->setValue($object->getFrequencyUnit()); + } + + if ($this->getIsCreate() || $object->getIsRecurring()) { + $fields[] = id(new PhabricatorEpochEditField()) + ->setAllowNull(true) + ->setKey('until') + ->setLabel(pht('Repeat Until')) + ->setTransactionType( + PhabricatorCalendarEventTransaction::TYPE_RECURRENCE_END_DATE) + ->setDescription(pht('Last instance of the event.')) + ->setConduitDescription(pht('Change when the event repeats until.')) + ->setConduitTypeDescription(pht('New final event time.')) + ->setValue($object->getRecurrenceEndDate()); + } + + $fields[] = id(new PhabricatorBoolEditField()) + ->setKey('isAllDay') + ->setLabel(pht('All Day')) + ->setOptions(pht('Normal Event'), pht('All Day Event')) + ->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_ALL_DAY) + ->setDescription(pht('Marks this as an all day event.')) + ->setConduitDescription(pht('Make the event an all day event.')) + ->setConduitTypeDescription(pht('Mark the event as an all day event.')) + ->setValue($object->getIsAllDay()); + + $fields[] = id(new PhabricatorEpochEditField()) + ->setKey('start') + ->setLabel(pht('Start')) + ->setTransactionType( + PhabricatorCalendarEventTransaction::TYPE_START_DATE) + ->setDescription(pht('Start time of the event.')) + ->setConduitDescription(pht('Change the start time of the event.')) + ->setConduitTypeDescription(pht('New event start time.')) + ->setValue($object->getViewerDateFrom()); + + $fields[] = id(new PhabricatorEpochEditField()) + ->setKey('end') + ->setLabel(pht('End')) + ->setTransactionType( + PhabricatorCalendarEventTransaction::TYPE_END_DATE) + ->setDescription(pht('End time of the event.')) + ->setConduitDescription(pht('Change the end time of the event.')) + ->setConduitTypeDescription(pht('New event end time.')) + ->setValue($object->getViewerDateTo()); + + $fields[] = id(new PhabricatorIconSetEditField()) ->setKey('icon') ->setLabel(pht('Icon')) ->setIconSet(new PhabricatorCalendarIconSet()) @@ -117,8 +193,7 @@ ->setDescription(pht('Event icon.')) ->setConduitDescription(pht('Change the event icon.')) ->setConduitTypeDescription(pht('New event icon.')) - ->setValue($object->getIcon()), - ); + ->setValue($object->getIcon()); return $fields; } 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 @@ -70,6 +70,16 @@ $is_recurring = true; } + $start = new DateTime('@'.PhabricatorTime::getNow()); + $start->setTimeZone($actor->getTimeZone()); + + $start->setTime($start->format('H'), 0, 0); + $start->modify('+1 hour'); + $end = id(clone $start)->modify('+1 hour'); + + $epoch_min = $start->format('U'); + $epoch_max = $end->format('U'); + return id(new PhabricatorCalendarEvent()) ->setUserPHID($actor->getPHID()) ->setIsCancelled(0) @@ -81,6 +91,8 @@ ->setEditPolicy($actor->getPHID()) ->setSpacePHID($actor->getDefaultSpacePHID()) ->attachInvitees(array()) + ->setDateFrom($epoch_min) + ->setDateTo($epoch_max) ->applyViewerTimezone($actor); } diff --git a/src/applications/transactions/editfield/PhabricatorEpochEditField.php b/src/applications/transactions/editfield/PhabricatorEpochEditField.php --- a/src/applications/transactions/editfield/PhabricatorEpochEditField.php +++ b/src/applications/transactions/editfield/PhabricatorEpochEditField.php @@ -3,8 +3,20 @@ final class PhabricatorEpochEditField extends PhabricatorEditField { + private $allowNull; + + public function setAllowNull($allow_null) { + $this->allowNull = $allow_null; + return $this; + } + + public function getAllowNull() { + return $this->allowNull; + } + protected function newControl() { return id(new AphrontFormDateControl()) + ->setAllowNull($this->getAllowNull()) ->setViewer($this->getViewer()); }