Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/lib/classes/offl_state.php
<?php
/**
 * This file defines the OFFL_State class
 *
 * @package offl
 * @author Stephen Rochelle <hide@address.com>
 */

if (strtr(__FILE__, "\\", "/") == $_SERVER["SCRIPT_FILENAME"])
{	die ("Cannot access file directly!");	}

require_once($DOC_ROOT . "/lib/classes/offl_stub.php");
require_once($DOC_ROOT . "/lib/classes/offl_control.php");
/**
 * A class for holding basic essential OFFL parameters.  Deprecated
 *
 * This class is deprecated and has been removed from use in OFFL
 *
 * {@inheritdoc}
 * @package offl
 * @see setDefaults()
 */
class OFFL_State extends OFFL_Stub
{
	/**
	 * @var integer
	 */
	var $_year = NULL;
	/**
	 * @var integer
	 */
	var $_week = NULL;
	/**
	 * @var integer
	 */
	var $_user_id = NULL;
	/**
	 * @var integer Treat as numeric boolean (0/1)
	 */
	var $_admin = 0;
	/**
	 * @var integer
	 */
	var $_league_id = NULL;
	/**
	 * @var integer Treat as numeric boolean (0/1)
	 */
	var $_league_admin = 0;
	/**
	 * @var integer
	 */
	var $_fflteam_id = NULL;
	/**
	 * @var integer
	 */
	var $_player_id = NULL;

	/**
	 * Constructor function, presently no functionality
	 */
	function OFFL_State ()
	{
	}

	/**
	 * Sets member variables to common values
	 *
	 * Member variables of the class instance are set as follows:
	 * <ul>
	 * <li>$_year
	 *   <ol>
	 *     <li>$_GET["year"]</li>
	 *     <li>$_POST["year"]</li>
	 *     <li>Server Calendar, adjusted in Jan/Feb for preceding season year</li>
	 *   </ol>
	 * </li>
	 * <li>$_week
	 *   <ol>
	 *     <li>$_GET["week"]</li>
	 *     <li>$_POST["week"]</li>
	 *     <li>{@link getCurrentWeek()} function</li>
	 *   </ol>
	 * </li>
	 * <li>$_user_id
	 *   <ol>
	 *     <li>$_GET["user_id"]</li>
	 *     <li>$_POST["user_id"]</li>
	 *     <li>$_SESSION["user_id"]</li>
	 *     <li>Default 0</li>
	 *   </ol>
	 * </li>
	 * <li>$_admin
	 *   <ol>
	 *     <li>$_SESSION["admin"]</li>
	 *     <li>Default FALSE</li>
	 *   </ol>
	 * </li>
	 * <li>$_league_id
	 *   <ol>
	 *     <li>$_GET["league_id"]</li>
	 *     <li>$_POST["league_id"]</li>
	 *     <li>$_SESSION["league_id"]</li>
	 *     <li>Default 0</li>
	 *   </ol>
	 * </li>
	 * <li>$_league_admin
	 *   <ol>
	 *     <li>{@link $_admin}</li>
	 *     <li>Default FALSE</li>
	 *   </ol>
	 * </li>
	 * <li>$_fflteam_id
	 *   <ol>
	 *     <li>$_GET["fflteam_id"]</li>
	 *     <li>$_POST["fflteam_id"]</li>
	 *     <li>$_SESSION["fflteam_id"]</li>
	 *     <li>Default 0</li>
	 *   </ol>
	 * </li>
	 * <li>$_fflteam_id
	 *   <ol>
	 *     <li>$_GET["player_id"]</li>
	 *     <li>$_POST["player_id"]</li>
	 *     <li>Default 0</li>
	 *   </ol>
	 * </li>
	 * </ul>
	 */
	function setDefaults()
	{
		// set $_year
		if (isset($_GET["year"]))
			$this->_year = $_GET["year"];
		elseif (isset($_POST["year"]))
			$this->_year = $_POST["year"];
		else
		{
			$today = getdate();
			$this->_year = $today["year"];
			if ( ($today["month"] == "January") || ($today["month"] == "February") )
				$this->_year--;
		}

		// set $_week
		if (isset($_GET["week"]))
			$this->_week = $_GET["week"];
		elseif (isset($_POST["week"]))
			$this->_week = $_POST["week"];
		else $this->_week = $this->getCurrentWeek();

		// set $_user_id
		if (isset($_GET["user_id"]))
			$this->_user_id = $_GET["user_id"];
		elseif (isset($_POST["user_id"]))
			$this->_user_id = $_POST["user_id"];
		elseif (isset($_SESSION["user_id"]))
			$this->_user_id = $_SESSION["user_id"];
		else $this->_user_id = 0;

		// set $_admin
		if ($_SESSION["admin"] === TRUE)
			$this->_admin = TRUE;

		// set $_league_id
		if (isset($_GET["league_id"]))
			$this->_league_id = $_GET["league_id"];
		elseif (isset($_POST["league_id"]))
			$this->_league_id = $_POST["league_id"];
		elseif (isset($_SESSION["league_id"]))
			$this->_league_id = $_SESSION["league_id"];
		else $this->_league_id = 0;

		// set $_league_admin
		$this->_league_admin = $this->_admin;

		// set $_fflteam_id
		if (isset($_GET["fflteam_id"]))
			$this->_fflteam_id = $_GET["fflteam_id"];
		elseif (isset($_POST["fflteam_id"]))
			$this->_fflteam_id = $_POST["fflteam_id"];
		elseif (isset($_SESSION["fflteam_id"]))
			$this->_fflteam_id = $_SESSION["fflteam_id"];
		else $this->_fflteam_id = 0;

		// set $_player_id
		if (isset($_GET["player_id"]))
			$this->_player_id = $_GET["player_id"];
		elseif (isset($_POST["player_id"]))
			$this->_player_id = $_POST["player_id"];
		else $this->_player_id = 0;

	}

	/**
	 * Sets $_year member variable
	 * @param integer $year value placed in $_year
	 */
	function setYear($year)
	{
		$this->_year = $year;
	}

	/**
	 * Gets $_year member variable
	 * @return integer value of $_year
	 */
	function getYear()
	{
		return $this->_year;
	}

	/**
	 * Sets $_week member variable
	 * @param integer $week value placed in $_week
	 */
	function setWeek($week)
	{
		$this->_week = $week;
	}

	/**
	 * Gets $_week member variable
	 * @return integer value of $_week
	 */
	function getWeek()
	{
		return $this->_week;
	}

	/**
	 * Sets $_user_id member variable
	 * @param integer $user_id value placed in $_user_id
	 */
	function setUserID($user_id)
	{
		$this->_user_id = $user_id;
	}

	/**
	 * Gets $_user_id member variable
	 * @return integer value of $_user_id
	 */
	function getUserID()
	{
		return $this->_user_id;
	}

	/**
	 * Sets $_admin member variable
	 * @param boolean $admin value placed in $_admin
	 */
	function setAdmin($admin)
	{
		$this->_admin = $admin;
	}

	/**
	 * Gets $_admin member variable
	 * @return boolean value of $_admin
	 */
	function getAdmin()
	{
		return $this->_admin;
	}

	/**
	 * Sets $_league_id member variable
	 * @param integer $league_id value placed in $_league_id
	 */
	function setLeagueID($league_id)
	{
		$this->_league_id = $league_id;
	}

	/**
	 * Gets $_league_id member variable
	 * @return integer value of $_league_id
	 */
	function getLeagueID()
	{
		return $this->_league_id;
	}

	/**
	 * Sets $_league_admin member variable
	 * @param boolean $league_admin value placed in $_league_admin
	 */
	function setLeagueAdmin($league_admin)
	{
		$this->_league_admin = $league_admin;
	}

	/**
	 * Gets $_league_admin member variable
	 * @return boolean value of $_league_admin
	 */
	function getLeagueAdmin()
	{
		return $this->_league_admin;
	}

	/**
	 * Sets $_fflteam_id member variable
	 * @param integer $fflteam_id value placed in $_fflteam_id
	 */
	function setFFLTeamID($fflteam_id)
	{
		$this->_fflteam_id = $fflteam_id;
	}

	/**
	 * Gets $_fflteam_id member variable
	 * @return integer value of $_fflteam_id
	 */
	function getFFLTeamID()
	{
		return $this->_fflteam_id;
	}

	/**
	 * Sets $_player_id member variable
	 * @param integer $player_id value placed in $_player_id
	 */
	function setPlayerID($player_id)
	{
		$this->_player_id = $player_id;
	}

	/**
	 * Gets $_player_id member variable
	 * @return integer value of $_player_id
	 */
	function getPlayerID()
	{
		return $this->_player_id;
	}

	/**
	 * Returns the current week based on an OFFL_Control setting and $_year
	 *
	 * @return integer current week (or 1 if preseason)
	 */
	function getCurrentWeek()
	{
// TEMP FOR TESTING ONLY!!! TAKE THIS SECTION OUT
		global $localtest;
		if ($localtest)
			return 3;

		$x = new OFFL_Control();
		$season_start = $x->getControl("MISC_SEASON_START_" . $this->_year);

		list($date, $time) = explode(" ", $season_start);
		list($Y, $M, $D) = explode("-", $date);
		list($h, $i, $s) = explode(":", $time);
		$time = gmmktime($h, $i, $s, $M, $D, $Y);

		$curr_time = time() - $time;
		$week = 1;

		while ($curr_time > 0)
		{
			$curr_time -= 3600 * 24 * 7; // one week in seconds
			$week++;
		}

		return $week;
	}

} // end OFFL_State class
?>
Return current item: Online Fantasy Football League