diff --git a/assets/css/translation-events.css b/assets/css/translation-events.css index 3a2f25de..83185108 100644 --- a/assets/css/translation-events.css +++ b/assets/css/translation-events.css @@ -138,10 +138,10 @@ h2.event_page_title { a.event-link-draft { color:#80807f; } -span.event-label-draft, span.event-details-join-expired { +span.event-label-draft, span.event-details-join-expired, span.active-events-before-translation-table { font-weight: 500; - color:#c05621; - border: 1px solid #c05621; + color: var( --gp-color-bubble-inactive-project-text ); + border: 1px solid var( --gp-color-bubble-inactive-project-text ); font-size: .7em; margin-right: 0.3em; width: 6em; @@ -150,6 +150,17 @@ span.event-label-draft, span.event-details-join-expired { border-radius: 1em; text-transform: capitalize; } +span.active-events-before-translation-table a { + color: var( --gp-color-bubble-inactive-project-text ); + text-decoration: none; +} +.active-events-before-translation-table { + width: 100%; + border: 1px solid var( --gp-color-border-default ); + background: var( --gp-color-status-waiting-subtle ); + margin: 1rem 0; + padding: 0.3rem 0.8rem; +} .event-page-wrapper { margin: 0 auto; width: 80%; diff --git a/wporg-gp-translation-events.php b/wporg-gp-translation-events.php index a39e3859..8f1cef3c 100644 --- a/wporg-gp-translation-events.php +++ b/wporg-gp-translation-events.php @@ -23,6 +23,7 @@ use Exception; use GP; use WP_Post; +use WP_Query; /** * Check if a slug is being used by another post type. @@ -404,3 +405,87 @@ function () { $wporg_gp_translation_events_listener->start(); } ); + +/** + * Add the active events for the current user before the translation table. + * + * @return void + */ +function add_active_events_current_user(): void { + $user_attending_events = get_user_meta( get_current_user_id(), Route::USER_META_KEY_ATTENDING, true ) ?: array(); + $current_datetime_utc = ( new DateTime( 'now', new DateTimeZone( 'UTC' ) ) )->format( 'Y-m-d H:i:s' ); + $user_attending_events_args = array( + 'post_type' => 'event', + 'post__in' => array_keys( $user_attending_events ), + 'post_status' => 'publish', + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query + 'meta_query' => array( + array( + 'key' => '_event_start', + 'value' => $current_datetime_utc, + 'compare' => '<=', + 'type' => 'DATETIME', + ), + 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 ); + $number_of_events = $user_attending_events_query->post_count; + if ( 0 === $number_of_events ) { + return; + } + + $content = '