Multi_Sort Issue
-
Hi,
I’ve been using the baseball.php for Netball because I needed extra fields such as RF (changed to Goals For), RA (changed to Goal Againts) and SO (changed to Goal Difference). I removed Pct and Games Behind as it is automatically generated. Everything is working fine. But one thing is not right when it comes to ranking. it ranks based on Match Won and Match Lost. It also ranks well based on Pts. But I want it to rank as well based on SO (Shutouts on baseball but I changed it to Goal Difference) after sorting it based on won, lost and pts.
I did try to changed the codes function rankTeams( $league_id ) located on /sports/baseball.php but nothing happened.
function rankTeams( $teams ) { $won = $lost = array(); foreach ( $teams AS $key => $row ) { $won[$key] = $row->won_matches; $lost[$key] = $row->lost_matches; $shutouts = $row->won_matches; } array_multisort( $won, SORT_DESC, $lost, SORT_ASC, $shutouts, SORT_DESC, $teams ); return $teams; }
I am trying to change the ones on /lib/core.php but I cant. Please help me. Here is the code.
function rankTeams( $league_id ) { global $wpdb; $league = $this->getLeague( $league_id ); if ( !isset($season) ) $season = $this->getSeason($league); $season = is_array($season) ? $season['name'] : $season; // rank Teams in groups $groups = !empty($league->groups) ? explode(";", $league->groups) : array( '' ); foreach ( $groups AS $group ) { $team_args = array("league_id" => $league_id, "season" => $season); if ( !empty($group) ) $team_args["group"] = $group; $teams = $teamsTmp = array(); foreach ( $this->getTeams( $team_args ) AS $team ) { $team->diff = ( $team->diff > 0 ) ? '+'.$team->diff : $team->diff; $team->points = array( 'plus' => $team->points_plus, 'minus' => $team->points_minus ); $team->points2 = array( 'plus' => $team->points2_plus, 'minus' => $team->points2_minus ); $team->winPercent = ($team->done_matches > 0) ? ($team->won_matches/$team->done_matches) * 100 : 0; $teams[] = $team; $teamsTmp[] = $team; } if ( !empty($teams) && $league->team_ranking == 'auto' ) { if ( has_filter( 'rank_teams_'.$league->sport ) ) { $teams = apply_filters( 'rank_teams_'.$league->sport, $teams ); } else { foreach ( $teams AS $key => $row ) { $points[$key] = $row->points['plus'] + $row->add_points; $done[$key] = $row->done_matches; } array_multisort($points, SORT_DESC, $done, SORT_ASC, $teams); } } updateRanking( $league_id, $season, $group, $teams, $teamsTmp ); } return true; }
Thanks in advance.
Geo
- The topic ‘Multi_Sort Issue’ is closed to new replies.