Skip to content

Commit

Permalink
fix: refactor code for clarity and add condition for weekday
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cgoIT committed Oct 12, 2024
1 parent c232c45 commit c0c0527
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/EventListener/DataContainer/CalendarEventsCallbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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];

Expand All @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c0c0527

Please sign in to comment.