Skip to content

Commit

Permalink
RotationConfigForm: MultiDay => Remove to_at time that exceeds a 7-…
Browse files Browse the repository at this point in the history
…day period

This change makes the validator for `to_day` element superfluous.
  • Loading branch information
sukhwinder33445 committed Mar 3, 2025
1 parent d769b4b commit dc4290a
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions application/forms/RotationConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,9 +829,9 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
]);
$from = $options->getElement('from_day');

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

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

Expand All @@ -840,22 +840,7 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
'required' => true,
'options' => $toDays,
'value' => 7,
'label' => $this->translate('To', 'notifications.rotation'),
'validators' => [
new CallbackValidator(function ($value, $validator) use ($options) {
if ($value !== $options->getValue('from_day')) {
return true;
}

if ($options->getValue('from_at') < $options->getValue('to_at')) {
$validator->addMessage($this->translate('Shifts cannot last longer than 7 days'));

return false;
}

return true;
})
]
'label' => $this->translate('To', 'notifications.rotation')
]);
$to = $options->getElement('to_day');

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

$timeOptions = $this->getTimeOptions();
$fromAt = $options->createElement('select', 'from_at', [
'class' => 'autosubmit',
'required' => true,
'options' => $this->getTimeOptions()
'options' => $timeOptions
]);
$options->registerElement($fromAt);

if ($selectedFromDay === (int) $to->getValue()) {
$selectedFromAt = $fromAt->getValue();
$keyIndex = array_search($selectedFromAt, array_keys($timeOptions));
$timeOptions = array_slice($timeOptions, 0, $keyIndex + 1, true);
}

$toAt = $options->createElement('select', 'to_at', [
'class' => 'autosubmit',
'required' => true,
'options' => $this->getTimeOptions()
'options' => $timeOptions
]);
$options->registerElement($toAt);

Expand Down

0 comments on commit dc4290a

Please sign in to comment.