diff --git a/assets/css/admin.css b/assets/css/admin.css index 304018f2..69270372 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -194,6 +194,11 @@ table.widefat.sp-data-table input[type="number"] { width: 100%; } +table.widefat.sp-data-table input.small-text { + width: 50px; + min-width: 0; +} + table.widefat.sp-data-table input.name { min-width: 0; width: auto; diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php index bdb855ca..100dca61 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php @@ -60,6 +60,16 @@ class SP_Meta_Box_Event_Performance { # + + + + + + + $label ): ?> @@ -80,10 +90,28 @@ class SP_Meta_Box_Event_Performance { foreach ( $data as $player_id => $player_performance ): if ( !$player_id ) continue; $number = get_post_meta( $player_id, 'sp_number', true ); + $value = sp_array_value( $player_performance, 'number', '' ); ?> - + + + + + 'sp_position', + 'name' => 'sp_players[' . $team_id . '][' . $player_id . '][position]', + 'values' => 'term_id', + 'selected' => $selected + ); + sp_dropdown_taxonomies( $args ); + ?> + $label ): $value = sp_array_value( $player_performance, $column, '' ); ?> @@ -104,6 +132,7 @@ class SP_Meta_Box_Event_Performance {   +   $label ): $player_id = 0; $player_performance = sp_array_value( $data, 0, array() ); diff --git a/includes/class-sp-event.php b/includes/class-sp-event.php index b3186d1f..e1ab5ea7 100644 --- a/includes/class-sp-event.php +++ b/includes/class-sp-event.php @@ -58,7 +58,6 @@ class SP_Event extends SP_Custom_Post{ $performance = (array)get_post_meta( $this->ID, 'sp_players', true ); $labels = sp_get_var_labels( 'sp_performance' ); $columns = get_post_meta( $this->ID, 'sp_columns', true ); - $output = array(); foreach( $teams as $i => $team_id ): $players = sp_array_between( (array)get_post_meta( $this->ID, 'sp_player', false ), 0, $i ); $data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) ); @@ -74,6 +73,12 @@ class SP_Event extends SP_Custom_Post{ $totals[ $key ] += sp_array_value( $player_performance, $key, 0 ); endif; endforeach; + if ( ! array_key_exists( 'number', $player_performance ) || $player_performance['number'] == null ): + $performance[ $team_id ][ $player_id ]['number'] = get_post_meta( $player_id, 'sp_number', true ); + endif; + if ( ! array_key_exists( 'position', $player_performance ) || $player_performance['position'] == null ): + $performance[ $team_id ][ $player_id ]['position'] = get_post_meta( $player_id, 'sp_position', true ); + endif; endforeach; foreach( $totals as $key => $value ): @@ -82,34 +87,13 @@ class SP_Event extends SP_Custom_Post{ $totals[ $key ] = $manual_total; endif; endforeach; - - $lineup = array_filter( $data, array( $this, 'lineup_filter' ) ); - $subs = array_filter( $data, array( $this, 'sub_filter' ) ); - - foreach ( $subs as $player_id => $player ): - if ( ! $player_id ) - continue; - - $sub = sp_array_value( $player, 'sub', 0 ); - - if ( ! $sub ) - continue; - - $lineup[ $sub ]['sub'] = $player_id; - endforeach; - - $output[ $team_id ] = array( - 'lineup' => $lineup, - 'subs' => $subs, - 'total' => $totals - ); endforeach; if ( $admin ): return array( $labels, $columns, $performance, $teams ); else: - // Add status to performance labels - $labels['status'] = __( 'Status', 'sportspress' ); + // Add position to performance labels + $labels = array_merge( array( 'position' => __( 'Position', 'sportspress' ) ), $labels ); if ( ! is_array( $columns ) ) $columns = array(); foreach ( $labels as $key => $label ): diff --git a/templates/event-performance.php b/templates/event-performance.php index a307450a..5687bd40 100644 --- a/templates/event-performance.php +++ b/templates/event-performance.php @@ -86,9 +86,9 @@ foreach( $teams as $index => $team_id ): if ( ! $name ) continue; - echo ''; + echo ''; - $number = get_post_meta( $player_id, 'sp_number', true ); + $number = sp_array_value( $row, 'number', ' ' ); // Player number echo '' . $number . ''; @@ -99,11 +99,12 @@ foreach( $teams as $index => $team_id ): if ( isset( $row['status'] ) && $row['status'] == 'sub' ): $name = '(' . $name . ')'; endif; - if ( array_key_exists( $player_id, $lineup_sub_relation ) ): - $name .= ' ' . get_post_meta( $lineup_sub_relation[ $player_id ], 'sp_number', true ) . ''; - elseif ( isset( $row['sub'] ) && $row['sub'] ): - $name .= ' ' . get_post_meta( $row['sub'], 'sp_number', true ) . ''; - endif; + endif; + + if ( array_key_exists( $player_id, $lineup_sub_relation ) ): + $name .= ' ' . sp_array_value( sp_array_value( $data, $lineup_sub_relation[ $player_id ], array() ), 'number', null ) . ''; + elseif ( isset( $row['sub'] ) && $row['sub'] ): + $name .= ' ' . sp_array_value( sp_array_value( $data, $row['sub'], array() ), 'number', null ) . ''; endif; echo '' . $name . ''; @@ -112,10 +113,19 @@ foreach( $teams as $index => $team_id ): foreach( $labels as $key => $label ): if ( $key == 'name' ) continue; - if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): - $value = $row[ $key ]; + if ( $key == 'position' ): + if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): + $position = get_term_by( 'id', $row[ $key ], 'sp_position' ); + $value = $position->name; + else: + $value = '—'; + endif; else: - $value = 0; + if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): + $value = $row[ $key ]; + else: + $value = 0; + endif; endif; if ( ! array_key_exists( $key, $totals ) ): $totals[ $key ] = 0;