diff --git a/CHANGELOG.MD b/CHANGELOG.MD index e3ac59b7..1dc6fb6a 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +- TMS-1089: Fix event fetching for events-component + +## [1.59.3] - 2024-11-25 + - TMS-1059: Eventz changes: - Add "Sign up"- & "Purchase tickets"-links - Add translation to homepage link diff --git a/lib/Eventz.php b/lib/Eventz.php index cd9334d1..84a26739 100644 --- a/lib/Eventz.php +++ b/lib/Eventz.php @@ -115,11 +115,11 @@ public static function normalize_event( $event ) : array { foreach ( $event->links as $event_link ) { // Assign links to their own variables if ( $event_link->name === 'PurchaseTicket' ) { - $event_link->name = \__( 'Purchase tickets', 'tms-theme-base' ); + $event_link->name = \__( 'Purchase tickets', 'tms-theme-base' ); $event_link_purchase_ticket = $event_link; } else if ( $event_link->name === 'SignUp' ) { - $event_link->name = \__( 'Sign up', 'tms-theme-base' ); + $event_link->name = \__( 'Sign up', 'tms-theme-base' ); $event_link_sign_up = $event_link; } else { @@ -140,16 +140,16 @@ public static function normalize_event( $event ) : array { } return [ - 'name' => $event->name ?? null, - 'short_description' => nl2br( $event->descriptionShort ) ?? null, - 'description' => nl2br( $event->description ) ?? null, - 'date_title' => __( 'Dates', 'tms-theme-base' ), - 'date' => static::get_event_date( $event ), - 'dates' => static::get_event_dates( $event ), - 'entries' => static::get_event_entries( $event ), - 'recurring' => $is_recurring, - 'time_title' => __( 'Time', 'tms-theme-base' ), - 'time' => static::get_event_time( $event ), + 'name' => $event->name ?? null, + 'short_description' => nl2br( $event->descriptionShort ) ?? null, + 'description' => nl2br( $event->description ) ?? null, + 'date_title' => __( 'Dates', 'tms-theme-base' ), + 'date' => static::get_event_date( $event ), + 'dates' => static::get_event_dates( $event ), + 'entries' => static::get_event_entries( $event ), + 'recurring' => $is_recurring, + 'time_title' => __( 'Time', 'tms-theme-base' ), + 'time' => static::get_event_time( $event ), // Include raw dates for possible sorting. 'start_date_raw' => static::get_as_datetime( $event->event->start ), 'end_date_raw' => static::get_as_datetime( $event->event->end ), diff --git a/lib/Formatters/EventzFormatter.php b/lib/Formatters/EventzFormatter.php index 59a834b6..f21ec3e4 100644 --- a/lib/Formatters/EventzFormatter.php +++ b/lib/Formatters/EventzFormatter.php @@ -87,11 +87,11 @@ public function format( array $layout ) : array { $layout['events'] = $this->format_events( $events, $layout['show_images'] ); $layout['classes'] = [ - 'event_item_bg' => apply_filters( 'tms/theme/layout_events/item_bg_class', 'has-background-secondary' ), - 'event_item_text' => apply_filters( 'tms/theme/layout_events/item_text_class', '' ), - 'event_item_icon' => apply_filters( 'tms/theme/layout_events/item_icon_class', '' ), - 'all_events_link' => apply_filters( 'tms/theme/layout_events/all_events_link', 'is-size-7' ), - 'event_item_pill' => apply_filters( 'tms/theme/layout_events/event_item', 'is-primary-invert' ), + 'event_item_bg' => \apply_filters( 'tms/theme/layout_events/item_bg_class', 'has-background-secondary' ), + 'event_item_text' => \apply_filters( 'tms/theme/layout_events/item_text_class', '' ), + 'event_item_icon' => \apply_filters( 'tms/theme/layout_events/item_icon_class', '' ), + 'all_events_link' => \apply_filters( 'tms/theme/layout_events/all_events_link', 'is-size-7' ), + 'event_item_pill' => \apply_filters( 'tms/theme/layout_events/event_item', 'is-primary-invert' ), ]; return $layout; @@ -106,10 +106,10 @@ public function format( array $layout ) : array { * * @return void */ - public static function create_recurring_events( $events, $query_params ) { + public static function create_recurring_events( $events, $query_params ) { $recurring_events = []; - if( ! empty( $events['events'] ) ) { + if ( ! empty( $events['events'] ) ) { foreach ( $events['events'] as $event ) { $recurring_event_dates = []; @@ -143,7 +143,7 @@ public static function create_recurring_events( $events, $query_params ) { } // Check if endPart includes date & time - if ( strpos($endPart, ' ') ) { + if ( strpos( $endPart, ' ' ) ) { list( $endDate, $endTime ) = explode( ' ', $endPart, 2 ); } else { @@ -185,7 +185,8 @@ public static function create_recurring_events( $events, $query_params ) { $recurring_events[] = $clone; } - } else { + } + else { $recurring_events[] = $event; } } @@ -248,7 +249,6 @@ public function format_query_params( array $layout ) : array { 'sort' => null, 'size' => null, 'skip' => null, - 'page_size' => null, ]; foreach ( $layout as $key => $value ) { @@ -287,13 +287,12 @@ public function format_query_params( array $layout ) : array { * * @return array|null */ - private function get_events( array $query_params ) : ?array { + private function get_events( array $query_params ): ?array { // Force sort param $query_params['sort'] = 'startDate'; - if ( ! empty( $query_params['page_size'] ) ) { - $query_params['size'] = $query_params['page_size']; - } + // Get enough events to show correct events if they're recurring + $query_params['size'] = 30; $client = new EventzClient( PIRKANMAA_EVENTZ_API_URL, PIRKANMAA_EVENTZ_API_KEY ); diff --git a/models/page-events-calendar.php b/models/page-events-calendar.php index 3059d180..7251ab96 100644 --- a/models/page-events-calendar.php +++ b/models/page-events-calendar.php @@ -26,7 +26,7 @@ class PageEventsCalendar extends PageEventsSearch { /** * Description text */ - public function description() : ?string { + public function description(): ?string { return get_field( 'description' ); } @@ -35,7 +35,7 @@ public function description() : ?string { * * @return string */ - public function no_results() : string { + public function no_results(): string { return __( 'No results', 'tms-theme-base' ); } @@ -44,7 +44,7 @@ public function no_results() : string { * * @return bool */ - public function is_grid() : bool { + public function is_grid(): bool { $is_grid = get_field( 'layout' ) ?? 'grid'; return $is_grid === 'grid'; @@ -55,7 +55,7 @@ public function is_grid() : bool { * * @return string */ - public function item_partial() : string { + public function item_partial(): string { $part = $this->is_grid() ? 'grid' : 'list'; return 'views/page-events-calendar/page-events-calendar-item-' . $part; @@ -64,7 +64,7 @@ public function item_partial() : string { /** * Get events */ - public function events() : ?array { + public function events(): ?array { try { $response = $this->get_events(); @@ -82,28 +82,28 @@ public function events() : ?array { * * @return array */ - protected function get_events() : array { + protected function get_events(): array { - $paged = get_query_var( 'paged', 1 ); + $paged = \get_query_var( 'paged', 1 ); $skip = 0; if ( $paged > 1 ) { - $skip = ( $paged - 1 ) * get_option( 'posts_per_page' ); + $skip = ( $paged - 1 ) * \get_option( 'posts_per_page' ); } $params = [ - 'q' => get_field( 'text' ), - 'start' => get_field( 'start' ), - 'end' => get_field( 'end' ), - 'category_id' => get_field( 'category' ), - 'areas' => get_field( 'area' ), - 'targets' => get_field( 'target' ), - 'tags' => get_field( 'tag' ), + 'q' => \get_field( 'text' ), + 'start' => \get_field( 'start' ), + 'end' => \get_field( 'end' ), + 'category_id' => \get_field( 'category' ), + 'areas' => \get_field( 'area' ), + 'targets' => \get_field( 'target' ), + 'tags' => \get_field( 'tag' ), 'sort' => 'startDate', - 'show_images' => get_field( 'show_images' ), + 'show_images' => \get_field( 'show_images' ), ]; - if ( ! empty( get_field( 'starts_today' ) ) && true === get_field( 'starts_today' ) ) { + if ( ! empty( \get_field( 'starts_today' ) ) && true === \get_field( 'starts_today' ) ) { $params['start'] = date( 'Y-m-d' ); } @@ -116,15 +116,15 @@ protected function get_events() : array { $params = $formatter->format_query_params( $params ); $cache_group = 'page-events-calendar'; - $cache_key = md5( wp_json_encode( $params ) ); - $response = wp_cache_get( $cache_key, $cache_group ); + $cache_key = md5( \wp_json_encode( $params ) ); + $response = \wp_cache_get( $cache_key, $cache_group ); if ( empty( $response ) ) { $response = $this->do_get_events( $params ); if ( ! empty( $response ) ) { - wp_cache_set( + \wp_cache_set( $cache_key, $response, $cache_group, @@ -136,7 +136,7 @@ protected function get_events() : array { if ( ! empty( $response['events'] ) ) { // Sort events. - usort( $response['events'], function( $a, $b ) { + usort( $response['events'], function ( $a, $b ) { return $a['start_date_raw'] <=> $b['start_date_raw']; } ); @@ -153,7 +153,7 @@ protected function get_events() : array { * * @return array|null */ - public function calendar_pages() : ?array { + public function calendar_pages(): ?array { if ( ! Settings::get_setting( 'show_related_events_calendars' ) ) { return null; } @@ -171,7 +171,7 @@ public function calendar_pages() : ?array { return null; } - $current_page = get_queried_object_id(); + $current_page = \get_queried_object_id(); $pages = array_filter( $the_query->posts, function ( $item ) use ( $current_page ) { return $item->ID !== $current_page; @@ -179,7 +179,7 @@ public function calendar_pages() : ?array { return array_map( function ( $item ) { return [ - 'url' => get_the_permalink( $item->ID ), + 'url' => \get_the_permalink( $item->ID ), 'title' => $item->post_title, ]; }, $pages ); diff --git a/partials/views/single-dynamic-event/single-dynamic-event-info.dust b/partials/views/single-dynamic-event/single-dynamic-event-info.dust index 753aa958..0662948e 100644 --- a/partials/views/single-dynamic-event/single-dynamic-event-info.dust +++ b/partials/views/single-dynamic-event/single-dynamic-event-info.dust @@ -72,7 +72,7 @@ {>"views/single-dynamic-event/single-dynamic-event-group-title" title=event.normalized.sign_up_title template_classes=template_classes.info_group_title icon="link" /}