Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions application/forms/RotationConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -919,11 +919,28 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
'options' => $timeOptions
]);
$options->registerElement($fromAt);
$selectedFromAt = $fromAt->getValue();

$removeOutOfRangeToAtOptions = function () use ($selectedFromAt, $timeOptions) {
return array_slice(
$timeOptions,
0,
array_search($selectedFromAt, array_keys($timeOptions), true) + 1,
true
);
};

if ($selectedFromDay === (int) $to->getValue()) {
$selectedFromAt = $fromAt->getValue();
$keyIndex = array_search($selectedFromAt, array_keys($timeOptions));
$timeOptions = array_slice($timeOptions, 0, $keyIndex + 1, true);
$timeOptionsFirstKey = array_key_first($timeOptions);
$selectedToDay = (int) $to->getValue();
$endOfDay = 'endOfDay';
if ($selectedFromDay === $selectedToDay) {
$timeOptions = $removeOutOfRangeToAtOptions();
} else {
$timeOptions[$endOfDay] = sprintf(
'%s (%s)',
$timeOptions[$timeOptionsFirstKey],
$this->translate('End of day')
);
}

$toAt = $options->createElement('select', 'to_at', [
Expand All @@ -933,6 +950,17 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
]);
$options->registerElement($toAt);

if ($toAt->getValue() === $endOfDay) {
$selectedToDay = $selectedToDay === 7 ? 1 : $selectedToDay + 1;

if ($selectedFromDay === $selectedToDay) {
$toAt->setOptions($removeOutOfRangeToAtOptions());
}

$to->setValue($selectedToDay);
$toAt->setValue($timeOptionsFirstKey);
}

$from->prependWrapper(
(new HtmlDocument())->addHtml(
$from,
Expand Down
Loading