Skip to content

Commit eb9a4d2

Browse files
authored
Merge pull request #525 from devgeniem/TMS-1089
TMS-1089: Fix event fetching for events-component
2 parents 468d399 + 1ef0380 commit eb9a4d2

File tree

3 files changed

+39
-38
lines changed

3 files changed

+39
-38
lines changed

CHANGELOG.MD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
- TMS-1089: Fix event fetching for events-component
11+
1012
## [1.59.3] - 2024-11-25
1113

1214
- TMS-1059: Eventz changes:

lib/Formatters/EventzFormatter.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ public function format( array $layout ) : array {
8787

8888
$layout['events'] = $this->format_events( $events, $layout['show_images'] );
8989
$layout['classes'] = [
90-
'event_item_bg' => apply_filters( 'tms/theme/layout_events/item_bg_class', 'has-background-secondary' ),
91-
'event_item_text' => apply_filters( 'tms/theme/layout_events/item_text_class', '' ),
92-
'event_item_icon' => apply_filters( 'tms/theme/layout_events/item_icon_class', '' ),
93-
'all_events_link' => apply_filters( 'tms/theme/layout_events/all_events_link', 'is-size-7' ),
94-
'event_item_pill' => apply_filters( 'tms/theme/layout_events/event_item', 'is-primary-invert' ),
90+
'event_item_bg' => \apply_filters( 'tms/theme/layout_events/item_bg_class', 'has-background-secondary' ),
91+
'event_item_text' => \apply_filters( 'tms/theme/layout_events/item_text_class', '' ),
92+
'event_item_icon' => \apply_filters( 'tms/theme/layout_events/item_icon_class', '' ),
93+
'all_events_link' => \apply_filters( 'tms/theme/layout_events/all_events_link', 'is-size-7' ),
94+
'event_item_pill' => \apply_filters( 'tms/theme/layout_events/event_item', 'is-primary-invert' ),
9595
];
9696

9797
return $layout;
@@ -106,10 +106,10 @@ public function format( array $layout ) : array {
106106
*
107107
* @return void
108108
*/
109-
public static function create_recurring_events( $events, $query_params ) {
109+
public static function create_recurring_events( $events, $query_params ) {
110110

111111
$recurring_events = [];
112-
if( ! empty( $events['events'] ) ) {
112+
if ( ! empty( $events['events'] ) ) {
113113
foreach ( $events['events'] as $event ) {
114114
$recurring_event_dates = [];
115115

@@ -143,7 +143,7 @@ public static function create_recurring_events( $events, $query_params ) {
143143
}
144144

145145
// Check if endPart includes date & time
146-
if ( strpos($endPart, ' ') ) {
146+
if ( strpos( $endPart, ' ' ) ) {
147147
list( $endDate, $endTime ) = explode( ' ', $endPart, 2 );
148148
}
149149
else {
@@ -185,7 +185,8 @@ public static function create_recurring_events( $events, $query_params ) {
185185

186186
$recurring_events[] = $clone;
187187
}
188-
} else {
188+
}
189+
else {
189190
$recurring_events[] = $event;
190191
}
191192
}
@@ -248,7 +249,6 @@ public function format_query_params( array $layout ) : array {
248249
'sort' => null,
249250
'size' => null,
250251
'skip' => null,
251-
'page_size' => null,
252252
];
253253

254254
foreach ( $layout as $key => $value ) {
@@ -287,13 +287,12 @@ public function format_query_params( array $layout ) : array {
287287
*
288288
* @return array|null
289289
*/
290-
private function get_events( array $query_params ) : ?array {
290+
private function get_events( array $query_params ): ?array {
291291
// Force sort param
292292
$query_params['sort'] = 'startDate';
293293

294-
if ( ! empty( $query_params['page_size'] ) ) {
295-
$query_params['size'] = $query_params['page_size'];
296-
}
294+
// Get enough events to show correct events if they're recurring
295+
$query_params['size'] = 30;
297296

298297
$client = new EventzClient( PIRKANMAA_EVENTZ_API_URL, PIRKANMAA_EVENTZ_API_KEY );
299298

models/page-events-calendar.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PageEventsCalendar extends PageEventsSearch {
2626
/**
2727
* Description text
2828
*/
29-
public function description() : ?string {
29+
public function description(): ?string {
3030
return get_field( 'description' );
3131
}
3232

@@ -35,7 +35,7 @@ public function description() : ?string {
3535
*
3636
* @return string
3737
*/
38-
public function no_results() : string {
38+
public function no_results(): string {
3939
return __( 'No results', 'tms-theme-base' );
4040
}
4141

@@ -44,7 +44,7 @@ public function no_results() : string {
4444
*
4545
* @return bool
4646
*/
47-
public function is_grid() : bool {
47+
public function is_grid(): bool {
4848
$is_grid = get_field( 'layout' ) ?? 'grid';
4949

5050
return $is_grid === 'grid';
@@ -55,7 +55,7 @@ public function is_grid() : bool {
5555
*
5656
* @return string
5757
*/
58-
public function item_partial() : string {
58+
public function item_partial(): string {
5959
$part = $this->is_grid() ? 'grid' : 'list';
6060

6161
return 'views/page-events-calendar/page-events-calendar-item-' . $part;
@@ -64,7 +64,7 @@ public function item_partial() : string {
6464
/**
6565
* Get events
6666
*/
67-
public function events() : ?array {
67+
public function events(): ?array {
6868
try {
6969
$response = $this->get_events();
7070

@@ -82,28 +82,28 @@ public function events() : ?array {
8282
*
8383
* @return array
8484
*/
85-
protected function get_events() : array {
85+
protected function get_events(): array {
8686

87-
$paged = get_query_var( 'paged', 1 );
87+
$paged = \get_query_var( 'paged', 1 );
8888
$skip = 0;
8989

9090
if ( $paged > 1 ) {
91-
$skip = ( $paged - 1 ) * get_option( 'posts_per_page' );
91+
$skip = ( $paged - 1 ) * \get_option( 'posts_per_page' );
9292
}
9393

9494
$params = [
95-
'q' => get_field( 'text' ),
96-
'start' => get_field( 'start' ),
97-
'end' => get_field( 'end' ),
98-
'category_id' => get_field( 'category' ),
99-
'areas' => get_field( 'area' ),
100-
'targets' => get_field( 'target' ),
101-
'tags' => get_field( 'tag' ),
95+
'q' => \get_field( 'text' ),
96+
'start' => \get_field( 'start' ),
97+
'end' => \get_field( 'end' ),
98+
'category_id' => \get_field( 'category' ),
99+
'areas' => \get_field( 'area' ),
100+
'targets' => \get_field( 'target' ),
101+
'tags' => \get_field( 'tag' ),
102102
'sort' => 'startDate',
103-
'show_images' => get_field( 'show_images' ),
103+
'show_images' => \get_field( 'show_images' ),
104104
];
105105

106-
if ( ! empty( get_field( 'starts_today' ) ) && true === get_field( 'starts_today' ) ) {
106+
if ( ! empty( \get_field( 'starts_today' ) ) && true === \get_field( 'starts_today' ) ) {
107107
$params['start'] = date( 'Y-m-d' );
108108
}
109109

@@ -116,15 +116,15 @@ protected function get_events() : array {
116116
$params = $formatter->format_query_params( $params );
117117

118118
$cache_group = 'page-events-calendar';
119-
$cache_key = md5( wp_json_encode( $params ) );
120-
$response = wp_cache_get( $cache_key, $cache_group );
119+
$cache_key = md5( \wp_json_encode( $params ) );
120+
$response = \wp_cache_get( $cache_key, $cache_group );
121121

122122
if ( empty( $response ) ) {
123123

124124
$response = $this->do_get_events( $params );
125125

126126
if ( ! empty( $response ) ) {
127-
wp_cache_set(
127+
\wp_cache_set(
128128
$cache_key,
129129
$response,
130130
$cache_group,
@@ -136,7 +136,7 @@ protected function get_events() : array {
136136
if ( ! empty( $response['events'] ) ) {
137137

138138
// Sort events.
139-
usort( $response['events'], function( $a, $b ) {
139+
usort( $response['events'], function ( $a, $b ) {
140140
return $a['start_date_raw'] <=> $b['start_date_raw'];
141141
} );
142142

@@ -153,7 +153,7 @@ protected function get_events() : array {
153153
*
154154
* @return array|null
155155
*/
156-
public function calendar_pages() : ?array {
156+
public function calendar_pages(): ?array {
157157
if ( ! Settings::get_setting( 'show_related_events_calendars' ) ) {
158158
return null;
159159
}
@@ -171,15 +171,15 @@ public function calendar_pages() : ?array {
171171
return null;
172172
}
173173

174-
$current_page = get_queried_object_id();
174+
$current_page = \get_queried_object_id();
175175

176176
$pages = array_filter( $the_query->posts, function ( $item ) use ( $current_page ) {
177177
return $item->ID !== $current_page;
178178
} );
179179

180180
return array_map( function ( $item ) {
181181
return [
182-
'url' => get_the_permalink( $item->ID ),
182+
'url' => \get_the_permalink( $item->ID ),
183183
'title' => $item->post_title,
184184
];
185185
}, $pages );

0 commit comments

Comments
 (0)