Skip to content

Commit 8b851a8

Browse files
sukhwinder33445nilmerg
authored andcommitted
RotationConfigForm: Add end of day time option to multi day mode
1 parent 42f7c74 commit 8b851a8

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

application/forms/RotationConfigForm.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -919,11 +919,28 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
919919
'options' => $timeOptions
920920
]);
921921
$options->registerElement($fromAt);
922+
$selectedFromAt = $fromAt->getValue();
923+
924+
// Small optimization only, out-of-range options are only required under certain conditions
925+
$removeOutOfRangeToAtOptions = function () use ($selectedFromAt, $timeOptions) {
926+
return array_slice(
927+
$timeOptions,
928+
0,
929+
array_search($selectedFromAt, array_keys($timeOptions), true) + 1,
930+
true
931+
);
932+
};
922933

923-
if ($selectedFromDay === (int) $to->getValue()) {
924-
$selectedFromAt = $fromAt->getValue();
925-
$keyIndex = array_search($selectedFromAt, array_keys($timeOptions));
926-
$timeOptions = array_slice($timeOptions, 0, $keyIndex + 1, true);
934+
$timeOptionsFirstKey = array_key_first($timeOptions);
935+
$selectedToDay = (int) $to->getValue();
936+
$endOfDay = 'endOfDay';
937+
if ($selectedFromDay === $selectedToDay) {
938+
$timeOptions = $removeOutOfRangeToAtOptions();
939+
} else {
940+
$timeOptions[$endOfDay] = sprintf(
941+
$this->translate('%s (End of day)'),
942+
$timeOptions[$timeOptionsFirstKey]
943+
);
927944
}
928945

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

953+
if ($toAt->getValue() === $endOfDay) {
954+
$selectedToDay = $selectedToDay === 7 ? 1 : $selectedToDay + 1;
955+
956+
if ($selectedFromDay === $selectedToDay) {
957+
$toAt->setOptions($removeOutOfRangeToAtOptions());
958+
}
959+
960+
$to->setValue($selectedToDay);
961+
$toAt->setValue($timeOptionsFirstKey);
962+
}
963+
936964
$from->prependWrapper(
937965
(new HtmlDocument())->addHtml(
938966
$from,

0 commit comments

Comments
 (0)