From 863020c95856c26d04bb3943613ccf0f79e3bb4b Mon Sep 17 00:00:00 2001 From: Moritz Strohm <strohm@data-quest.de> Date: Wed, 13 Nov 2024 11:39:03 +0000 Subject: [PATCH] fixed errors when moving dates, fixes #4723 Closes #4723 Merge request studip/studip!3573 --- app/controllers/calendar/date.php | 48 +++++++++---------- app/views/calendar/date/index.php | 2 +- app/views/calendar/date/move.php | 6 +-- lib/classes/calendar/EventData.php | 12 ++++- .../calendar/CalendarDateAssignment.php | 5 +- 5 files changed, 39 insertions(+), 34 deletions(-) diff --git a/app/controllers/calendar/date.php b/app/controllers/calendar/date.php index a3a80f14673..94385503242 100644 --- a/app/controllers/calendar/date.php +++ b/app/controllers/calendar/date.php @@ -655,7 +655,30 @@ class Calendar_DateController extends AuthenticatedController throw new InvalidArgumentException(); } - if ($this->date->repetition_type !== 'SINGLE') { + //In case the moved event is a repetition event, we must know the original date from where + //it was moved from to correctly move the whole date series: + $original_date = Request::getDateTime('original_date'); + $real_begin = new DateTime(); + $real_begin->setTimestamp($this->date->begin); + if ( + $original_date + && $original_date->format('Ymd') !== $real_begin->format('Ymd') + ) { + //The original date is set. If it differs from the beginning, a repetition date + //of a date series has been moved. In this case, the difference of the beginning + //and the original date has to be calculated and the begin and end fields have + //to be updated. + $original_date->setTime( + $real_begin->format('H'), + $real_begin->format('i'), + $real_begin->format('s') + ); + $diff = $real_begin->diff($original_date); + $this->begin = $this->begin->sub($diff); + $this->end = $this->end->sub($diff); + } + + if ($this->date->repetition_type !== CalendarDate::REPETITION_SINGLE) { PageLayout::setTitle(_('Verschieben eines Termins aus einer Terminserie')); //Show the dialog to decide what shall be done with the repetition. if (Request::submitted('move')) { @@ -696,29 +719,6 @@ class Calendar_DateController extends AuthenticatedController } $this->response->add_header('X-Dialog-Close', '1'); return; - } elseif ($repetition_handling === 'change_times') { - //Set the new time for begin and end: - $date_begin = new DateTime(); - $date_begin->setTimestamp($this->date->begin); - $date_begin->setTime( - intval($this->begin->format('H')), - intval($this->begin->format('i')), - intval($this->begin->format('s')) - ); - $this->date->begin = $date_begin->getTimestamp(); - $date_end = new DateTime(); - $date_end->setTimestamp($this->date->end); - $date_end->setTime( - intval($this->end->format('H')), - intval($this->end->format('i')), - intval($this->end->format('s')) - ); - $this->date->end = $date_end->getTimestamp(); - - //Set the editor-ID: - $this->date->editor_id = $GLOBALS['user']->id; - - $store_old_date = true; } elseif ($repetition_handling === 'change_all') { $this->date->begin = $this->begin->getTimestamp(); if ($this->date->repetition_end && intval($this->date->repetition_end) != pow(2,31) - 1) { diff --git a/app/views/calendar/date/index.php b/app/views/calendar/date/index.php index a10058bd1ee..73ecd68996d 100644 --- a/app/views/calendar/date/index.php +++ b/app/views/calendar/date/index.php @@ -128,7 +128,7 @@ <?= Studip\LinkButton::create( _('Bearbeiten'), $controller->url_for('calendar/date/edit/' . $date->id, array_merge($button_params, ['return_path' => '/calendar/calendar'])), - ['data-dialog' => 'size=auto;reload-on-close'] + ['data-dialog' => 'size=auto'] ) ?> <?= \Studip\LinkButton::create( _('Löschen'), diff --git a/app/views/calendar/date/move.php b/app/views/calendar/date/move.php index 3ea2b89a9ff..f999e65da0f 100644 --- a/app/views/calendar/date/move.php +++ b/app/views/calendar/date/move.php @@ -8,13 +8,9 @@ <input type="radio" name="repetition_handling" value="create_single_date"> <?= _('Der Termin soll aus der Terminserie herausgelöst werden.') ?> </label> - <label> - <input type="radio" name="repetition_handling" value="change_times"> - <?= _('Start- und Enduhrzeit der gesamten Terminserie soll geändert werden.') ?> - </label> <label> <input type="radio" name="repetition_handling" value="change_all"> - <?= _('Die gesamte Terminserie soll verschoben werden und erst am gewählten Datum beginnen.') ?> + <?= _('Die gesamte Terminserie soll verschoben werden.') ?> </label> <div data-dialog-button> <?= \Studip\Button::create(_('Verschieben'), 'move') ?> diff --git a/lib/classes/calendar/EventData.php b/lib/classes/calendar/EventData.php index 95e89b0ec6a..db1e4726494 100644 --- a/lib/classes/calendar/EventData.php +++ b/lib/classes/calendar/EventData.php @@ -25,6 +25,12 @@ class EventData public $border_colour; public $all_day; + /** + * @var string The ID in this field is used to group events when displayed + * in Fullcalendar so that they can be moved together. + */ + public string $group_id; + public function __construct( \DateTime $begin, \DateTime $end, @@ -43,7 +49,8 @@ class EventData Array $api_urls = [], string $icon = '', string $border_colour = '', - bool $all_day = false + bool $all_day = false, + string $group_id = '' ) { $this->begin = $begin; @@ -64,6 +71,7 @@ class EventData $this->icon = $icon; $this->border_colour = $border_colour ?: $background_colour; $this->all_day = $all_day; + $this->group_id = $group_id; } @@ -109,6 +117,6 @@ class EventData 'studip_view_urls' => $this->view_urls, 'studip_api_urls' => $this->api_urls, 'icon' => $this->icon - ]; + ] + ($this->group_id ? ['groupId' => $this->group_id] : []); } } diff --git a/lib/models/calendar/CalendarDateAssignment.php b/lib/models/calendar/CalendarDateAssignment.php index d61d124bf8b..43c00809f4b 100644 --- a/lib/models/calendar/CalendarDateAssignment.php +++ b/lib/models/calendar/CalendarDateAssignment.php @@ -676,11 +676,12 @@ class CalendarDateAssignment extends SimpleORMap implements Event ], [ 'resize_dialog' => URLHelper::getURL('dispatch.php/calendar/date/move/' . $this->calendar_date_id), - 'move_dialog' => URLHelper::getURL('dispatch.php/calendar/date/move/' . $this->calendar_date_id) + 'move_dialog' => URLHelper::getURL('dispatch.php/calendar/date/move/' . $this->calendar_date_id, ['original_date' => $begin->format('Y-m-d')]) ], $this->participation === 'DECLINED' ? 'decline-circle-full' : '', $border_colour, - $all_day + $all_day, + $this->calendar_date_id ); } -- GitLab