From 85c0489b8b81f8d6d7c89e90824a7f802e228eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Amieiro=20Becerra?= <1667814+amieiro@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:46:45 +0100 Subject: [PATCH] Add the list of events the user is attending (#87) * Remove the default method in a route and add the post method to the attend route * Add the list of events the user is attending --- assets/css/translation-events.css | 4 ++ ...lass-wporg-gp-translation-events-route.php | 36 ++++++++++++- templates/events-list.php | 50 ++++++++++++++----- wporg-gp-translation-events.php | 4 +- 4 files changed, 77 insertions(+), 17 deletions(-) diff --git a/assets/css/translation-events.css b/assets/css/translation-events.css index 34e99ded..80683a83 100644 --- a/assets/css/translation-events.css +++ b/assets/css/translation-events.css @@ -69,6 +69,10 @@ span.event-list-date { font-size: .9em; font-weight: bold; } +span.event-list-date.events-i-am-attending { + font-size: .8em; + font-weight: normal; +} .event-list-item a{ font-weight: bold; font-size: 1.2em; diff --git a/includes/class-wporg-gp-translation-events-route.php b/includes/class-wporg-gp-translation-events-route.php index aeb7ecc2..7b5d3fb2 100644 --- a/includes/class-wporg-gp-translation-events-route.php +++ b/includes/class-wporg-gp-translation-events-route.php @@ -33,8 +33,9 @@ public function events_list() { $this->die_with_error( 'Something is wrong.' ); } - $_current_events_paged = 1; - $_upcoming_events_paged = 1; + $_current_events_paged = 1; + $_upcoming_events_paged = 1; + $_user_attending_events_paged = 1; // phpcs:disable WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['current_events_paged'] ) ) { @@ -49,6 +50,12 @@ public function events_list() { $_upcoming_events_paged = (int) $value; } } + if ( isset( $_GET['user_attending_events_paged'] ) ) { + $value = sanitize_text_field( wp_unslash( $_GET['user_attending_events_paged'] ) ); + if ( is_numeric( $value ) ) { + $_user_attending_events_paged = (int) $value; + } + } // phpcs:enable $current_events_args = array( @@ -96,6 +103,30 @@ public function events_list() { 'order' => 'ASC', ); $upcoming_events_query = new WP_Query( $upcoming_events_args ); + + $user_attending_events = get_user_meta( get_current_user_id(), self::USER_META_KEY_ATTENDING, true ) ?: array(); + $user_attending_events_args = array( + 'post_type' => 'event', + 'post__in' => array_keys( $user_attending_events ), + 'posts_per_page' => 10, + 'user_attending_events_paged' => $_user_attending_events_paged, + 'paged' => $_user_attending_events_paged, + 'post_status' => 'publish', + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query + 'meta_query' => array( + array( + 'key' => '_event_end', + 'value' => $current_datetime_utc, + 'compare' => '>', + 'type' => 'DATETIME', + ), + ), + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key + 'meta_key' => '_event_start', + 'orderby' => 'meta_value', + 'order' => 'ASC', + ); + $user_attending_events_query = new WP_Query( $user_attending_events_args ); $this->tmpl( 'events-list', get_defined_vars() ); } @@ -223,6 +254,7 @@ public function events_attend( int $event_id ) { } $event = get_post( $event_id ); + if ( ! $event ) { $this->die_with_404(); } diff --git a/templates/events-list.php b/templates/events-list.php index dfd06f12..7164b40c 100644 --- a/templates/events-list.php +++ b/templates/events-list.php @@ -92,19 +92,43 @@
You don't have any events to attend.
+ +