Add support of Player Performance and Player statistic icons to Player List template

This commit is contained in:
savvasha
2018-05-14 19:35:05 +03:00
parent ed70d8babe
commit d1e147178e
3 changed files with 47 additions and 9 deletions

View File

@@ -149,6 +149,17 @@ class SP_Settings_Players extends SP_Settings_Page {
), ),
), ),
array(
'title' => __( 'Mode', 'sportspress' ),
'id' => 'sportspress_player_statistics_mode',
'default' => 'values',
'type' => 'radio',
'options' => array(
'values' => __( 'Values', 'sportspress' ),
'icons' => __( 'Icons', 'sportspress' ),
),
),
array( array(
'title' => __( 'Categories', 'sportspress' ), 'title' => __( 'Categories', 'sportspress' ),
'id' => 'sportspress_player_performance_sections', 'id' => 'sportspress_player_performance_sections',

View File

@@ -213,8 +213,19 @@ class SP_Player_List extends SP_Secondary_Post {
// Add precision to object // Add precision to object
$stat->precision = sp_array_value( sp_array_value( $meta, 'sp_precision', array() ), 0, 0 ) + 0; $stat->precision = sp_array_value( sp_array_value( $meta, 'sp_precision', array() ), 0, 0 ) + 0;
// Add column name to columns // Add column icons to columns were is available
if ( get_option( 'sportspress_player_statistics_mode', 'values' ) == 'icons' && ( $stat->post_type == 'sp_performance' || $stat->post_type == 'sp_statistic' ) ) {
$icon = apply_filters( 'sportspress_event_performance_icons', '', $stat->ID, 1 );
if ( $icon != '' ) {
$columns[ $stat->post_name ] = apply_filters( 'sportspress_event_performance_icons', '', $stat->ID, 1 );
}else{
$columns[ $stat->post_name ] = $stat->post_title; $columns[ $stat->post_name ] = $stat->post_title;
}
}else{
$columns[ $stat->post_name ] = $stat->post_title;
}
// Add columns titles for using with data-label
$columns_title[ $stat->post_name ] = $stat->post_title;
// Add format // Add format
$format = get_post_meta( $stat->ID, 'sp_format', true ); $format = get_post_meta( $stat->ID, 'sp_format', true );
@@ -669,16 +680,20 @@ class SP_Player_List extends SP_Secondary_Post {
foreach( $this->columns as $key ): foreach( $this->columns as $key ):
if ( $key == 'number' ): if ( $key == 'number' ):
$labels[ $key ] = '#'; $labels[ $key ] = '#';
$labels_title[ $key ] = '#';
elseif ( $key == 'team' ): elseif ( $key == 'team' ):
$labels[ $key ] = __( 'Team', 'sportspress' ); $labels[ $key ] = __( 'Team', 'sportspress' );
$labels_title[ $key ] = __( 'Team', 'sportspress' );
elseif ( $key == 'position' ): elseif ( $key == 'position' ):
$labels[ $key ] = __( 'Position', 'sportspress' ); $labels[ $key ] = __( 'Position', 'sportspress' );
$labels_title[ $key ] = __( 'Position', 'sportspress' );
elseif ( array_key_exists( $key, $columns ) ): elseif ( array_key_exists( $key, $columns ) ):
$labels[ $key ] = $columns[ $key ]; $labels[ $key ] = $columns[ $key ];
$labels_title[ $key ] = $columns_title[ $key ];
endif; endif;
endforeach; endforeach;
return array( $labels, $data, $placeholders, $merged, $orderby ); return array( $labels, $labels_title, $data, $placeholders, $merged, $orderby );
else: else:
// Convert to time notation // Convert to time notation
@@ -716,10 +731,18 @@ class SP_Player_List extends SP_Secondary_Post {
$labels = array(); $labels = array();
if ( in_array( 'number', $this->columns ) ) $labels['number'] = '#'; if ( in_array( 'number', $this->columns ) ) $labels['number'] = '#';
$labels['name'] = __( 'Player', 'sportspress' ); $labels['name'] = __( 'Player', 'sportspress' );
if ( in_array( 'team', $this->columns ) ) $labels['team'] = __( 'Team', 'sportspress' ); $labels_title['name'] = __( 'Player', 'sportspress' );
if ( in_array( 'position', $this->columns ) ) $labels['position'] = __( 'Position', 'sportspress' ); if ( in_array( 'team', $this->columns ) ) {
$labels['team'] = __( 'Team', 'sportspress' );
$labels_title['team'] = __( 'Team', 'sportspress' );
}
if ( in_array( 'position', $this->columns ) ) {
$labels['position'] = __( 'Position', 'sportspress' );
$labels_title['position'] = __( 'Position', 'sportspress' );
}
$merged[0] = array_merge( $labels, $columns ); $merged['head'] = array_merge( $labels, $columns );
$merged[0] = array_merge( $labels, $columns_title );
return $merged; return $merged;
endif; endif;
} }

View File

@@ -53,17 +53,21 @@ if ( isset( $columns ) && null !== $columns ):
endif; endif;
$data = $list->data(); $data = $list->data();
// The first row should be column labels // The first row should be data-label labels
$labels = $data[0]; $labels = $data[0];
// The 'head' row should be column labels
$labels_head = $data['head'];
//Create a unique identifier based on the current time in microseconds //Create a unique identifier based on the current time in microseconds
$identifier = uniqid( 'playerlist_' ); $identifier = uniqid( 'playerlist_' );
// If responsive tables are enabled then load the inline css code // If responsive tables are enabled then load the inline css code
if ( true == $responsive ){ if ( true == $responsive ){
//sportspress_responsive_tables_css( $identifier ); //sportspress_responsive_tables_css( $identifier );
} }
// Remove the first row to leave us with the actual data // Remove the first row and 'head' row to leave us with the actual data
unset( $data[0] ); unset( $data[0] );
unset( $data['head'] );
if ( $grouping === null || $grouping === 'default' ): if ( $grouping === null || $grouping === 'default' ):
$grouping = $list->grouping; $grouping = $list->grouping;
@@ -223,7 +227,7 @@ foreach ( $groups as $group ):
endif; endif;
endif; endif;
foreach( $labels as $key => $label ): foreach( $labels_head as $key => $label ):
if ( $key !== 'number' && ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) ) ) if ( $key !== 'number' && ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) ) )
$output .= '<th class="data-' . $key . '">'. $label . '</th>'; $output .= '<th class="data-' . $key . '">'. $label . '</th>';
endforeach; endforeach;