Changeset 13298
- Timestamp:
- 03/07/2024 06:39:00 AM (11 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events
- Files:
-
- 10 added
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/assets/css/translation-events.css
r13268 r13298 50 50 table-layout: fixed; 51 51 } 52 .event-details-stats table th, .event-details-stats table td {52 .event-details-stats table th, .event-details-stats table td { 53 53 padding: 1em; 54 54 text-align: center; 55 } 56 .event-details-stats table td:first-child { 57 text-align: left; 55 58 } 56 59 .event-details-stats table tr { … … 60 63 background-color: #e9e9e9; 61 64 } 62 .event-details-stats-totals { 63 font-weight: bold; 65 .event-details-stats-totals td { 66 font-weight: bold; 67 } 68 .event-contributors li { 69 display: inline-block; 70 list-style-type: none; 71 margin-right: 1em; 72 margin-bottom: .5em; 73 width: 15em; 74 } 75 .event-contributors li .avatar { 76 border-radius: 50%; 77 vertical-align: middle; 64 78 } 65 79 .hide-event-url { … … 218 232 font-size: .9em; 219 233 border-top: thin solid #e0e0e0; 220 font-family: monospace;221 234 } 222 235 time.event-utc-time { -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/stats-calculator.php
r13279 r13298 5 5 use Exception; 6 6 use WP_Post; 7 use WP_User; 8 use GP_Locale; 9 use GP_Locales; 7 10 8 11 class Stats_Row { … … 10 13 public int $reviewed; 11 14 public int $users; 12 13 public function __construct( $created, $reviewed, $users ) { 15 public ?GP_Locale $language = null; 16 17 public function __construct( $created, $reviewed, $users, ?GP_Locale $language = null ) { 14 18 $this->created = $created; 15 19 $this->reviewed = $reviewed; 16 20 $this->users = $users; 21 $this->language = $language; 17 22 } 18 23 } … … 50 55 */ 51 56 public function rows(): array { 57 uasort( 58 $this->rows, 59 function ( $a, $b ) { 60 if ( ! $a->language && ! $b->language ) { 61 return 0; 62 } 63 if ( ! $a->language ) { 64 return -1; 65 } 66 if ( ! $b->language ) { 67 return 1; 68 } 69 70 return strcasecmp( $a->language->english_name, $b->language->english_name ); 71 } 72 ); 73 52 74 return $this->rows; 53 75 } … … 101 123 } 102 124 125 $lang = GP_Locales::by_slug( $row->locale ); 126 if ( ! $lang ) { 127 $lang = null; 128 } 129 103 130 $stats_row = new Stats_Row( 104 131 $row->created, 105 132 $row->total - $row->created, 106 133 $row->users, 134 $lang 107 135 ); 108 136 … … 115 143 116 144 return $stats; 145 } 146 147 /** 148 * Get contributors for an event. 149 */ 150 public function get_contributors( WP_Post $event ): array { 151 global $wpdb, $gp_table_prefix; 152 153 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared 154 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery 155 // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching 156 // phpcs thinks we're doing a schema change but we aren't. 157 // phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange 158 $rows = $wpdb->get_results( 159 $wpdb->prepare( 160 " 161 select user_id, group_concat( distinct locale ) as locales 162 from {$gp_table_prefix}event_actions 163 where event_id = %d 164 group by user_id 165 ", 166 array( 167 $event->ID, 168 ) 169 ) 170 ); 171 // phpcs:enable 172 173 $users = array(); 174 foreach ( $rows as $row ) { 175 $user = new WP_User( $row->user_id ); 176 $user->locales = explode( ',', $row->locales ); 177 $users[] = $user; 178 } 179 180 uasort( 181 $users, 182 function ( $a, $b ) { 183 return strcasecmp( $a->display_name, $b->display_name ); 184 } 185 ); 186 187 return $users; 117 188 } 118 189 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/stats-listener.php
r13279 r13298 26 26 function ( $translation ) { 27 27 $happened_at = DateTimeImmutable::createFromFormat( 'Y-m-d H:i:s', $translation->date_added, new DateTimeZone( 'UTC' ) ); 28 if ( ! $translation->user_id ) { 29 return; 30 } 28 31 $this->handle_action( $translation, $translation->user_id, self::ACTION_CREATE, $happened_at ); 29 32 }, … … 55 58 } 56 59 57 if ( $action ) {60 if ( $action && $user_id ) { 58 61 $this->handle_action( $translation, $user_id, $action, $happened_at ); 59 62 } … … 66 69 private function handle_action( GP_Translation $translation, int $user_id, string $action, DateTimeImmutable $happened_at ): void { 67 70 try { 68 if ( ! $user_id ) {69 return;70 }71 71 // Get events that are active when the action happened, for which the user is registered for. 72 72 $active_events = $this->get_active_events( $happened_at ); … … 172 172 // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.Found 173 173 private function select_events_user_is_registered_for( array $events, int $user_id ): array { 174 $attending_event_ids = get_user_meta( $user_id, Route::USER_META_KEY_ATTENDING, true );174 $attending_event_ids = get_user_meta( $user_id, Translation_Events::USER_META_KEY_ATTENDING, true ); 175 175 return array_filter( 176 176 $events, -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/templates/event.php
r13268 r13298 47 47 <?php if ( ! empty( $event_stats->rows() ) ) : ?> 48 48 <div class="event-details-stats"> 49 <h2> Stats</h2>49 <h2><?php esc_html_e( 'Stats', 'gp-translation-events' ); ?></h2> 50 50 <table> 51 51 <thead> … … 59 59 <tbody> 60 60 <?php /** @var $row Stats_Row */ ?> 61 <?php foreach ( $event_stats->rows() as $ locale_=> $row ) : ?>61 <?php foreach ( $event_stats->rows() as $_locale => $row ) : ?> 62 62 <tr> 63 <td ><?php echo esc_html( $locale_ ); ?></td>63 <td title="<?php echo esc_html( $_locale ); ?> "><a href="<?php echo esc_url( gp_url_join( gp_url( '/languages' ), $row->language->slug ) ); ?>"><?php echo esc_html( $row->language->english_name ); ?></a></td> 64 64 <td><?php echo esc_html( $row->created ); ?></td> 65 65 <td><?php echo esc_html( $row->reviewed ); ?></td> … … 76 76 </table> 77 77 </div> 78 <div class="event-contributors"> 79 <h2><?php esc_html_e( 'Contributors', 'gp-translation-events' ); ?></h2> 80 <ul> 81 <?php foreach ( $contributors as $contributor ) : ?> 82 <li class="event-contributor" title="<?php echo esc_html( implode( ', ', $contributor->locales ) ); ?>" 83 <a href="<?php echo esc_url( get_author_posts_url( $contributor->ID ) ); ?>"><?php echo get_avatar( $contributor->ID, 48 ); ?></a> 84 <a href="<?php echo esc_url( get_author_posts_url( $contributor->ID ) ); ?>"><?php echo esc_html( get_the_author_meta( 'display_name', $contributor->ID ) ); ?></a> 85 </li> 86 <?php endforeach; ?> 87 </ul> 88 </div> 78 89 <details class="event-stats-summary"> 79 90 <summary>View stats summary in text </summary> 80 <p class="event-stats-text"><?php echo esc_html( sprintf( 'At the %s event, %d people contributed in %d languages (%s), translated %d strings and reviewed %d strings.', esc_html( $event_title ), esc_html( $event_stats->totals()->users ), count( $event_stats->rows() ), esc_html( implode( ',', array_keys( $event_stats->rows() ) ) ), esc_html( $event_stats->totals()->created ), esc_html( $event_stats->totals()->reviewed ) ) ); ?></p> 91 <p class="event-stats-text"> 92 <?php 93 echo wp_kses( 94 sprintf( 95 // translators: %1$s: Event title, %2$d: Number of contributors, %3$d: Number of languages, %4$s: List of languages, %5$d: Number of strings translated, %6$d: Number of strings reviewed. 96 __( 'At the <strong>%1$s</strong> event, %2$d people contributed in %3$d languages (%4$s), translated %5$d strings and reviewed %6$d strings.', 'gp-translation-events' ), 97 esc_html( $event_title ), 98 esc_html( $event_stats->totals()->users ), 99 count( $event_stats->rows() ), 100 esc_html( 101 implode( 102 ', ', 103 array_map( 104 function ( $row ) { 105 return $row->language->english_name; 106 }, 107 $event_stats->rows() 108 ) 109 ) 110 ), 111 esc_html( $event_stats->totals()->created ), 112 esc_html( $event_stats->totals()->reviewed ) 113 ), 114 array( 115 'strong' => array(), 116 ) 117 ); 118 ?> 119 <?php 120 echo esc_html( 121 sprintf( 122 // translators: %s the contributors. 123 __( 'Contributors were %s.', 'gp-translation-events' ), 124 esc_html( 125 implode( 126 ', ', 127 array_map( 128 function ( $contributor ) { 129 return '@' . $contributor->user_login; 130 }, 131 $contributors 132 ) 133 ) 134 ) 135 ) 136 ); 137 ?> 138 </p> 81 139 </details> 82 <?php endif ?> 140 141 <?php endif; ?> 83 142 </div> 84 143 <div class="event-details-right"> -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/wporg-gp-translation-events.php
r13279 r13298 27 27 28 28 class Translation_Events { 29 const CPT = 'translation_event'; 29 public const CPT = 'translation_event'; 30 public const USER_META_KEY_ATTENDING = 'translation-events-attending'; 30 31 31 32 public static function get_instance() { … … 56 57 require_once __DIR__ . '/includes/active-events-cache.php'; 57 58 require_once __DIR__ . '/includes/event.php'; 58 require_once __DIR__ . '/includes/route.php'; 59 require_once __DIR__ . '/includes/routes/route.php'; 60 require_once __DIR__ . '/includes/routes/event/create.php'; 61 require_once __DIR__ . '/includes/routes/event/details.php'; 62 require_once __DIR__ . '/includes/routes/event/edit.php'; 63 require_once __DIR__ . '/includes/routes/event/list.php'; 64 require_once __DIR__ . '/includes/routes/user/attend-event.php'; 65 require_once __DIR__ . '/includes/routes/user/my-events.php'; 59 66 require_once __DIR__ . '/includes/stats-calculator.php'; 60 67 require_once __DIR__ . '/includes/stats-listener.php'; 61 68 62 GP::$router->add( '/events?', array( 'Wporg\TranslationEvents\Route ', 'events_list' ) );63 GP::$router->add( '/events/new', array( 'Wporg\TranslationEvents\Route ', 'events_create' ) );64 GP::$router->add( '/events/edit/(\d+)', array( 'Wporg\TranslationEvents\Route ', 'events_edit' ) );65 GP::$router->add( '/events/attend/(\d+)', array( 'Wporg\TranslationEvents\Route ', 'events_attend' ), 'post' );66 GP::$router->add( '/events/my-events', array( 'Wporg\TranslationEvents\Route ', 'my_events' ) );67 GP::$router->add( '/events/([a-z0-9_-]+)', array( 'Wporg\TranslationEvents\Route ', 'events_details' ) );69 GP::$router->add( '/events?', array( 'Wporg\TranslationEvents\Routes\Event\List_Route', 'handle' ) ); 70 GP::$router->add( '/events/new', array( 'Wporg\TranslationEvents\Routes\Event\Create_Route', 'handle' ) ); 71 GP::$router->add( '/events/edit/(\d+)', array( 'Wporg\TranslationEvents\Routes\Event\Edit_Route', 'handle' ) ); 72 GP::$router->add( '/events/attend/(\d+)', array( 'Wporg\TranslationEvents\Routes\User\Attend_Event_Route', 'handle' ), 'post' ); 73 GP::$router->add( '/events/my-events', array( 'Wporg\TranslationEvents\Routes\User\My_Events_Route', 'handle' ) ); 74 GP::$router->add( '/events/([a-z0-9_-]+)', array( 'Wporg\TranslationEvents\Routes\Event\Details_Route', 'handle' ) ); 68 75 69 76 $active_events_cache = new Active_Events_Cache(); … … 400 407 if ( 'publish' === $new_status && ( 'new' === $old_status || 'draft' === $old_status ) ) { 401 408 $current_user_id = get_current_user_id(); 402 $user_attending_events = get_user_meta( $current_user_id, Route::USER_META_KEY_ATTENDING, true ) ?: array();409 $user_attending_events = get_user_meta( $current_user_id, self::USER_META_KEY_ATTENDING, true ) ?: array(); 403 410 $is_user_attending_event = in_array( $post->ID, $user_attending_events, true ); 404 411 if ( ! $is_user_attending_event ) { 405 412 $new_user_attending_events = $user_attending_events; 406 413 $new_user_attending_events[ $post->ID ] = true; 407 update_user_meta( $current_user_id, Route::USER_META_KEY_ATTENDING, $new_user_attending_events, $user_attending_events );414 update_user_meta( $current_user_id, self::USER_META_KEY_ATTENDING, $new_user_attending_events, $user_attending_events ); 408 415 } 409 416 } … … 462 469 */ 463 470 public function add_active_events_current_user(): void { 464 $user_attending_events = get_user_meta( get_current_user_id(), Route::USER_META_KEY_ATTENDING, true ) ?: array();471 $user_attending_events = get_user_meta( get_current_user_id(), self::USER_META_KEY_ATTENDING, true ) ?: array(); 465 472 if ( empty( $user_attending_events ) ) { 466 473 return;
Note: See TracChangeset
for help on using the changeset viewer.