Skip to content
Snippets Groups Projects
Commit 7657df71 authored by Moritz Strohm's avatar Moritz Strohm Committed by Jan-Hendrik Willms
Browse files

calendar/date/delete: added fieldset to decide what to do with dates that are...

calendar/date/delete: added fieldset to decide what to do with dates that are in multiple calendars, fixes #3882

Closes #3882

Merge request studip/studip!2739
parent daf2bba0
No related branches found
No related tags found
No related merge requests found
...@@ -783,7 +783,10 @@ class Calendar_DateController extends AuthenticatedController ...@@ -783,7 +783,10 @@ class Calendar_DateController extends AuthenticatedController
$this->selected_date->setTimestamp($this->date->begin); $this->selected_date->setTimestamp($this->date->begin);
} }
} }
$this->date_is_in_multiple_calendars = count($this->date->calendars) > 1;
$this->repetition_handling = Request::get('repetition_handling', 'create_exception'); $this->repetition_handling = Request::get('repetition_handling', 'create_exception');
$this->multiple_calendar_handling = Request::get('multiple_calendar_handling', 'delete_from_mine');
if (Request::submitted('delete')) { if (Request::submitted('delete')) {
$delete_whole_date = false; $delete_whole_date = false;
CSRFProtection::verifyUnsafeRequest(); CSRFProtection::verifyUnsafeRequest();
...@@ -801,6 +804,7 @@ class Calendar_DateController extends AuthenticatedController ...@@ -801,6 +804,7 @@ class Calendar_DateController extends AuthenticatedController
); );
$this->response->add_header('X-Dialog-Close', '1'); $this->response->add_header('X-Dialog-Close', '1');
$this->render_nothing(); $this->render_nothing();
return;
} else { } else {
PageLayout::postError( PageLayout::postError(
sprintf( sprintf(
...@@ -809,11 +813,11 @@ class Calendar_DateController extends AuthenticatedController ...@@ -809,11 +813,11 @@ class Calendar_DateController extends AuthenticatedController
) )
); );
} }
} elseif ($this->repetition_handling === 'delete_all') { } elseif ($this->repetition_handling === 'delete_all' && $this->multiple_calendar_handling === 'delete_all') {
$delete_whole_date = true; $delete_whole_date = true;
} }
} else { } else {
$delete_whole_date = true; $delete_whole_date = $this->multiple_calendar_handling === 'delete_all';
} }
if ($delete_whole_date) { if ($delete_whole_date) {
if ($this->date->delete()) { if ($this->date->delete()) {
...@@ -831,6 +835,21 @@ class Calendar_DateController extends AuthenticatedController ...@@ -831,6 +835,21 @@ class Calendar_DateController extends AuthenticatedController
PageLayout::postError(_('Der Termin konnte nicht gelöscht werden!')); PageLayout::postError(_('Der Termin konnte nicht gelöscht werden!'));
} }
} }
} elseif ($this->multiple_calendar_handling === 'delete_from_mine') {
$result = CalendarDateAssignment::deleteBySQL(
'`calendar_date_id` = :calendar_date_id AND `range_id` = :current_user_id',
[
'calendar_date_id' => $this->date->id,
'current_user_id' => User::findCurrent()->id
]
);
if ($result) {
PageLayout::postSuccess(_('Der Termin wurde aus Ihrem Kalender gelöscht.'));
$this->response->add_header('X-Dialog-Close', '1');
$this->render_nothing();
} else {
PageLayout::postError(_('Der Termin konnte nicht aus Ihrem Kalender gelöscht werden!'));
}
} }
} }
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<legend><?= _('Es handelt sich um einen Termin in einer Terminserie. Was möchten Sie tun?') ?></legend> <legend><?= _('Es handelt sich um einen Termin in einer Terminserie. Was möchten Sie tun?') ?></legend>
<label> <label>
<input type="radio" name="repetition_handling" value="create_exception" <input type="radio" name="repetition_handling" value="create_exception"
data-hides="#calendar_delete_date_form_delete_question"
<?= $repetition_handling === 'create_exception' ? 'checked' : '' ?>> <?= $repetition_handling === 'create_exception' ? 'checked' : '' ?>>
<?= sprintf( <?= sprintf(
_('Am %s soll aus dem Einzeltermin eine Ausnahme der Terminserie werden.'), _('Am %s soll aus dem Einzeltermin eine Ausnahme der Terminserie werden.'),
...@@ -15,11 +16,28 @@ ...@@ -15,11 +16,28 @@
</label> </label>
<label> <label>
<input type="radio" name="repetition_handling" value="delete_all" <input type="radio" name="repetition_handling" value="delete_all"
data-shows="#calendar_delete_date_form_delete_question"
<?= $repetition_handling === 'delete_all' ? 'checked' : '' ?>> <?= $repetition_handling === 'delete_all' ? 'checked' : '' ?>>
<?= _('Die gesamte Terminserie soll gelöscht werden.') ?> <?= _('Die gesamte Terminserie soll gelöscht werden.') ?>
</label> </label>
</fieldset> </fieldset>
<? else : ?> <? endif ?>
<? if ($date_is_in_multiple_calendars) : ?>
<fieldset id="calendar_delete_date_form_delete_question" <?= $date_has_repetitions ? 'style="display: none"' : '' ?>>
<legend><?= _('Der Termin ist in mehreren Kalendern eingetragen. Was möchten Sie tun?') ?></legend>
<label>
<input type="radio" name="multiple_calendar_handling" value="delete_from_mine"
<?= $multiple_calendar_handling === 'delete_from_mine' ? 'checked' : '' ?>>
<?= _('Den Termin nur aus meinem Kalender löschen.') ?>
</label>
<label>
<input type="radio" name="multiple_calendar_handling" value="delete_all"
<?= $multiple_calendar_handling === 'delete_all' ? 'checked' : '' ?>>
<?= _('Den Termin aus allen Kalendern löschen.') ?>
</label>
</fieldset>
<? endif ?>
<? if (!$date_has_repetitions && !$date_is_in_multiple_calendars) : ?>
<?= MessageBox::warning(_('Soll der folgende Termin wirklich gelöscht werden?')) ?> <?= MessageBox::warning(_('Soll der folgende Termin wirklich gelöscht werden?')) ?>
<? endif ?> <? endif ?>
<fieldset> <fieldset>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment