Add support of Player Performance and Player statistic icons to Player Profile template and simplify the loop logic
This commit is contained in:
@@ -224,8 +224,6 @@ class SP_Player_List extends SP_Secondary_Post {
|
||||
}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
|
||||
$format = get_post_meta( $stat->ID, 'sp_format', true );
|
||||
@@ -677,24 +675,19 @@ class SP_Player_List extends SP_Secondary_Post {
|
||||
endif;
|
||||
|
||||
$labels = array();
|
||||
$labels_title = array();
|
||||
foreach( $this->columns as $key ):
|
||||
if ( $key == 'number' ):
|
||||
$labels[ $key ] = '#';
|
||||
$labels_title[ $key ] = '#';
|
||||
elseif ( $key == 'team' ):
|
||||
$labels[ $key ] = __( 'Team', 'sportspress' );
|
||||
$labels_title[ $key ] = __( 'Team', 'sportspress' );
|
||||
elseif ( $key == 'position' ):
|
||||
$labels[ $key ] = __( 'Position', 'sportspress' );
|
||||
$labels_title[ $key ] = __( 'Position', 'sportspress' );
|
||||
elseif ( array_key_exists( $key, $columns ) ):
|
||||
$labels[ $key ] = $columns[ $key ];
|
||||
$labels_title[ $key ] = $columns_title[ $key ];
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
return array( $labels, $labels_title, $data, $placeholders, $merged, $orderby );
|
||||
return array( $labels, $data, $placeholders, $merged, $orderby );
|
||||
else:
|
||||
|
||||
// Convert to time notation
|
||||
@@ -726,7 +719,6 @@ class SP_Player_List extends SP_Secondary_Post {
|
||||
foreach ( $columns as $key => $label ):
|
||||
if ( ! in_array( $key, $this->columns ) ):
|
||||
unset( $columns[ $key ] );
|
||||
unset( $columns_title[ $key ] );
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
@@ -740,8 +732,7 @@ class SP_Player_List extends SP_Secondary_Post {
|
||||
$labels['position'] = __( 'Position', 'sportspress' );
|
||||
}
|
||||
|
||||
$merged['head'] = array_merge( $labels, $columns );
|
||||
$merged[0] = array_merge( $labels, $columns_title );
|
||||
$merged[0] = array_merge( $labels, $columns );
|
||||
return $merged;
|
||||
endif;
|
||||
}
|
||||
|
||||
@@ -184,8 +184,17 @@ class SP_Player extends SP_Custom_Post {
|
||||
|
||||
foreach ( $posts as $post ):
|
||||
if ( -1 === $section ) {
|
||||
$performance_labels[ $post->post_name ] = $post->post_title;
|
||||
} else {
|
||||
if ( get_option( 'sportspress_player_statistics_mode', 'values' ) == 'icons' ) {
|
||||
$icon = apply_filters( 'sportspress_event_performance_icons', '', $post->ID, 1 );
|
||||
if ( $icon != '' ) {
|
||||
$performance_labels[ $post->post_name ] = apply_filters( 'sportspress_event_performance_icons', '', $post->ID, 1 );
|
||||
}else{
|
||||
$performance_labels[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
}else{
|
||||
$performance_labels[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
}else{
|
||||
$post_section = get_post_meta( $post->ID, 'sp_section', true );
|
||||
|
||||
if ( '' === $post_section ) {
|
||||
@@ -193,7 +202,16 @@ class SP_Player extends SP_Custom_Post {
|
||||
}
|
||||
|
||||
if ( $section == $post_section || -1 == $post_section ) {
|
||||
if ( get_option( 'sportspress_player_statistics_mode', 'values' ) == 'icons' ) {
|
||||
$icon = apply_filters( 'sportspress_event_performance_icons', '', $post->ID, 1 );
|
||||
if ( $icon != '' ) {
|
||||
$performance_labels[ $post->post_name ] = apply_filters( 'sportspress_event_performance_icons', '', $post->ID, 1 );
|
||||
}else{
|
||||
$performance_labels[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
}else{
|
||||
$performance_labels[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -566,7 +584,16 @@ class SP_Player extends SP_Custom_Post {
|
||||
|
||||
foreach ( $posts as $post ):
|
||||
if ( -1 === $section ) {
|
||||
$stats[ $post->post_name ] = $post->post_title;
|
||||
if ( get_option( 'sportspress_player_statistics_mode', 'values' ) == 'icons' ) {
|
||||
$icon = apply_filters( 'sportspress_event_performance_icons', '', $post->ID, 1 );
|
||||
if ( $icon != '' ) {
|
||||
$stats[ $post->post_name ] = apply_filters( 'sportspress_event_performance_icons', '', $post->ID, 1 );
|
||||
}else{
|
||||
$stats[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
}else{
|
||||
$stats[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
} else {
|
||||
$post_section = get_post_meta( $post->ID, 'sp_section', true );
|
||||
|
||||
@@ -577,16 +604,43 @@ class SP_Player extends SP_Custom_Post {
|
||||
if ( $admin ) {
|
||||
if ( 1 == $section ) {
|
||||
if ( 1 == $post_section ) {
|
||||
$stats[ $post->post_name ] = $post->post_title;
|
||||
if ( get_option( 'sportspress_player_statistics_mode', 'values' ) == 'icons' ) {
|
||||
$icon = apply_filters( 'sportspress_event_performance_icons', '', $post->ID, 1 );
|
||||
if ( $icon != '' ) {
|
||||
$stats[ $post->post_name ] = apply_filters( 'sportspress_event_performance_icons', '', $post->ID, 1 );
|
||||
} else {
|
||||
$stats[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
} else {
|
||||
$stats[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( 1 != $post_section ) {
|
||||
$stats[ $post->post_name ] = $post->post_title;
|
||||
if ( get_option( 'sportspress_player_statistics_mode', 'values' ) == 'icons' ) {
|
||||
$icon = apply_filters( 'sportspress_event_performance_icons', '', $post->ID, 1 );
|
||||
if ( $icon != '' ) {
|
||||
$stats[ $post->post_name ] = apply_filters( 'sportspress_event_performance_icons', '', $post->ID, 1 );
|
||||
} else {
|
||||
$stats[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
} else {
|
||||
$stats[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ( $section == $post_section || -1 == $post_section ) {
|
||||
if ( get_option( 'sportspress_player_statistics_mode', 'values' ) == 'icons' ) {
|
||||
$icon = apply_filters( 'sportspress_event_performance_icons', '', $post->ID, 1 );
|
||||
if ( $icon != '' ) {
|
||||
$stats[ $post->post_name ] = apply_filters( 'sportspress_event_performance_icons', '', $post->ID, 1 );
|
||||
}else{
|
||||
$stats[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
}else{
|
||||
$stats[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
}
|
||||
}
|
||||
endforeach;
|
||||
|
||||
|
||||
@@ -53,12 +53,9 @@ if ( isset( $columns ) && null !== $columns ):
|
||||
endif;
|
||||
$data = $list->data();
|
||||
|
||||
// The first row should be data-label labels
|
||||
// The first row should be labels
|
||||
$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
|
||||
$identifier = uniqid( 'playerlist_' );
|
||||
// If responsive tables are enabled then load the inline css code
|
||||
@@ -67,7 +64,6 @@ if ( true == $responsive ){
|
||||
}
|
||||
// Remove the first row and 'head' row to leave us with the actual data
|
||||
unset( $data[0] );
|
||||
unset( $data['head'] );
|
||||
|
||||
if ( $grouping === null || $grouping === 'default' ):
|
||||
$grouping = $list->grouping;
|
||||
@@ -136,9 +132,11 @@ foreach ( $groups as $group ):
|
||||
endif;
|
||||
endif;
|
||||
|
||||
foreach( $labels_head as $key => $label ):
|
||||
foreach( $labels as $key => $label ):
|
||||
if ( $key !== 'number' && ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) ) )
|
||||
$thead .= '<th class="data-' . $key . '">'. $label . '</th>';
|
||||
$thead .= '<th class="data-' . $key . '">'. $label . '</th>';
|
||||
if ( preg_match ( "/title=\"(.*?)\"/", $label, $new_label ) )
|
||||
$labels[$key] = $label[1];
|
||||
endforeach;
|
||||
|
||||
$thead .= '</tr>' . '</thead>';
|
||||
|
||||
Reference in New Issue
Block a user