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; }
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; }
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; }