예제 #1
0
 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);
 }
예제 #2
0
 function process()
 {
     $games = Game::load_many(array('league_id' => $this->league->league_id, '_order' => 'g.game_date,g.game_id'));
     if (!is_array($games)) {
         error_exit("There are no games scheduled for this league");
     }
     $s = new Spirit();
     $s->display_numeric_sotg = $this->league->display_numeric_sotg();
     // Start the output, let the browser know what type it is
     header('Content-type: text/x-csv');
     header("Content-Disposition: attachment; filename=\"spirit{$this->league_id}.csv\"");
     $out = fopen('php://output', 'w');
     $header = array_merge(array('Game #', 'Date', 'Giver Name', 'Giver ID', 'Given To', 'Given To ID', 'SOTG Total'), (array) $s->question_headings(), array('Comments'));
     fputcsv($out, $header);
     while (list(, $game) = each($games)) {
         $teams = array($game->home_team => $game->home_name, $game->away_team => $game->away_name);
         while (list($giver, $giver_name) = each($teams)) {
             $recipient = $game->get_opponent_id($giver);
             # Fetch spirit answers for games
             $entry = $game->get_spirit_entry($recipient);
             if (!$entry) {
                 $entry = array(comments => 'Team did not submit a spirit rating');
             }
             $thisrow = array($game->game_id, strftime('%a %b %d %Y', $game->timestamp), $giver_name, $giver, $teams[$recipient], $recipient, $entry['numeric_sotg'], $entry['timeliness'], $entry['rules_knowledge'], $entry['sportsmanship'], $entry['rating_overall'], $entry['score_entry_penalty'], $entry['comments']);
             fputcsv($out, $thisrow);
         }
     }
     fclose($out);
     // Returning would cause the Leaguerunner menus to be added
     exit;
 }
예제 #3
0
 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;
 }
예제 #4
0
 function process()
 {
     global $lr_session;
     $this->title = "{$this->team->name} » Spirit";
     $this->template_name = 'pages/team/spirit.tpl';
     // load the league
     $league = League::load(array('league_id' => $this->team->league_id));
     // if the person doesn't have permission to see this team's spirit, bail out
     if (!$lr_session->has_permission('team', 'view', $this->team->team_id, 'spirit')) {
         error_exit("You do not have permission to view this team's spirit results");
     }
     if ($league->display_sotg == 'coordinator_only' && !$lr_session->is_coordinator_of($league->league_id)) {
         error_exit("Spirit results are restricted to coordinator-only");
     }
     $s = new Spirit();
     $s->display_numeric_sotg = $league->display_numeric_sotg();
     /*
      * Grab schedule info
      */
     $games = Game::load_many(array('either_team' => $this->team->team_id, '_order' => 'g.game_date'));
     if (!is_array($games)) {
         error_exit('There are no games scheduled for this team');
     }
     $this->smarty->assign('question_keys', array_merge(array('full'), $s->question_keys(), array('score_entry_penalty')));
     $this->smarty->assign('question_headings', $s->question_headings());
     $this->smarty->assign('num_spirit_columns', count($s->question_headings()) + 1);
     $this->smarty->assign('num_comment_columns', count($s->question_headings()) + 2);
     $rows = array();
     foreach ($games as $game) {
         if (!$game->is_finalized()) {
             continue;
         }
         if ($game->home_id == $this->team->team_id) {
             $opponent_id = $game->away_id;
             $opponent_name = $game->away_name;
             $home_away = '(home)';
         } else {
             $opponent_id = $game->home_id;
             $opponent_name = $game->home_name;
             $home_away = '(away)';
         }
         $thisrow = array('game_id' => $game->game_id, 'day_id' => $game->day_id, 'given_by_id' => $opponent_id, 'given_by_name' => $opponent_name, 'has_entry' => 0);
         # Fetch spirit answers for games
         $entry = $game->get_spirit_entry($this->team->team_id);
         if (!$entry) {
             $rows[] = $thisrow;
             continue;
         }
         $thisrow['has_entry'] = 1;
         // can only see comments if you're a coordinator
         if ($lr_session->has_permission('league', 'view', $this->team->league_id, 'spirit')) {
             $thisrow['comments'] = $entry['comments'];
         }
         $thisrow = array_merge($thisrow, (array) $s->fetch_game_spirit_items_html($entry));
         $rows[] = $thisrow;
     }
     $this->smarty->assign('spirit_detail', $rows);
     return true;
 }
예제 #5
0
 function process()
 {
     global $lr_session;
     $this->title = "{$this->league->fullname} » Spirit";
     $this->template_name = 'pages/league/spirit.tpl';
     $s = new Spirit();
     $s->display_numeric_sotg = $this->league->display_numeric_sotg();
     $this->smarty->assign('question_headings', $s->question_headings());
     $this->smarty->assign('spirit_summary', $s->league_sotg($this->league));
     $this->smarty->assign('spirit_avg', $s->league_sotg_averages($this->league));
     $this->smarty->assign('spirit_dev', $s->league_sotg_std_dev($this->league));
     if (!$lr_session->is_coordinator_of($this->league)) {
         return true;
     }
     $games = Game::load_many(array('league_id' => $this->league->league_id, '_order' => 'g.game_date,g.game_id'));
     if (!is_array($games)) {
         error_exit("There are no games scheduled for this league");
     }
     $this->smarty->assign('question_keys', array_merge(array('full'), $s->question_keys(), array('score_entry_penalty')));
     $this->smarty->assign('num_spirit_columns', count($s->question_headings()) + 1);
     $this->smarty->assign('num_comment_columns', count($s->question_headings()) + 2);
     $rows = array();
     foreach ($games as $game) {
         $teams = array($game->home_team => $game->home_name, $game->away_team => $game->away_name);
         while (list($giver, ) = each($teams)) {
             $recipient = $game->get_opponent_id($giver);
             $thisrow = array('game_id' => $game->game_id, 'day_id' => $game->day_id, 'given_by_id' => $giver, 'given_by_name' => $teams[$giver], 'given_to_id' => $recipient, 'given_to_name' => $teams[$recipient], 'has_entry' => 0);
             # Fetch spirit answers for games
             $entry = $game->get_spirit_entry($recipient);
             if (!$entry) {
                 $rows[] = $thisrow;
                 continue;
             }
             $thisrow['has_entry'] = 1;
             $thisrow = array_merge($thisrow, (array) $s->fetch_game_spirit_items_html($entry));
             $thisrow['comments'] = $entry['comments'];
             $rows[] = $thisrow;
         }
     }
     $this->smarty->assign('spirit_detail', $rows);
     return true;
 }
예제 #6
0
 /**
  * @param \Illuminate\Database\Eloquent\Model $user
  * @param array $data
  */
 public function createUserRelatedRecords($user, $data = [])
 {
     if (isset($data['groups'])) {
         foreach ($data['groups'] as $groupID) {
             if ($groupID == Group::users) {
                 continue;
             }
             \Sentinel::getUserGroupProvider()->attach($user->getAttribute('id'), $groupID);
         }
     }
     //In every case, we attach the user to the user group.
     \Sentinel::getUserGroupProvider()->attachToUsersGroup($user->getAttribute('id'));
     return \Spirit::getPersonProvider()->createPerson($data);
 }
예제 #7
0
 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;
 }
예제 #8
0
 function perform($edit)
 {
     global $lr_session;
     if (!$this->can_edit) {
         error_exit("You do not have permission to edit this game");
     }
     $s = new Spirit();
     $home_spirit = $s->as_formbuilder();
     $away_spirit = $s->as_formbuilder();
     if ($_POST['spirit_home']) {
         $home_spirit->bulk_set_answers($_POST['spirit_home']);
     }
     if ($_POST['spirit_away']) {
         $away_spirit->bulk_set_answers($_POST['spirit_away']);
     }
     $dataInvalid = $this->isDataInvalid($edit);
     if ($edit['status'] == 'normal') {
         $dataInvalid .= $home_spirit->answers_invalid();
         $dataInvalid .= $away_spirit->answers_invalid();
     }
     if ($dataInvalid) {
         error_exit($dataInvalid . "<br>Please use your back button to return to the form, fix these errors, and try again");
     }
     // store the old info:
     $oldgameresults['home_score'] = $this->game->home_score;
     $oldgameresults['away_score'] = $this->game->away_score;
     // Now, finalize score.
     $this->game->set('home_score', $edit['home_score']);
     $this->game->set('away_score', $edit['away_score']);
     $this->game->set('status', $edit['status']);
     $this->game->set('approved_by', $lr_session->attr_get('user_id'));
     // For a normal game, save spirit entries.
     if ($edit['status'] == 'normal') {
         # TODO: don't need to do this unless there are changes.
         if (!$s->store_spirit_entry($this->game, $this->game->home_id, $lr_session->attr_get('user_id'), $home_spirit->bulk_get_answers())) {
             error_exit("Error saving spirit entry for " . $this->game->home_name);
         }
         if (!$s->store_spirit_entry($this->game, $this->game->away_id, $lr_session->attr_get('user_id'), $away_spirit->bulk_get_answers())) {
             error_exit("Error saving spirit entry for " . $this->game->away_name);
         }
     }
     switch ($edit['status']) {
         // for defaults, have to prepare both home and away spirit scores!
         case 'normal':
         default:
             break;
     }
     // load the teams in order to be able to save their current rating
     $home_team = Team::load(array('team_id' => $this->game->home_id));
     $away_team = Team::load(array('team_id' => $this->game->away_id));
     // only save the current team ratings if we didn't already save them
     if ($this->game->rating_home == null || $this->game->rating_home == "" && $this->game->rating_away == null || $this->game->rating_away == "") {
         // save the current snapshot of each team's rating:
         $this->game->set('rating_home', $home_team->rating);
         $this->game->set('rating_away', $away_team->rating);
     }
     if (!$this->game->save()) {
         error_exit("Could not successfully save game results");
     }
     return true;
 }
 public function updateAccountPerson(PersonUpdate $apu)
 {
     Flash::successUpdate(2);
     \Spirit::getPersonProvider()->updatePerson(\Auth::user()->getAttribute('person_id'), $apu->sanitize());
     return \Redirect::back();
 }