function render_standings() { $s = new Spirit(); if ($this->league->schedule_type == 'none') { error_exit("This league does not have a schedule or standings."); } list($order, $season, $round) = $this->league->calculate_standings(array('round' => $current_round)); $teams = array(); while (list(, $id) = each($order)) { $team =& $season[$id]; switch ($this->league->schedule_type) { case 'ratings_ladder': case 'ratings_wager_ladder': $team->rank = $team->rating; break; default: $team->rank = ++$rank; } $team->standing_points = 2 * $team->win + $team->tie; $team->plusminus = $team->points_for - $team->points_against; if ($this->league->display_numeric_sotg) { if ($team->games > 3) { $team->numeric_sotg = printf("%.2f", $s->average_sotg($team->spirit)); } } $teams[] = $team; } $this->smarty->assign('teams', $teams); }
function process() { global $lr_session; $this->title = "{$this->league->fullname} » Standings"; $this->template_name = 'pages/league/standings.tpl'; if ($this->league->schedule_type == 'none') { error_exit("This league does not have a schedule or standings."); } $s = new Spirit(); $round = $_GET['round']; if (!isset($round)) { $round = $this->league->current_round; } // check to see if this league is on round 2 or higher... // if so, set the $current_round so that the standings table is split up if ($round > 1) { $current_round = $round; } // TODO: calculate_standings should set the ->round_XXX values on each team object list($order, $season, $round) = $this->league->calculate_standings(array('round' => $current_round)); $teams = array(); $seed = 1; while (list(, $tid) = each($order)) { $team = $season[$tid]; $team->seed = $seed++; // Don't need the current round for a ladder schedule. if ($this->league->schedule_type == "roundrobin") { if ($current_round) { $team->round_win = $round[$tid]->win; $team->round_loss = $round[$tid]->loss; $team->round_tie = $round[$tid]->tie; $team->round_defaults_against = $round[$tid]->defaults_against; $team->round_points_for = $round[$tid]->points_for; $team->round_points_against = $round[$tid]->points_against; } } // TODO: should be a helper on the Team object if (count($team->streak) > 1) { $team->display_streak = count($team->streak) . $team->streak[0]; } else { $team->display_streak = '-'; } $team->sotg_average = $s->average_sotg($team->spirit, false); $team->sotg_image = $s->full_spirit_symbol_html($team->sotg_average); $teams[] = $team; } $this->smarty->assign('league', $this->league); $this->smarty->assign('teams', $teams); $this->smarty->assign('highlight_team', $this->teamid); $this->smarty->assign('display_round', $current_round > 1); return true; }
function standings_sort_bywinloss(&$a, &$b) { /* First, order by wins */ $b_points = 2 * $b->win + $b->tie; $a_points = 2 * $a->win + $a->tie; if ($a_points > $b_points) { return -1; } else { if ($a_points < $b_points) { return 1; } } /* Then, check head-to-head wins */ if (isset($b->vs[$a->team_id]) && isset($a->vs[$b->team_id])) { if ($b->vs[$a->team_id] > $a->vs[$b->team_id]) { return 1; } else { if ($b->vs[$a->team_id] < $a->vs[$b->team_id]) { return -1; } } } $s = new Spirit(); /* Check SOTG */ if ($s->average_sotg($a->spirit, true) > $s->average_sotg($b->spirit, true)) { return -1; } elseif ($s->average_sotg($a->spirit, true) < $s->average_sotg($b->spirit, true)) { return 1; } /* Next, check +/- */ if ($b->points_for - $b->points_against > $a->points_for - $a->points_against) { return 1; } else { if ($b->points_for - $b->points_against > $a->points_for - $a->points_against) { return -1; } } /* * Finally, check losses. This ensures that teams with no record * appear above teams who have losses. */ if ($a->loss < $b->loss) { return -1; } else { if ($a->loss > $b->loss) { return 1; } } return 0; }