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 @@

Events I'm Attending

- have_posts() ) : ?> +

You don't have any events to attend.

+ + + $user_attending_events_query->max_num_pages, + 'current' => max( 1, $user_attending_events_query->query_vars['user_attending_events_paged'] ), + 'format' => '?user_attending_events_paged=%#%', + 'prev_text' => '« Previous', + 'next_text' => 'Next »', + ) + ) ?? '' + ); + + wp_reset_postdata(); + endif; ?> -
diff --git a/wporg-gp-translation-events.php b/wporg-gp-translation-events.php index e086d8ab..950a5d3e 100644 --- a/wporg-gp-translation-events.php +++ b/wporg-gp-translation-events.php @@ -345,8 +345,8 @@ function () { GP::$router->add( '/events?', array( 'WPORG_GP_Translation_Events_Route', 'events_list' ) ); GP::$router->add( '/events/new', array( 'WPORG_GP_Translation_Events_Route', 'events_create' ) ); GP::$router->add( '/events/edit/(\d+)', array( 'WPORG_GP_Translation_Events_Route', 'events_edit' ) ); - GP::$router->add( '/events/attend/(\d+)', array( 'WPORG_GP_Translation_Events_Route', 'events_attend' ) ); - GP::$router->add( '/events/my-events', array( 'WPORG_GP_Translation_Events_Route', 'events_user_created' ), 'get' ); + GP::$router->add( '/events/attend/(\d+)', array( 'WPORG_GP_Translation_Events_Route', 'events_attend' ), 'post' ); + GP::$router->add( '/events/my-events', array( 'WPORG_GP_Translation_Events_Route', 'events_user_created' ) ); GP::$router->add( '/events/([a-z0-9_-]+)', array( 'WPORG_GP_Translation_Events_Route', 'events_details' ) ); require_once __DIR__ . '/includes/class-wporg-gp-translation-events-event.php';