Changeset 13565
- Timestamp:
- 04/18/2024 10:06:30 AM (15 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/stats/stats-calculator.php
r13541 r13565 303 303 304 304 /** 305 * Check if a user is a first time contributor.305 * Check if a user is a new translation contributor. A new contributor is a user who has made 10 or fewer translations before event start time. 306 306 * 307 307 * @param Event_Start_Date $event_start The event start date. 308 308 * @param int $user_id The user ID. 309 309 * 310 * @return bool True if the user is a first time contributor, false otherwise. 311 */ 312 public function is_first_time_contributor( $event_start, $user_id ) { 313 global $wpdb, $gp_table_prefix; 314 310 * @return bool True if the user is a new translation contributor, false otherwise. 311 */ 312 public function is_new_translation_contributor( $event_start, $user_id ) { 313 global $wpdb, $gp_table_prefix; 314 $new_contributor_max_translation_count = 10; 315 $event_start_date_time = $event_start->__toString(); 315 316 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared 316 317 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery 317 318 // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching 318 319 // phpcs:disable WordPress.DB.DirectDatabaseQuery.SchemaChange 319 $user s_first_translation_date= $wpdb->get_var(320 $wpdb->prepare( 321 " 322 select min(date_added) from {$gp_table_prefix}translations where user_id = %d320 $user_translations_count = $wpdb->get_var( 321 $wpdb->prepare( 322 " 323 select count(*) from {$gp_table_prefix}translations where user_id = %d and date_added < %s 323 324 ", 324 325 array( 325 326 $user_id, 326 ) 327 ) 328 ); 329 330 if ( get_userdata( $user_id ) && ! $users_first_translation_date ) { 327 $event_start_date_time, 328 ) 329 ) 330 ); 331 332 if ( get_userdata( $user_id ) && ! $user_translations_count ) { 331 333 return true; 332 334 } 333 $event_start_date_time = new DateTimeImmutable( $event_start->__toString(), new DateTimeZone( 'UTC' ) ); 334 $first_translation_date = new DateTimeImmutable( $users_first_translation_date, new DateTimeZone( 'UTC' ) ); 335 // A first time contributor is someone whose first translation was made not earlier than 24 hours before the event. 336 $event_start_date_time = $event_start_date_time->modify( '-1 day' ); 337 return $event_start_date_time <= $first_translation_date; 335 return $user_translations_count <= $new_contributor_max_translation_count; 338 336 } 339 337 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/templates/event.php
r13541 r13565 6 6 namespace Wporg\TranslationEvents; 7 7 8 use GP_Locales; 8 9 use WP_User; 9 10 use Wporg\TranslationEvents\Attendee\Attendee; … … 44 45 <?php if ( ! empty( $contributors ) ) : ?> 45 46 <div class="event-contributors"> 46 <h2><?php esc_html_e( 'Contributors', 'gp-translation-events' ); ?></h2> 47 <h2> 48 <?php 49 // translators: %d is the number of contributors. 50 echo esc_html( sprintf( __( 'Contributors (%d)', 'gp-translation-events' ), number_format_i18n( count( $contributors ) ) ) ); 51 ?> 52 </h2> 47 53 <ul> 48 54 <?php foreach ( $contributors as $contributor ) : ?> … … 50 56 <a href="<?php echo esc_url( get_author_posts_url( $contributor->ID ) ); ?>" class="avatar"><?php echo get_avatar( $contributor->ID, 48 ); ?></a> 51 57 <a href="<?php echo esc_url( get_author_posts_url( $contributor->ID ) ); ?>" class="name"><?php echo esc_html( get_the_author_meta( 'display_name', $contributor->ID ) ); ?></a> 52 <?php if ( $stats_calculator->is_ first_time_contributor( $event_start, $contributor->ID ) ) : ?>58 <?php if ( $stats_calculator->is_new_translation_contributor( $event_start, $contributor->ID ) ) : ?> 53 59 <span class="first-time-contributor-tada" title="<?php esc_html_e( 'New Translation Contributor', 'gp-translation-events' ); ?>"></span> 54 60 <?php endif; ?> … … 78 84 <?php if ( ! empty( $attendees ) && ( ! $event->end()->is_in_the_past() || ( ( $attendee instanceof Attendee && $attendee->is_host() ) || current_user_can( 'manage_options' ) || $user->ID === $event->author_id() ) ) ) : ?> 79 85 <div class="event-attendees"> 80 <h2><?php esc_html_e( 'Attendees', 'gp-translation-events' ); ?></h2> 86 <h2> 87 <?php 88 // translators: %d is the number of attendees. 89 echo esc_html( sprintf( __( 'Attendees (%d)', 'gp-translation-events' ), number_format_i18n( count( $attendees ) ) ) ); 90 ?> 91 </h2> 81 92 <ul> 82 93 <?php foreach ( $attendees as $_user ) : ?> … … 84 95 <a href="<?php echo esc_url( get_author_posts_url( $_user->ID ) ); ?>" class="avatar"><?php echo get_avatar( $_user->ID, 48 ); ?></a> 85 96 <a href="<?php echo esc_url( get_author_posts_url( $_user->ID ) ); ?>" class="name"><?php echo esc_html( get_the_author_meta( 'display_name', $_user->ID ) ); ?></a> 86 <?php if ( $stats_calculator->is_ first_time_contributor( $event_start, $_user->ID ) ) : ?>97 <?php if ( $stats_calculator->is_new_translation_contributor( $event_start, $_user->ID ) ) : ?> 87 98 <span class="first-time-contributor-tada" title="<?php esc_html_e( 'New Translation Contributor', 'gp-translation-events' ); ?>"></span> 88 99 <?php endif; ?> … … 147 158 <?php 148 159 foreach ( explode( ',', $row->locales ) as $_locale ) { 149 $_locale = \GP_Locales::by_slug( $_locale );160 $_locale = GP_Locales::by_slug( $_locale ); 150 161 ?> 151 <a href="<?php echo esc_url( gp_url_project_locale( $row->project, $_locale , 'default' ) ); ?>"><?php echo esc_html( $_locale->english_name ); ?></a>162 <a href="<?php echo esc_url( gp_url_project_locale( $row->project, $_locale->slug, 'default' ) ); ?>"><?php echo esc_html( $_locale->english_name ); ?></a> 152 163 <?php 153 164 } … … 200 211 function ( $contributor ) use ( $stats_calculator, $event_start ) { 201 212 $append_tada = ''; 202 if ( $stats_calculator->is_ first_time_contributor( $event_start, $contributor->ID ) ) {213 if ( $stats_calculator->is_new_translation_contributor( $event_start, $contributor->ID ) ) { 203 214 $append_tada = '<span class="first-time-contributor-tada" title="' . esc_html__( 'New Translation Contributor', 'gp-translation-events' ) . '"></span>'; 204 215 }
Note: See TracChangeset
for help on using the changeset viewer.