diff --git a/assets/js/admin/editor-lang.php b/assets/js/admin/editor-lang.php index 4f8ed23c..4bf69df6 100644 --- a/assets/js/admin/editor-lang.php +++ b/assets/js/admin/editor-lang.php @@ -12,9 +12,7 @@ $strings = 'tinyMCE.addI18n({' . _WP_Editors::$mce_locale . ':{ countdown: "' . esc_js( __( 'Countdown', 'sportspress' ) ) . '", performance: "' . esc_js( __( 'Performance', 'sportspress' ) ) . '", calendar: "' . esc_js( __( 'Calendar', 'sportspress' ) ) . '", - team: "' . esc_js( __( 'Team', 'sportspress' ) ) . '", statistics: "' . esc_js( __( 'Statistics', 'sportspress' ) ) . '", - table_columns: "' . esc_js( __( 'Table Columns', 'sportspress' ) ) . '", league_table: "' . esc_js( __( 'League Table', 'sportspress' ) ) . '", player_list: "' . esc_js( __( 'Player List', 'sportspress' ) ) . '", list: "' . esc_js( __( 'List', 'sportspress' ) ) . '", diff --git a/assets/js/admin/editor.js b/assets/js/admin/editor.js index c1762afb..ac9d4f15 100644 --- a/assets/js/admin/editor.js +++ b/assets/js/admin/editor.js @@ -88,21 +88,6 @@ } ] }, - { - text: ed.getLang( 'sportspress.team' ), - menu: [ - { - text: ed.getLang( 'sportspress.table_columns' ), - onclick: function() { - // triggers the thickbox - var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width; - W = W - 80; - H = H - 84; - tb_show( ed.getLang( 'sportspress.team' ) + ' - ' + ed.getLang( 'sportspress.table_columns' ), 'admin-ajax.php?action=sportspress_team_columns_shortcode&width=' + W + '&height=' + H ); - } - } - ] - }, { text: ed.getLang( 'sportspress.league_table' ), onclick : function() { diff --git a/includes/admin/post-types/class-sp-admin-meta-boxes.php b/includes/admin/post-types/class-sp-admin-meta-boxes.php index e46305a7..acb64f5e 100644 --- a/includes/admin/post-types/class-sp-admin-meta-boxes.php +++ b/includes/admin/post-types/class-sp-admin-meta-boxes.php @@ -63,6 +63,7 @@ class SP_Admin_Meta_Boxes { add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Details::save', 10, 2 ); add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Columns::save', 20, 2 ); add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Lists::save', 30, 2 ); + add_action( 'sportspress_process_sp_team_meta', 'SP_Meta_Box_Team_Tables::save', 40, 2 ); // Save Table Meta Boxes add_action( 'sportspress_process_sp_table_meta', 'SP_Meta_Box_Table_Details::save', 10, 2 ); @@ -141,6 +142,7 @@ class SP_Admin_Meta_Boxes { if ( isset( $post ) && isset( $post->ID ) ): add_meta_box( 'sp_columnssdiv', __( 'Table Columns', 'sportspress' ), 'SP_Meta_Box_Team_Columns::output', 'sp_team', 'normal', 'high' ); add_meta_box( 'sp_listsdiv', __( 'Player Lists', 'sportspress' ), 'SP_Meta_Box_Team_Lists::output', 'sp_team', 'normal', 'high' ); + add_meta_box( 'sp_tablesdiv', __( 'League Tables', 'sportspress' ), 'SP_Meta_Box_Team_Tables::output', 'sp_team', 'normal', 'high' ); endif; add_meta_box( 'sp_editordiv', __( 'Profile', 'sportspress' ), 'SP_Meta_Box_Team_Editor::output', 'sp_team', 'normal', 'low' ); @@ -161,7 +163,7 @@ class SP_Admin_Meta_Boxes { add_meta_box( 'sp_editordiv', __( 'Profile', 'sportspress' ), 'SP_Meta_Box_Player_Editor::output', 'sp_player', 'normal', 'low' ); // Lists - add_meta_box( 'sp_shortcodediv', __( 'Shortcode', 'sportspress' ), 'SP_Meta_Box_List_Shortcode::output', 'sp_list', 'side', 'default' ); + add_meta_box( 'sp_shortcodediv', __( 'Shortcode', 'sportspress' ), 'SP_Meta_Box_List_Shortcode::output', 'sp_table', 'side', 'default' ); add_meta_box( 'sp_formatdiv', __( 'Layout', 'sportspress' ), 'SP_Meta_Box_List_Format::output', 'sp_list', 'side', 'default' ); add_meta_box( 'sp_columnsdiv', __( 'Columns', 'sportspress' ), 'SP_Meta_Box_List_Columns::output', 'sp_list', 'side', 'default' ); add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_List_Details::output', 'sp_list', 'side', 'default' ); diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-shortcode.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-shortcode.php deleted file mode 100644 index 2bb82fdb..00000000 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-shortcode.php +++ /dev/null @@ -1,32 +0,0 @@ - -

- -

-

- -

-

- tables( true ); + self::table( $data, $checked ); + + else: + + printf( __( 'No results found.', 'sportspress' ) ); + + endif; + } + + /** + * Save meta box data + */ + public static function save( $post_id, $post ) { + sp_update_post_meta_recursive( $post_id, 'sp_table', sp_array_value( $_POST, 'sp_table', array() ) ); + } + + /** + * Admin edit table + */ + public static function table( $data = array(), $checked = array() ) { + ?> +
+ + + + + + + + + + + + 0 ): + $i = 0; + foreach ( $data as $table ): + $players = array_filter( get_post_meta( $table->ID, 'sp_player' ) ); + $format = get_post_meta( $table->ID, 'sp_format', true ); + ?> + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+ ID, $checked ) ); ?>> + + + post_title; ?> + + ID, 'sp_league' ) ? the_terms( $table->ID, 'sp_league' ) : '—'; ?>ID, 'sp_season' ) ? the_terms( $table->ID, 'sp_season' ) : '—'; ?>
+ +
+ +
+
+ __CLASS__ . '::event_calendar', 'event_list' => __CLASS__ . '::event_list', 'event_blocks' => __CLASS__ . '::event_blocks', - 'team_columns' => __CLASS__ . '::team_columns', 'league_table' => __CLASS__ . '::league_table', 'player_details' => __CLASS__ . '::player_details', 'player_statistics' => __CLASS__ . '::player_statistics', @@ -141,17 +140,6 @@ class SP_Shortcodes { return self::shortcode_wrapper( array( 'SP_Shortcode_Event_Blocks', 'output' ), $atts ); } - /** - * Team columns shortcode. - * - * @access public - * @param mixed $atts - * @return string - */ - public static function team_columns( $atts ) { - return self::shortcode_wrapper( array( 'SP_Shortcode_Team_Columns', 'output' ), $atts ); - } - /** * League table shortcode. * diff --git a/includes/class-sp-team.php b/includes/class-sp-team.php index 65188784..1e48b1f0 100644 --- a/includes/class-sp-team.php +++ b/includes/class-sp-team.php @@ -78,7 +78,7 @@ class SP_Team extends SP_Custom_Post { foreach ( $div_ids as $div_id ): - $totals = array( 'eventsplayed' => 0, 'streak' => 0, 'last5' => null, 'last10' => null ); + $totals = array( 'eventsplayed' => 0, 'eventminutes' => 0, 'streak' => 0, 'last5' => null, 'last10' => null ); foreach ( $result_labels as $key => $value ): $totals[ $key . 'for' ] = 0; @@ -145,6 +145,9 @@ class SP_Team extends SP_Custom_Post { foreach( $events as $event ): $results = (array)get_post_meta( $event->ID, 'sp_results', true ); + $minutes = get_post_meta( $event->ID, 'sp_minutes', true ); + if ( $minutes === '' ) $minutes = get_option( 'sportspress_event_minutes', 90 ); + foreach ( $results as $team_id => $team_result ): foreach ( $team_result as $key => $value ): if ( $team_id == $this->ID ): @@ -159,8 +162,9 @@ class SP_Team extends SP_Custom_Post { // Increment events played and outcome count if ( array_key_exists( $outcome, $totals ) ): - $totals['eventsplayed']++; - $totals[ $outcome ]++; + $totals['eventsplayed'] ++; + $totals['eventminutes'] += $minutes; + $totals[ $outcome ] ++; endif; if ( $outcome && $outcome != '-1' ): @@ -307,4 +311,38 @@ class SP_Team extends SP_Custom_Post { return $lists; endif; } + + /** + * Returns league tables + * + * @access public + * @return array + */ + public function tables( $admin = false ) { + if ( ! $this->ID ) return null; + + $args = array( + 'post_type' => 'sp_table', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC', + 'meta_key' => 'sp_team', + 'meta_value' => $this->ID, + ); + $tables = get_posts( $args ); + + $checked = (array) get_post_meta( $this->ID, 'sp_table' ); + + if ( $admin ): + return array( $tables, $checked ); + else: + foreach ( $tables as $key => $table ): + if ( ! in_array( $table->ID, $checked ) ): + unset( $tables[ $key ] ); + endif; + endforeach; + return $tables; + endif; + } } diff --git a/includes/shortcodes/class-sp-shortcode-team-columns.php b/includes/shortcodes/class-sp-shortcode-team-columns.php deleted file mode 100644 index 242522a1..00000000 --- a/includes/shortcodes/class-sp-shortcode-team-columns.php +++ /dev/null @@ -1,24 +0,0 @@ -columns( $league->term_id ); - - if ( sizeof( $data ) <= 1 ) - continue; - - // The first row should be column labels - $labels = $data[0]; - - // Remove the first row to leave us with the actual data - unset( $data[0] ); - - $output .= '

' . $league->name . '

' . - '
' . - '' . '' . ''; - - foreach( $labels as $key => $label ): - $output .= ''; - endforeach; - - $output .= '' . '' . ''; - - $i = 0; - - foreach( $data as $season_id => $row ): - - $output .= ''; - - foreach( $labels as $key => $value ): - $output .= ''; - endforeach; - - $output .= ''; - - $i++; - - endforeach; - - $output .= '' . '
' . $label . '
' . sp_array_value( $row, $key, '—' ) . '
' . '
'; - - -endforeach; - -?> -
- -
\ No newline at end of file diff --git a/templates/team-tables.php b/templates/team-tables.php new file mode 100644 index 00000000..4b0eed16 --- /dev/null +++ b/templates/team-tables.php @@ -0,0 +1,30 @@ +tables(); + +foreach ( $tables as $table ): + if ( ! $table ) continue; + + if ( sizeof( $tables ) > 1 ): + ?> +

post_title; ?>

+ $table->ID, 'highlight' => $id ) ); +endforeach; +?> +
\ No newline at end of file