Making WordPress.org


Ignore:
Timestamp:
02/26/2018 08:14:23 PM (8 years ago)
Author:
ocean90
Message:

Translate: Split translation editors list into project and inherited editors.

Fixes #3461.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-locale.php

    r6692 r6770  
    372372                global $wpdb;
    373373
     374                $editors = [
     375                        'project'   => [],
     376                        'inherited' => [],
     377                ];
     378
    374379                // Get the translation editors of the project.
    375                 $editors = (array) $wpdb->get_col( $wpdb->prepare( "
     380                $editors['project'] = (array) $wpdb->get_col( $wpdb->prepare( "
    376381                        SELECT
    377382                                `user_id`
     
    382387                ", $project->id, $locale_slug ) );
    383388
     389                // Get the translation editors of parent projects.
    384390                if ( $project->parent_project_id ) {
    385391                        $parent_project_id = $project->parent_project_id;
    386392                        $parent_project = GP::$project->get( $parent_project_id );
    387393                        while ( $parent_project_id ) {
    388                                 $editors = $editors + (array) $wpdb->get_col( $wpdb->prepare( "
     394                                $editors['inherited'] = array_merge( $editors['inherited'], (array) $wpdb->get_col( $wpdb->prepare( "
    389395                                        SELECT
    390396                                                `user_id`
     
    393399                                                `project_id` = %d
    394400                                                AND `locale` IN (%s, 'all-locales')
    395                                 ", $parent_project->id, $locale_slug ) );
     401                                ", $parent_project->id, $locale_slug ) ) );
    396402
    397403                                $parent_project = GP::$project->get( $parent_project_id );
     
    399405                        }
    400406                }
     407
     408                // Get the translation editors for all projects.
     409                $editors['inherited'] = array_merge( $editors['inherited'], (array) $wpdb->get_col( $wpdb->prepare( "
     410                        SELECT
     411                                `user_id`
     412                        FROM {$wpdb->wporg_translation_editors}
     413                        WHERE
     414                                `project_id` = '0'
     415                                AND `locale` = %s
     416                ", $locale_slug ) ) );
    401417
    402418                return $editors;
     
    414430                global $wpdb;
    415431
    416                 $locale_contributors = array(
    417                         'editors'      => array(),
    418                         'contributors' => array(),
    419                 );
     432                $locale_contributors = [
     433                        'editors'      => [
     434                                'project'   => [],
     435                                'inherited' => [],
     436                        ],
     437                        'contributors' => [],
     438                ];
    420439
    421440                // Get the translation editors of the project.
    422441                $editors = $this->get_translation_editors( $project, $locale_slug );
    423442
     443                $editor_ids = [];
     444
    424445                // Get the names of the translation editors.
    425                 foreach ( $editors as $editor_id ) {
    426                         $user = get_user_by( 'id', $editor_id );
    427                         if ( ! $user ) {
    428                                 continue;
    429                         }
    430 
    431                         $locale_contributors['editors'][ $editor_id ] = (object) array(
    432                                 'nicename'     => $user->user_nicename,
    433                                 'display_name' => $this->_encode( $user->display_name ),
    434                                 'email'        => $user->user_email,
    435                         );
    436                 }
     446                foreach ( [ 'project', 'inherited'] as $editor_source ) {
     447                        foreach ( $editors[ $editor_source ] as $editor_id ) {
     448                                $user = get_user_by( 'id', $editor_id );
     449                                if ( ! $user ) {
     450                                        continue;
     451                                }
     452
     453                                $locale_contributors['editors'][ $editor_source ][ $editor_id ] = (object) array(
     454                                        'nicename'     => $user->user_nicename,
     455                                        'display_name' => $this->_encode( $user->display_name ),
     456                                        'email'        => $user->user_email,
     457                                );
     458
     459                                $editor_ids[] = $editor_id;
     460                        }
     461
     462                        uasort( $locale_contributors['editors'][ $editor_source ], function( $a, $b ) {
     463                                return strcasecmp( $a->display_name, $b->display_name );
     464                        } );
     465                }
     466
    437467                unset( $editors );
    438468
     
    469499                        );
    470500                }
    471 
    472                 $editors = array_keys( $locale_contributors['editors'] );
    473501
    474502                // Get the names of the contributors.
     
    502530                                'waiting_count' => $contributor->waiting_count,
    503531                                'fuzzy_count'   => $contributor->fuzzy_count,
    504                                 'is_editor'     => in_array( $user->ID, $editors ),
     532                                'is_editor'     => in_array( $user->ID, $editor_ids ),
    505533                        );
    506534                }
    507                 unset( $contributors, $editors );
     535                unset( $contributors, $editor_ids );
    508536
    509537                uasort( $locale_contributors['contributors'], function( $a, $b ) {
    510538                        return $a->total_count < $b->total_count;
    511                 } );
    512 
    513                 uasort( $locale_contributors['editors'], function( $a, $b ) {
    514                         return strcasecmp( $a->display_name, $b->display_name );
    515539                } );
    516540
Note: See TracChangeset for help on using the changeset viewer.