Skip to content

Add missing option for end of day (Multiday) #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
38 changes: 32 additions & 6 deletions application/forms/RotationConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class RotationConfigForm extends CompatForm
*/
public const EXPERIMENTAL_OVERRIDES = false;

protected const DAY_END = 'dayEnd';

/** @var ?int The ID of the affected schedule */
protected $scheduleId;

Expand Down Expand Up @@ -895,14 +897,15 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
$toDays[$i] = sprintf('%s (%s)', $day, $this->translate('Next week'));
}

$options->addElement('select', 'to_day', [
$options->addElement('select', 'to_day_ignored', [
'class' => 'autosubmit',
'required' => true,
'ignore' => true,
'options' => $toDays,
'value' => 7,
'value' => $options->getPopulatedValue('to_day', 7),
'label' => $this->translate('To', 'notifications.rotation')
]);
$to = $options->getElement('to_day');
$to = $options->getElement('to_day_ignored');

$options->addElement('number', 'interval', [
'required' => true,
Expand All @@ -920,19 +923,42 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
]);
$options->registerElement($fromAt);

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

$toAt = $options->createElement('select', 'to_at', [
$toAt = $options->createElement('select', 'to_at_ignored', [
'class' => 'autosubmit',
'required' => true,
'options' => $timeOptions
'ignore' => true,
'options' => $timeOptions,
'value' => $options->getPopulatedValue('to_at'),
]);
$options->registerElement($toAt);

$selectedToAt = $toAt->getValue();

if ($selectedToAt === self::DAY_END) {
++$selectedToDay;
$selectedToAt = $timeOptionsFirstKey;
}

$options->clearPopulatedValue('to_day');
$options->clearPopulatedValue('to_at');

$options->addElement('hidden', 'to_day', ['value' => $selectedToDay]);
$options->addElement('hidden', 'to_at', ['value' => $selectedToAt]);

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