<?php
/**
* Scores Processor
*
* This file should be run via cron. I recommend every 10 minutes, 2 minutes after stats run. It updates the game methods.
* I leave this out of the stats process itself because it's already busy enough.
*
* that line would look like:
*
* 2,12,22,32,42,52 * * * * /path/to/php /path/to/processscores.php
*
* alternately, win32 servers can use pycron (http://www.kalab.com/freeware/pycron/pycron.htm)
* and have a line like
*
* 2,12,22,32,42,52 * * * * "c:\path\to\php" "c:\path\to\processscores.php"
*
* Since you're not accessing this via the web, you should place it outside of your document root.
* There are no permission checks; therefore, anyone could prematurely execute a waiver claim if the
* file is public. Security through obscurity is a poor substitute.
*
* @author Stephen Rochelle <hide@address.com>
* @version OFFL v0.2
* @copyright Copyright (c) 2004 Stephen Rochelle. Some rights reserved.
* @package offl-maint
*/
$pageTitle = "Fantasy Score Processing";
$public = TRUE;
$maintenance = TRUE;
require_once("offlconfig.php");
require_once($DOC_ROOT . "/lib/header.php");
if (!isset($_GET["year"]))
{ $_GET["year"] = getThisYear(); }
if (!isset($_GET["week"]))
{ $_GET["week"] = getCurrentWeek($_GET["year"]); }
echo "<h2>" . $_GET["year"] . " Week " . $_GET["week"] . " Scores</h2>\n";
// check to see if this is the current week (and use players for roster)
// or a past week (and use pastrosters for roster)
$curr_year = getThisYear();
$curr_week = getCurrentWeek($curr_year);
$playerStat_lookup = new OFFL_PlayerStat();
$current = FALSE;
if (($curr_week == $_GET["week"]) && ($curr_year == $_GET["year"]))
{ $current = TRUE; }
// find the final game of the week so I can setFinal() if needed
$x = new OFFL_NFLGame();
$weekGames = $x->getNFLGames($_GET["year"], $_GET["week"]);
$gametime = 0;
foreach ($weekGames as $nfl_game)
{
if ($nfl_game->getGametime() > $gametime)
{ $gametime = $nfl_game->getGametime(); }
}
$final = 0;
if ( (time()-$gametime) > (5*3600) ) // 5 hours past start time of last weekly game
{ $final = 1; }
// *********************************************
// start checking for new compatibility here!!!
// *********************************************
$x = new OFFL_Game();
$games = $x->getGames(NULL, $_GET["year"], $_GET["week"]);
foreach ($games as $game)
{
$hTeam = new OFFL_FFLTeam($game->getHFFLTeamID());
$vTeam = new OFFL_FFLTeam($game->getVFFLTeamID());
if ($current)
{
$hRosterPlayers = $hTeam->getRoster(TRUE); // get starters
$vRosterPlayers = $vTeam->getRoster(TRUE);
$hRoster = array();
$vRoster = array();
foreach ($hRosterPlayers as $player)
{ $hRoster[] = $player->getPlayerID(); }
foreach ($vRosterPlayers as $player)
{ $vRoster[] = $player->getPlayerID(); }
}
else
{
$hPastRoster = new OFFL_PastRoster($_GET["year"], $_GET["week"], $game->getHFFLTeamID());
$hRoster = array();
$hR = $hPastRoster->getPlayerIDArray();
$hS = $hPastRoster->getStarterArray();
foreach ($hR as $i=>$player_id)
{
if ($hS[$i])
{ $hRoster[] = $player_id; }
}
$vPastRoster = new OFFL_PastRoster($_GET["year"], $_GET["week"], $game->getVFFLTeamID());
$vRoster = array();
$vR = $vPastRoster->getPlayerIDArray();
$vS = $vPastRoster->getStarterArray();
foreach ($vR as $i=>$player_id)
{
if ($vS[$i])
{ $vRoster[] = $player_id; }
}
}
$hScore = 0;
$vScore = 0;
foreach ($hRoster as $player_id)
{
$stat = $playerStat_lookup->getStatsByPlayerIDYearWeek($player_id, $_GET["year"], $_GET["week"]);
if ($stat !== FALSE)
{
$stat->setLeagueID($game->getLeagueID());
$hScore += $stat->calculatePoints();
}
}
foreach ($vRoster as $player_id)
{
$stat = $playerStat_lookup->getStatsByPlayerIDYearWeek($player_id, $_GET["year"], $_GET["week"]);
if ($stat !== FALSE)
{
$stat->setLeagueID($game->getLeagueID());
$vScore += $stat->calculatePoints();
}
}
$game->setHFFLTeamScore($hScore);
$game->setVFFLTeamScore($vScore);
echo "<p>" . $vTeam->getFFLTeamFullName() . " " . $vScore . " at " . $hTeam->getFFLTeamFullName() . " " . $hScore;
if ($final)
{ echo " (Final)"; }
else
{ echo " (In Progress)"; }
echo "</p>\n";
$game->setFinal($final);
$game->save();
}
require($DOC_ROOT . "/lib/footer.php"); ?>