Skip to content

Commit

Permalink
Merge branch 'TMS-940' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbi committed Nov 27, 2023
2 parents d0e70fc + 57b5dc5 commit 8aa4c34
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 62 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Search-page form accessibility fixes
- Header search accessibility fixes
- Added focus on input when opening header search
- TMS-940: Hide current language on mobile header if only 2 languages in use

## [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

## [1.54.0] - 2023-11-21

Expand Down
110 changes: 56 additions & 54 deletions lib/Formatters/EventzFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function format( array $layout ) : array {
}

// 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
16 changes: 13 additions & 3 deletions models/shared/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,18 @@ public function language_nav() : ?array {
'hide_empty' => 0,
];

$languages = pll_the_languages( $args );
$languages = \pll_the_languages( $args );
$lang_data = [ 'all' => $languages ];

// If there are two languages, show only one in mobile view
if ( count( $languages ) === 2 ) {
$args['hide_current'] = 1;
$without_current = \pll_the_languages( $args );
$lang_data_mobile = [
'all' => $without_current,
];
}

foreach ( $languages as $lang ) {
if ( ! empty( $lang['current_lang'] ) ) {
$lang_data['current'] = $lang;
Expand All @@ -99,10 +108,11 @@ public function language_nav() : ?array {
}

return [
'partial' => 'dropdown' === $lang_nav_display
'partial' => 'dropdown' === $lang_nav_display
? 'ui/menu/language-nav-dropdown'
: 'ui/menu/language-nav',
'links' => $lang_data,
'links' => $lang_data,
'links_without_current' => $lang_data_mobile,
];
}

Expand Down
14 changes: 10 additions & 4 deletions partials/shared/header-inner.dust
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
{/Header.lang_nav_horizontal}

{?Header.lang_nav_horizontal}
<div class="is-hidden-desktop">
<div class="is-hidden-desktop">
{?Header.language_nav.links_without_current}
{>"ui/menu/language-nav" links=Header.language_nav.links_without_current /}
{:else}
{>"ui/menu/language-nav-dropdown" links=Header.language_nav.links /}
{/Header.language_nav.links_without_current}
</div>
{/Header.lang_nav_horizontal}
{>"ui/menu/language-nav-dropdown" links=Header.language_nav.links /}
{?Header.lang_nav_horizontal}
</div>

{^Header.lang_nav_horizontal}
{>"ui/menu/language-nav-dropdown" links=Header.language_nav.links /}
{/Header.lang_nav_horizontal}

{^Header.hide_search}
Expand Down
2 changes: 1 addition & 1 deletion partials/ui/menu/menu-item-simple.dust
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<a href="{url}" class="navbar-item {#classes}{.}{@sep} {/sep}{/classes}" {?classes.is_current}aria-page="current"{/classes.is_current}>
<a href="{url}" class="navbar-item {#classes}{.}{@sep} {/sep}{/classes}" {?classes.is_current}aria-current="page"{/classes.is_current}>
{title|s}

{?icon}
Expand Down

0 comments on commit 8aa4c34

Please sign in to comment.