Skip to content

Commit

Permalink
fix: the start time and end time of the "repeat exceptions" are displ…
Browse files Browse the repository at this point in the history
…ayed correctly in the frontend

fixes #15
  • Loading branch information
cgoIT committed Jul 11, 2024
1 parent 67f77ae commit 99574aa
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Classes/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static function appendToArrayKey(&$arr, mixed $key, mixed $val): void
* If the input array has more than 4 dates, it will only include the first 4 dates and append the count of other dates.
* Otherwise, it will implode all the dates with a comma separator and append the last date with an "and" label.
*
* @param array|null $arrFixedDates Array of fixed dates
* @param array<mixed>|null $arrFixedDates Array of fixed dates
*
* @return string The imploded string of fixed dates
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Module/ModuleFullCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ protected function compile(): void
$objTemplate->firstDay = $this->cal_startDay;

if (!empty($this->businessHours)) {
$arrDays = array_map('\intval', StringUtil::deserialize($this->businessDays, true));
$arrDays = array_map(\intval(...), StringUtil::deserialize($this->businessDays, true));

$businessHours = new \stdClass();
$businessHours->daysOfWeek = $arrDays;
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Module/ModuleTimeTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected function compile(): void

// Find the boundaries
$blnShowUnpublished = System::getContainer()->get('contao.security.token_checker')->isPreviewMode();
$objMinMax = $this->Database->query('SELECT MIN(startTime) AS dateFrom, MAX(endTime) AS dateTo, MAX(repeatEnd) AS repeatUntil FROM tl_calendar_events WHERE pid IN('.implode(',', array_map('\intval', $this->cal_calendar)).')'.(!$blnShowUnpublished ? " AND published='1' AND (start='' OR start<=$time) AND (stop='' OR stop>$time)" : ''));
$objMinMax = $this->Database->query('SELECT MIN(startTime) AS dateFrom, MAX(endTime) AS dateTo, MAX(repeatEnd) AS repeatUntil FROM tl_calendar_events WHERE pid IN('.implode(',', array_map(\intval(...), $this->cal_calendar)).')'.(!$blnShowUnpublished ? " AND published='1' AND (start='' OR start<=$time) AND (stop='' OR stop>$time)" : ''));
$dateFrom = $objMinMax->dateFrom;
$dateTo = $objMinMax->dateTo;
$repeatUntil = $objMinMax->repeatUntil;
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Module/ModuleYearView.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected function compile(): void

// Find the boundaries
$blnShowUnpublished = System::getContainer()->get('contao.security.token_checker')->isPreviewMode();
$objMinMax = $this->Database->query('SELECT MIN(startTime) AS dateFrom, MAX(endTime) AS dateTo, MAX(repeatEnd) AS repeatUntil FROM tl_calendar_events WHERE pid IN('.implode(',', array_map('\intval', $this->cal_calendar)).')'.(!$blnShowUnpublished ? " AND published='1' AND (start='' OR start<=$time) AND (stop='' OR stop>$time)" : ''));
$objMinMax = $this->Database->query('SELECT MIN(startTime) AS dateFrom, MAX(endTime) AS dateTo, MAX(repeatEnd) AS repeatUntil FROM tl_calendar_events WHERE pid IN('.implode(',', array_map(\intval(...), $this->cal_calendar)).')'.(!$blnShowUnpublished ? " AND published='1' AND (start='' OR start<=$time) AND (stop='' OR stop>$time)" : ''));
$dateFrom = $objMinMax->dateFrom;
$dateTo = $objMinMax->dateTo;
$repeatUntil = $objMinMax->repeatUntil;
Expand Down
2 changes: 2 additions & 0 deletions src/EventListener/DataContainer/CalendarEventsCallbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ private function checkExceptionsByDate(Result|\stdClass $activeRecord, int $curr

/**
* Get the recurrence array.
*
* @return array<mixed>
*/
private function getRecurrenceArray(int|false $start, int|false $end, string|null $moveReason = null): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@

class CalendarEventsMCWCallbacks extends Backend
{
/**
* __construct().
*
* Constructor for the class.
*
* @param Connection $db The database connection object
* @param int $exceptionsMoveDays The number of days to move exceptions
* @param array<mixed> $exceptionsMoveTimes The array of exception move times
*/
public function __construct(
private readonly Connection $db,
private readonly int $exceptionsMoveDays,
Expand Down
8 changes: 4 additions & 4 deletions src/EventListener/DataContainer/ModuleCallbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function __construct(
}

/**
* @return array
* @return array<mixed>
*/
#[AsCallback(table: 'tl_module', target: 'fields.filter_fields.options')]
public function getEventField()
public function getEventField(): array
{
// Load tl_calendar_events data
$this->loadDataContainer('tl_calendar_events');
Expand Down Expand Up @@ -69,9 +69,9 @@ public function getEventField()
}

/**
* @return array|null
* @return array<mixed>|null
*/
public function getTimeRange()
public function getTimeRange(): array|null
{
return [
'time_from' => [
Expand Down
26 changes: 21 additions & 5 deletions src/Hook/GetAllEventsHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ class GetAllEventsHook
private int|false $intTodayEnd = false;

/**
* @param array<mixed> $arrEvents
* @param array<mixed> $arrCalendars
*
* @return array<mixed>
*
* @throws \Exception
*/
public function __invoke(array $arrEvents, array $arrCalendars, int $timeStart, int $timeEnd, Events $objModule): array
{
Expand Down Expand Up @@ -146,9 +151,17 @@ private function handleExtendedRecurrences(array $arrEvents, array $arrCalendars
}

/**
* @param array<mixed> $arrEvents
* Handle fixed dates with recurrences.
*
* @return array<mixed>
* @param array<mixed> $arrEvents Array of events
* @param array<int> $arrCalendars Array of calendar IDs
* @param int $timeStart Start time
* @param int $timeEnd End time
* @param Events $objModule Events module object
*
* @return array<mixed> Array of events with fixed dates recurrences
*
* @throws \Exception
*/
private function handleFixedDatesRecurrences(array $arrEvents, array $arrCalendars, int $timeStart, int $timeEnd, Events $objModule): array
{
Expand All @@ -173,13 +186,16 @@ private function handleFixedDatesRecurrences(array $arrEvents, array $arrCalenda
if (!empty($arrFixedDates) && \is_array($arrFixedDates)) {
foreach ($arrFixedDates as $date) {
$intStart = $date['new_repeat'];
$intEnd = $intStart;
if (!empty($date['new_start']) && $objEvent->addTime) {
$objEvent->startTime = strtotime(Date::parse($objPage->dateFormat, $intStart).' '.$date['new_start']);
$objEvent->startTime = strtotime(Date::parse($objPage->dateFormat, $date['new_repeat']).' '.date('H:i', $date['new_start']));
$intStart = $objEvent->startTime;
$intEnd = $intStart;
}
if (!empty($date['new_end']) && $objEvent->addTime) {
$objEvent->startTime = strtotime(Date::parse($objPage->dateFormat, $intStart).' '.$date['new_end']);
$objEvent->endTime = strtotime(Date::parse($objPage->dateFormat, $date['new_repeat']).' '.date('H:i', $date['new_end']));
$intEnd = $objEvent->endTime;
}
$intEnd = $intStart;

if ($intStart >= $timeStart && $intStart <= $timeEnd) {
$key = Date::parse('Ymd', $intStart);
Expand Down
14 changes: 8 additions & 6 deletions src/Hook/ParseFrontendTemplateHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private function processEventTemplate(CalendarEventsModel $objEvent, FrontendTem

// Replace the date an time with the correct ones from the recurring event
if (Input::get('times')) {
[$intStartTime, $intEndTime] = array_map('\intval', explode(',', Input::get('times')));
[$intStartTime, $intEndTime] = array_map(\intval(...), explode(',', Input::get('times')));
} else {
// Do not show dates in the past if the event is recurring (see #923)
if (!empty($objEvent->allRecurrences)) {
Expand Down Expand Up @@ -260,13 +260,15 @@ private function processEventTemplate(CalendarEventsModel $objEvent, FrontendTem
}

/**
* Return the date and time strings.
* Get the date and time based on the provided parameters.
*
* @param int $intStartTime
* @param int $intEndTime
* @param int $span
* @param CalendarEventsModel $objEvent the event model
* @param PageModel $objPage the page model
* @param int $intStartTime the start time
* @param int $intEndTime the end time
* @param int $span the span value
*
* @return array
* @return array<mixed> the array containing the date and time
*/
private function getDateAndTime(CalendarEventsModel $objEvent, PageModel $objPage, $intStartTime, $intEndTime, $span)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Migration/RenameFieldsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

class RenameFieldsMigration extends AbstractMigration
{
/**
* @var array<mixed>
*/
private static array $arrColumns = [
'show_holiday' => 'hide_holiday',
'cellhight' => 'cellheight',
Expand Down
2 changes: 1 addition & 1 deletion src/Models/CalendarEventsModelExt.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function findUpcomingByPids($arrIds, $intLimit = 0, array $arrOpti
$time = Date::floorToMinute();

// Get upcoming events using endTime instead of startTime (see #3917)
$arrColumns = ["$t.pid IN(".implode(',', array_map('\intval', $arrIds)).") AND $t.published=1 AND ($t.start='' OR $t.start<=$time) AND ($t.stop='' OR $t.stop>$time) AND ($t.endTime>=$time OR (($t.recurringExt=1 OR $t.recurring=1) AND ($t.recurrences=0 OR $t.repeatEnd>=$time)))"];
$arrColumns = ["$t.pid IN(".implode(',', array_map(\intval(...), $arrIds)).") AND $t.published=1 AND ($t.start='' OR $t.start<=$time) AND ($t.stop='' OR $t.stop>$time) AND ($t.endTime>=$time OR (($t.recurringExt=1 OR $t.recurring=1) AND ($t.recurrences=0 OR $t.repeatEnd>=$time)))"];

if ($intLimit > 0) {
$arrOptions['limit'] = $intLimit;
Expand Down

0 comments on commit 99574aa

Please sign in to comment.