Skip to content

Commit

Permalink
1.54.2
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbi committed Nov 22, 2023
1 parent 8cac57e commit 852779c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [1.54.2] - 2023-11-22

- TMS-974: Fix event formatting if only manual events are shown

## [1.54.1] - 2023-11-22

- TMS-974: Fix fatal error in EventzFormatter
Expand Down
112 changes: 57 additions & 55 deletions lib/Formatters/EventzFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public function format( array $layout ) : array {
$events = $this->get_events( $query_params );

if ( empty( $events ) ) {
$events['events'] = [];
$events = [];
}

// Create recurring events
$event_data['events'] = $events ?? null;
$event_data['events'] = $events ?? [];
if ( ! empty( $event_data['events'] ) ) {
$events = self::create_recurring_events( $event_data );
}
Expand All @@ -70,7 +70,7 @@ public function format( array $layout ) : array {
$manual_events = self::get_manual_events( $layout['manual_event_categories'] );
}

$events = array_merge( $events['events'], $manual_events );
$events = array_merge( $events['events'] ?? [], $manual_events );

if ( empty( $events ) ) {
return $layout;
Expand Down Expand Up @@ -108,60 +108,62 @@ public function format( array $layout ) : array {
public static function create_recurring_events( $events ) {

$recurring_events = [];
foreach ( $events['events'] as $event ) {
if ( count( $event['dates'] ) > 1 ) {
foreach ( $event['dates'] as $date ) {
$clone = $event;

// Split the dates and times into parts
list( $startPart, $endPart ) = explode( ' - ', $date['date'], 2 );
list( $startDate, $startTime ) = explode( ' ', $startPart, 2 );

// Check if endPart includes date & time
if ( strpos($endPart, ' ') ) {
list( $endDate, $endTime ) = explode( ' ', $endPart, 2 );
if( ! empty( $events['events'] ) ) {
foreach ( $events['events'] as $event ) {
if ( count( $event['dates'] ) > 1 ) {
foreach ( $event['dates'] as $date ) {
$clone = $event;

// Split the dates and times into parts
list( $startPart, $endPart ) = explode( ' - ', $date['date'], 2 );
list( $startDate, $startTime ) = explode( ' ', $startPart, 2 );

// Check if endPart includes date & time
if ( strpos($endPart, ' ') ) {
list( $endDate, $endTime ) = explode( ' ', $endPart, 2 );
}
else {
$endTime = $endPart;
}

// Parse the dates
$newStartDate = \DateTime::createFromFormat( 'd.m.Y', $startDate );
$newEndDate = isset( $endDate ) ? \DateTime::createFromFormat( 'd.m.Y', $endDate ) : null;

// Parse the start and end times
$startDateTime = \DateTime::createFromFormat( 'H.i', $startTime );
$startDateTime->setDate( $newStartDate->format( 'Y' ), $newStartDate->format( 'm' ), $newStartDate->format( 'd' ) );
if ( $newEndDate ) {
$endDateTime = \DateTime::createFromFormat( 'H.i', $endTime );
$endDateTime->setDate( $newEndDate->format( 'Y' ), $newEndDate->format( 'm' ), $newEndDate->format( 'd' ) );
}

// Create time & date-ranges
if ( $endTime ) {
$timeRange = $startTime . ' - ' . $endTime;
}
else {
$timeRange = $startTime;
}

if ( $newEndDate ) {
$dateRange = $newStartDate->format( 'd.m.Y' ) . ' - ' . $newEndDate->format( 'd.m.Y' );
}
else {
$dateRange = $newStartDate->format( 'd.m.Y' );
}

$clone['date'] = $dateRange;
$clone['time'] = $timeRange;
$clone['start_date_raw'] = $startDateTime;
$clone['end_date_raw'] = $endDateTime ?? '';
$clone['url'] = $event['url'] . '&date=' . urlencode( $dateRange ) . '&time=' . urlencode( $timeRange );

$recurring_events[] = $clone;
}
else {
$endTime = $endPart;
}

// Parse the dates
$newStartDate = \DateTime::createFromFormat( 'd.m.Y', $startDate );
$newEndDate = isset( $endDate ) ? \DateTime::createFromFormat( 'd.m.Y', $endDate ) : null;

// Parse the start and end times
$startDateTime = \DateTime::createFromFormat( 'H.i', $startTime );
$startDateTime->setDate( $newStartDate->format( 'Y' ), $newStartDate->format( 'm' ), $newStartDate->format( 'd' ) );
if ( $newEndDate ) {
$endDateTime = \DateTime::createFromFormat( 'H.i', $endTime );
$endDateTime->setDate( $newEndDate->format( 'Y' ), $newEndDate->format( 'm' ), $newEndDate->format( 'd' ) );
}

// Create time & date-ranges
if ( $endTime ) {
$timeRange = $startTime . ' - ' . $endTime;
}
else {
$timeRange = $startTime;
}

if ( $newEndDate ) {
$dateRange = $newStartDate->format( 'd.m.Y' ) . ' - ' . $newEndDate->format( 'd.m.Y' );
}
else {
$dateRange = $newStartDate->format( 'd.m.Y' );
}

$clone['date'] = $dateRange;
$clone['time'] = $timeRange;
$clone['start_date_raw'] = $startDateTime;
$clone['end_date_raw'] = $endDateTime ?? '';
$clone['url'] = $event['url'] . '&date=' . urlencode( $dateRange ) . '&time=' . urlencode( $timeRange );

$recurring_events[] = $clone;
} else {
$recurring_events[] = $event;
}
} else {
$recurring_events[] = $event;
}
}

Expand Down

0 comments on commit 852779c

Please sign in to comment.