Making WordPress.org

Changeset 6478


Ignore:
Timestamp:
01/30/2018 11:25:21 PM (7 years ago)
Author:
danielbachhuber
Message:

phpunit-test-reporter: Display reporter avatars at the top of the page

See https://github.com/WordPress/phpunit-test-reporter/pull/54

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/phpunit-test-reporter/src/class-display.php

    r6386 r6478  
    115115        }
    116116        $output .= self::get_display_css();
     117        if ( $paged <= 1 ) {
     118            $output .= self::get_reporter_avatars();
     119        }
    117120        $output .= ptr_get_template_part(
    118121            'result-set', array(
     
    166169                cursor: pointer;
    167170            }
     171            .ptr-test-reporter-list {
     172                list-style-type: none;
     173                margin-left: 0;
     174                margin-right: 0;
     175            }
     176            .ptr-test-reporter-list li {
     177                display: inline-block;
     178                vertical-align: top;
     179                text-align: center;
     180                margin-left: 10px;
     181                margin-right: 10px;
     182                width: 100px;
     183            }
     184            .ptr-test-reporter-list li h5.avatar-name {
     185                font-weight: 600;
     186                margin-top: 6px;
     187                margin-bottom: 6px;
     188            }
    168189        </style>
    169190        <?php
    170191        return ob_get_clean();
     192    }
     193
     194    /**
     195     * Get the avatars who have recently reported.
     196     */
     197    private static function get_reporter_avatars() {
     198        global $wpdb;
     199
     200        $output           = '';
     201        $query_args       = array(
     202            'posts_per_page'         => 10,
     203            'post_type'              => 'result',
     204            'post_parent'            => 0,
     205            'orderby'                => 'post_name',
     206            'order'                  => 'DESC',
     207            'fields'                 => 'ids',
     208            'update_post_meta_cache' => false,
     209            'update_post_term_cache' => false,
     210            'no_found_rows'          => true,
     211        );
     212        $query            = new \WP_Query( $query_args );
     213        $active_reporters = array();
     214        if ( ! empty( $query->posts ) ) {
     215            $active_reporters = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type='result' AND post_status='publish' AND post_parent IN (" . implode( ',', $query->posts ) . ')' ); // @codingStandardsIgnoreLine
     216            $active_reporters = array_map( 'intval', $active_reporters );
     217            $output          .= '<h3>Active Test Reporters</h3>' . PHP_EOL;
     218            $users            = get_users(
     219                array(
     220                    'orderby' => 'display_name',
     221                    'include' => $active_reporters,
     222                )
     223            );
     224            $output          .= self::get_user_list( $users );
     225        }
     226
     227        $all_time_reporters = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type='result' AND post_status='publish' AND post_parent != 0" ); // @codingStandardsIgnoreLine
     228        if ( ! empty( $all_time_reporters ) ) {
     229            $all_time_reporters = array_map( 'intval', $all_time_reporters );
     230            $output            .= '<h3>No Reports in >10 Revisions</h3>' . PHP_EOL;
     231            $users              = get_users(
     232                array(
     233                    'orderby' => 'display_name',
     234                    'include' => $all_time_reporters,
     235                )
     236            );
     237            foreach ( $users as $i => $user ) {
     238                if ( in_array( $user->ID, $active_reporters, true ) ) {
     239                    unset( $users[ $i ] );
     240                }
     241            }
     242            $output .= self::get_user_list( $users );
     243        }
     244        return $output;
     245    }
     246
     247    private static function get_user_list( $users ) {
     248        $output = '<ul class="ptr-test-reporter-list">';
     249        foreach ( $users as $user ) {
     250            $output .= '<li>';
     251            if ( ! empty( $user->user_url ) ) {
     252                $output .= '<a target="_blank" rel="nofollow" href="' . esc_url( $user->user_url ) . '">';
     253            }
     254            $output .= get_avatar( $user->user_email, 82 );
     255            if ( ! empty( $user->user_url ) ) {
     256                $output .= '</a>';
     257            }
     258            $output .= '<h5 class="avatar-name">';
     259            if ( ! empty( $user->user_url ) ) {
     260                $output .= '<a target="_blank" rel="nofollow" href="' . esc_url( $user->user_url ) . '">';
     261            }
     262            $output .= $user->display_name;
     263            if ( ! empty( $user->user_url ) ) {
     264                $output .= '</a>';
     265            }
     266            $output .= '</h5>';
     267            $output .= '</li>';
     268        }
     269        $output .= '</ul>';
     270        return $output;
    171271    }
    172272
Note: See TracChangeset for help on using the changeset viewer.