Merge pull request #290 from ThemeBoy/feature-statistics-icons
Feature statistics icons
This commit is contained in:
@@ -109,3 +109,22 @@
|
||||
.sp-icon-card:before {
|
||||
content: "\e801";
|
||||
}
|
||||
.sp-icon-league:before {
|
||||
content: "\f332";
|
||||
}
|
||||
.sp-icon-shield:before {
|
||||
content: "\f334";
|
||||
}
|
||||
.sp-icon-tshirt:before,
|
||||
.sp-icon-sp_player:before {
|
||||
content: "\f307";
|
||||
}
|
||||
.sp-icon-whistle:before {
|
||||
content: "\f227";
|
||||
}
|
||||
.sp-icon-time:before {
|
||||
content: "\f469";
|
||||
}
|
||||
.sp-icon-friendly:before {
|
||||
content: "\f328";
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ class SP_Admin_CPT_Statistic extends SP_Admin_CPT {
|
||||
public function edit_columns( $existing_columns ) {
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'sp_icon' => __( 'Icon', 'sportspress' ),
|
||||
'title' => __( 'Label', 'sportspress' ),
|
||||
'sp_key' => __( 'Key', 'sportspress' ),
|
||||
'sp_equation' => __( 'Equation', 'sportspress' ),
|
||||
@@ -55,6 +56,9 @@ class SP_Admin_CPT_Statistic extends SP_Admin_CPT {
|
||||
*/
|
||||
public function custom_columns( $column, $post_id ) {
|
||||
switch ( $column ):
|
||||
case 'sp_icon':
|
||||
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : '';
|
||||
break;
|
||||
case 'sp_key':
|
||||
global $post;
|
||||
echo $post->post_name;
|
||||
|
||||
@@ -303,6 +303,9 @@ class SP_Admin_Meta_Boxes {
|
||||
|
||||
remove_meta_box( 'postimagediv', 'sp_performance', 'side' );
|
||||
add_meta_box( 'postimagediv', __( 'Icon', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_performance', 'side', 'low' );
|
||||
|
||||
remove_meta_box( 'postimagediv', 'sp_statistic', 'side' );
|
||||
add_meta_box( 'postimagediv', __( 'Icon', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_statistic', 'side', 'low' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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(
|
||||
'title' => __( 'Categories', 'sportspress' ),
|
||||
'id' => 'sportspress_player_performance_sections',
|
||||
|
||||
@@ -371,6 +371,7 @@ $columns = get_option( 'sportspress_player_columns', 'auto' );
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th class="icon" scope="col"><?php _e( 'Icon', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Equation', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Decimal Places', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Category', 'sportspress' ); ?></th>
|
||||
@@ -391,6 +392,16 @@ $columns = get_option( 'sportspress_player_columns', 'auto' );
|
||||
?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||
<td class="icon">
|
||||
<?php
|
||||
if ( has_post_thumbnail( $row->ID ) )
|
||||
$icon = get_the_post_thumbnail( $row->ID, 'sportspress-fit-mini' );
|
||||
else
|
||||
$icon = ' ';
|
||||
|
||||
echo apply_filters( 'sportspress_performance_icon', $icon, $row->ID );
|
||||
?>
|
||||
</td>
|
||||
<td><?php echo sp_get_post_equation( $row->ID ); ?></td>
|
||||
<td><?php echo sp_get_post_precision( $row->ID ); ?></td>
|
||||
<td><?php echo sp_get_post_section( $row->ID ); ?></td>
|
||||
|
||||
@@ -213,8 +213,17 @@ class SP_Player_List extends SP_Secondary_Post {
|
||||
// Add precision to object
|
||||
$stat->precision = sp_array_value( sp_array_value( $meta, 'sp_precision', array() ), 0, 0 ) + 0;
|
||||
|
||||
// Add column name to columns
|
||||
$columns[ $stat->post_name ] = $stat->post_title;
|
||||
// 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;
|
||||
}
|
||||
}else{
|
||||
$columns[ $stat->post_name ] = $stat->post_title;
|
||||
}
|
||||
|
||||
// Add format
|
||||
$format = get_post_meta( $stat->ID, 'sp_format', true );
|
||||
@@ -716,8 +725,12 @@ class SP_Player_List extends SP_Secondary_Post {
|
||||
$labels = array();
|
||||
if ( in_array( 'number', $this->columns ) ) $labels['number'] = '#';
|
||||
$labels['name'] = __( 'Player', 'sportspress' );
|
||||
if ( in_array( 'team', $this->columns ) ) $labels['team'] = __( 'Team', 'sportspress' );
|
||||
if ( in_array( 'position', $this->columns ) ) $labels['position'] = __( 'Position', 'sportspress' );
|
||||
if ( in_array( 'team', $this->columns ) ) {
|
||||
$labels['team'] = __( 'Team', 'sportspress' );
|
||||
}
|
||||
if ( in_array( 'position', $this->columns ) ) {
|
||||
$labels['position'] = __( 'Position', 'sportspress' );
|
||||
}
|
||||
|
||||
$merged[0] = array_merge( $labels, $columns );
|
||||
return $merged;
|
||||
|
||||
@@ -172,8 +172,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 ) {
|
||||
@@ -181,7 +190,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,7 +572,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 );
|
||||
|
||||
@@ -565,16 +592,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;
|
||||
|
||||
|
||||
@@ -392,6 +392,9 @@ class SP_Post_types {
|
||||
'search_items' => __( 'Search', 'sportspress' ),
|
||||
'not_found' => __( 'No results found.', 'sportspress' ),
|
||||
'not_found_in_trash' => __( 'No results found.', 'sportspress' ),
|
||||
'set_featured_image' => __( 'Select Icon', 'sportspress' ),
|
||||
'remove_featured_image' => __( 'Remove icon', 'sportspress' ),
|
||||
'use_featured_image' => __( 'Add icon', 'sportspress' ),
|
||||
),
|
||||
'public' => false,
|
||||
'show_ui' => true,
|
||||
|
||||
@@ -41,6 +41,7 @@ class SportsPress_Icons {
|
||||
add_filter( 'sportspress_event_performance_icons', array( $this, 'replace_icons' ), 10, 3 );
|
||||
add_filter( 'admin_post_thumbnail_html', array( $this, 'admin_post_thumbnail_html' ), 10, 2 );
|
||||
add_action( 'sportspress_process_sp_performance_meta', array( $this, 'save' ), 10, 2 );
|
||||
add_action( 'sportspress_process_sp_statistic_meta', array( $this, 'save' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,6 +92,12 @@ class SportsPress_Icons {
|
||||
'racing-flag',
|
||||
'shoe',
|
||||
'card',
|
||||
'league',
|
||||
'shield',
|
||||
'tshirt',
|
||||
'whistle',
|
||||
'time',
|
||||
'friendly',
|
||||
'sub',
|
||||
'update',
|
||||
'undo',
|
||||
@@ -143,7 +150,7 @@ class SportsPress_Icons {
|
||||
|
||||
// Bypass if not performance post type
|
||||
$post_type = get_post_type( $id );
|
||||
if ( 'sp_performance' !== $post_type ) return $content;
|
||||
if ( 'sp_performance' !== $post_type && 'sp_statistic' !== $post_type ) return $content;
|
||||
|
||||
// Detect if image uploaded
|
||||
$is_uploaded = isset( $_POST['thumbnail_id'] );
|
||||
|
||||
@@ -53,7 +53,7 @@ if ( isset( $columns ) && null !== $columns ):
|
||||
endif;
|
||||
$data = $list->data();
|
||||
|
||||
// The first row should be column labels
|
||||
// The first row should be labels
|
||||
$labels = $data[0];
|
||||
|
||||
//Create a unique identifier based on the current time in microseconds
|
||||
@@ -62,7 +62,7 @@ $identifier = uniqid( 'playerlist_' );
|
||||
if ( true == $responsive ){
|
||||
//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] );
|
||||
|
||||
if ( $grouping === null || $grouping === 'default' ):
|
||||
@@ -122,6 +122,25 @@ foreach ( $groups as $group ):
|
||||
if ( intval( $number ) > 0 )
|
||||
$limit = $number;
|
||||
|
||||
$thead = '<thead>' . '<tr>';
|
||||
|
||||
if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ):
|
||||
if ( in_array( $orderby, array( 'number', 'name' ) ) ):
|
||||
$thead .= '<th class="data-number">#</th>';
|
||||
else:
|
||||
$thead .= '<th class="data-rank">' . __( 'Rank', 'sportspress' ) . '</th>';
|
||||
endif;
|
||||
endif;
|
||||
|
||||
foreach( $labels as $key => $label ):
|
||||
if ( $key !== 'number' && ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) ) )
|
||||
$thead .= '<th class="data-' . $key . '">'. $label . '</th>';
|
||||
if ( preg_match ( "/title=\"(.*?)\"/", $label, $new_label ) )
|
||||
$labels[$key] = $label[1];
|
||||
endforeach;
|
||||
|
||||
$thead .= '</tr>' . '</thead>';
|
||||
|
||||
$tbody = '';
|
||||
|
||||
foreach( $data as $player_id => $row ): if ( empty( $group->term_id ) || has_term( $group->term_id, 'sp_position', $player_id ) ):
|
||||
@@ -213,22 +232,9 @@ foreach ( $groups as $group ):
|
||||
endif;
|
||||
|
||||
$output .= '<div class="sp-table-wrapper">' .
|
||||
'<table class="sp-player-list sp-data-table' . ( $sortable ? ' sp-sortable-table' : '' ). ( $responsive ? ' sp-responsive-table '.$identifier : '' ) . ( $scrollable ? ' sp-scrollable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>';
|
||||
'<table class="sp-player-list sp-data-table' . ( $sortable ? ' sp-sortable-table' : '' ). ( $responsive ? ' sp-responsive-table '.$identifier : '' ) . ( $scrollable ? ' sp-scrollable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">';
|
||||
|
||||
if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ):
|
||||
if ( in_array( $orderby, array( 'number', 'name' ) ) ):
|
||||
$output .= '<th class="data-number">#</th>';
|
||||
else:
|
||||
$output .= '<th class="data-rank">' . __( 'Rank', 'sportspress' ) . '</th>';
|
||||
endif;
|
||||
endif;
|
||||
|
||||
foreach( $labels as $key => $label ):
|
||||
if ( $key !== 'number' && ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) ) )
|
||||
$output .= '<th class="data-' . $key . '">'. $label . '</th>';
|
||||
endforeach;
|
||||
|
||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||
$output .= $thead . '<tbody>';
|
||||
|
||||
$output .= $tbody;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user