Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/maintenance/processrosters.php
<?php
/**
 * Processes roster archival.  Runs during MNF to ensure locked rosters
 * 
 * This file should be run via cron.  I recommend once weekly on Monday at 10PM Eastern (during the MNF game).
 * 
 * that line would look like:
 * 
 * 0 22 * * 0 /path/to/php /path/to/processrosters.php
 * 
 * alternately, win32 servers can use pycron (http://www.kalab.com/freeware/pycron/pycron.htm)
 * and have a line like
 * 
 * 0 22 * * 0 "c:\path\to\php" "c:\path\to\processrosters.php"
 * 
 * Of course, you'll have to adjust it to the proper timezone (the "22" is 10 PM on the 24-hour clock).
 * 
 * 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 = "Roster Processing";
$public = TRUE;
$maintenance = TRUE;
require_once("offlconfig.php");
require_once($DOC_ROOT . "/lib/header.php");

if (isset($_GET["year"]))
{	$year = $_GET["year"];	}
else
{	$year = getThisYear();	}
if (isset($_GET["week"]))
{	$week = $_GET["week"];	}
else
{	$week = getCurrentWeek($year);	}

/*
	Save the weekly roster for archival purposes.  Should be run during MNF so that rosters are locked in.
*/

$lg = new OFFL_League();
$FFLTeams = $lg->getAllFFLTeams(TRUE);
foreach ($FFLTeams as $team)
{
	$pastRoster = new OFFL_PastRoster($year, $week, $team->getFFLTeamID());
	$pastRoster->setLeagueID($team->getLeagueID());
	$player_id_array = array();
	$starter_array = array();
	$nflteam_id_array = array();

	$players = $team->getRoster();

	foreach ($players as $player)
	{
		$player_id_array[] = $player->getPlayerID();
		$starter_array[] = $player->getStarter();
		$nflteam_id_array[] = $player->getNFLTeamID();
	}

	$pastRoster->setPlayerIDArray($player_id_array);
	$pastRoster->setStarterArray($starter_array);
	$pastRoster->setNFLTeamIDArray($nflteam_id_array);
	$pastRoster->setLeagueID($team->getLeagueID());
	$pastRoster->save();
	echo "<p>" . $team->getFFLTeamFullName() . " roster saved for Week " . $week . ", " . $year . ".</p>\n\n";
}

require($DOC_ROOT . "/lib/footer.php"); ?>
Return current item: Online Fantasy Football League