Skip to content

Commit dc4290a

Browse files
RotationConfigForm: MultiDay => Remove to_at time that exceeds a 7-day period
This change makes the validator for `to_day` element superfluous.
1 parent d769b4b commit dc4290a

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

application/forms/RotationConfigForm.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -829,9 +829,9 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
829829
]);
830830
$from = $options->getElement('from_day');
831831

832-
$selectedDay = (int) $from->getValue();
832+
$selectedFromDay = (int) $from->getValue();
833833

834-
for ($i = 1; $i <= $selectedDay; $i++) {
834+
for ($i = 1; $i <= $selectedFromDay; $i++) {
835835
$toDays[$i] = sprintf('%s (%s)', $toDays[$i], $this->translate('Next week'));
836836
}
837837

@@ -840,22 +840,7 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
840840
'required' => true,
841841
'options' => $toDays,
842842
'value' => 7,
843-
'label' => $this->translate('To', 'notifications.rotation'),
844-
'validators' => [
845-
new CallbackValidator(function ($value, $validator) use ($options) {
846-
if ($value !== $options->getValue('from_day')) {
847-
return true;
848-
}
849-
850-
if ($options->getValue('from_at') < $options->getValue('to_at')) {
851-
$validator->addMessage($this->translate('Shifts cannot last longer than 7 days'));
852-
853-
return false;
854-
}
855-
856-
return true;
857-
})
858-
]
843+
'label' => $this->translate('To', 'notifications.rotation')
859844
]);
860845
$to = $options->getElement('to_day');
861846

@@ -867,17 +852,24 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
867852
'label' => $this->translate('Handoff every')
868853
]);
869854

855+
$timeOptions = $this->getTimeOptions();
870856
$fromAt = $options->createElement('select', 'from_at', [
871857
'class' => 'autosubmit',
872858
'required' => true,
873-
'options' => $this->getTimeOptions()
859+
'options' => $timeOptions
874860
]);
875861
$options->registerElement($fromAt);
876862

863+
if ($selectedFromDay === (int) $to->getValue()) {
864+
$selectedFromAt = $fromAt->getValue();
865+
$keyIndex = array_search($selectedFromAt, array_keys($timeOptions));
866+
$timeOptions = array_slice($timeOptions, 0, $keyIndex + 1, true);
867+
}
868+
877869
$toAt = $options->createElement('select', 'to_at', [
878870
'class' => 'autosubmit',
879871
'required' => true,
880-
'options' => $this->getTimeOptions()
872+
'options' => $timeOptions
881873
]);
882874
$options->registerElement($toAt);
883875

0 commit comments

Comments
 (0)