From c0c05274b062c179cc38c5fe48df71d06ef1355e Mon Sep 17 00:00:00 2001 From: cgoIT Date: Sat, 12 Oct 2024 15:10:58 +0200 Subject: [PATCH] fix: refactor code for clarity and add condition for weekday Restructure assignments for better code readability. Add condition to check if weekday is set before processing repeat exceptions, ensuring more robust handling of calendar event logic. --- .../DataContainer/CalendarEventsCallbacks.php | 6 +++++- .../DataContainer/CalendarEventsMCWCallbacks.php | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/EventListener/DataContainer/CalendarEventsCallbacks.php b/src/EventListener/DataContainer/CalendarEventsCallbacks.php index 5d8bdff..fd58464 100644 --- a/src/EventListener/DataContainer/CalendarEventsCallbacks.php +++ b/src/EventListener/DataContainer/CalendarEventsCallbacks.php @@ -29,6 +29,7 @@ use Contao\System; use Doctrine\DBAL\Connection; use Symfony\Component\HttpFoundation\RequestStack; +use function PHPUnit\Framework\isEmpty; class CalendarEventsCallbacks extends Backend { @@ -543,7 +544,7 @@ private function processExceptions(Result|\stdClass $activeRecord, int $currentE */ private function checkExceptionsByInterval(Result|\stdClass $activeRecord, array $exceptionRows, int $intStart, int $intRepeatEnd): array { - if ($activeRecord->repeatExceptionsInt) { + if ($activeRecord->repeatExceptionsInt && $activeRecord->weekday) { // weekday $unit = $this->arrDays[$activeRecord->weekday]; @@ -565,7 +566,10 @@ private function checkExceptionsByInterval(Result|\stdClass $activeRecord, array $year = (int) date('Y', $searchNext); while ($searchNext <= $searchEnd) { + System::loadLanguageFile('default', 'en', true); $strDateToFind = $arg.' '.$unit.' of '.$GLOBALS['TL_LANG']['MONTHS'][$month - 1].' '.$year; + System::loadLanguageFile('default'); + $strDateToFind = strtotime($strDateToFind); $searchNext = strtotime(date('Y-m-d', $strDateToFind).' '.date('H:i', $intStart)); diff --git a/src/EventListener/DataContainer/CalendarEventsMCWCallbacks.php b/src/EventListener/DataContainer/CalendarEventsMCWCallbacks.php index 40af9e5..8c2b5c1 100644 --- a/src/EventListener/DataContainer/CalendarEventsMCWCallbacks.php +++ b/src/EventListener/DataContainer/CalendarEventsMCWCallbacks.php @@ -80,11 +80,11 @@ public function listMultiExceptions(MultiColumnWizard $mcw): array $arrSource1[$k] = $date; } } - - // fill array for option action - $arrSource2['move'] = $GLOBALS['TL_LANG']['tl_calendar_events']['move']; - $arrSource2['hide'] = $GLOBALS['TL_LANG']['tl_calendar_events']['hide']; } + + // fill array for option action + $arrSource2['move'] = $GLOBALS['TL_LANG']['tl_calendar_events']['move']; + $arrSource2['hide'] = $GLOBALS['TL_LANG']['tl_calendar_events']['hide']; } // fill array for option new date