Changeset 13298 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/stats-calculator.php
- Timestamp:
- 03/07/2024 06:39:00 AM (13 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.