Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/lib/classes/offl_rosterplayer.php
<?php
/**
 * Contains the implementation of the {@link OFFL_RosterPlayer} 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_dbobject.php");
/**
 * New specification for {@link OFFL_FFLTeam FFL team} roster info.
 *
 * This was part of the player class in earlier versions of FFL, but has been broken out to accomodate multiple leagues.
 * Additionally, this has been broken out of the 0.1.x OFFL {@link OFFL_FFLTeam} class as database load was unacceptable.
 *
 * @package offl
 */
class OFFL_RosterPlayer extends OFFL_DBObject
{
	/**
	 * @var integer
	 */
	var $_player_id = NULL;
	/**
	 * @var integer
	 */
	var $_league_id = NULL;
	/**
	 * @var integer Integral boolean value (0/1)
	 */
	var $_starter = 0;
	/**
	 * @var integer {@link OFFL_FFLTeam} {@link OFFL_FFLTeam::_fflteam_id id} (0 if not on a team)
	 */
	var $_fflteam_id = 0;

	/**
	 * Constructor
	 *
	 * Both parameters should be set together or not at all
	 * @param integer $player_id Optional: If set, loads player from database
	 * @param integer $league_id Optional: If set, loads player from database
	 * @see populate()
	 */
	function OFFL_RosterPlayer ($player_id = NULL, $league_id = NULL)
	{
		OFFL_DBObject::OFFL_DBObject();

	    if(isset($player_id) && isset($league_id))
		{
			$this->_player_id = $player_id;
			$this->_league_id = $league_id;
			$this->populate();
		}
	}

	/**
	 * Pulls info from database.  {@link $_player_id} and {@link $_league_id} must be set.
	 *
	 * @return boolean TRUE if successful, FALSE otherwise.
	 */
	function populate ()
	{
		if(is_null($this->_player_id) || is_null($this->_league_id))
		{
			$this->_emsg = "Control values are not set.  Cannot populate OFFL_RosterPlayer object.";
			error_log ($this->_emsg);
			return FALSE;
		}
		$sql = "SELECT * FROM rosterplayers WHERE player_id='" . $this->_player_id . "' AND league_id='" . $this->_league_id . "'";
		$result = $this->SQLQuery($sql) or die (mysql_error() . ": $sql");

		if($this->SQLNumRows() == 0)
		{
			$this->_emsg = "No roster/player records found for player_id " . $this->_player_id . " and league_id " . $this->_league_id . ".";
//		ERROR LOGGING DISABLED SINCE THIS FUNCTION IS USED FOR LOOKUPS
//	        error_log ($this->_emsg);
			return FALSE;
		}
		$this->_starter = $this->SQLResult(0,"starter");
		$this->_fflteam_id = $this->SQLResult(0,"fflteam_id");
		$this->SQLFreeResult();
		return TRUE;
	}

	/**
	 * Saves the roster/player info to the database
	 *
	 * {@link $_player_id} and {@link $_league_id} must be set for this call to succeed
	 *
	 * @return boolean TRUE if successful, FALSE otherwise
	 */
	function save ()
	{
		if (is_null($this->_player_id) || is_null($this->_league_id))
		{	return FALSE;	}
		$sql = "SELECT * FROM rosterplayers WHERE player_id='" . $this->_player_id . "' AND league_id='" . $this->_league_id . "'";
		$this->SQLQuery($sql);
		if ($this->SQLNumRows() > 0)
		{	$sql = "UPDATE rosterplayers SET starter='" . $this->_starter . "', fflteam_id='" . $this->_fflteam_id . "' WHERE player_id='" . $this->_player_id . "' AND league_id='" . $this->_league_id . "'";	}
		else
		{	$sql = "INSERT INTO rosterplayers (player_id, league_id, starter, fflteam_id) VALUES (" . $this->_player_id . ", " . $this->_league_id . ", " . $this->_starter . ", " . $this->_fflteam_id . ")";	}

		return $this->SQLQuery($sql) or die (mysql_error() . ": $sql");
	}

	/**
	 * Deletes this roster/player entry
	 *
	 * {@link $_player_id} and {@link $_league_id} must be set
	 *
	 * @return boolean TRUE on success, FALSE otherwise
	 */
	function deleteRosterPlayer()
	{
		if (isset($this->_player_id) && isset($this->_league_id))
		{
			$sql = "DELETE FROM rosterplayers WHERE player_id='" . $this->_player_id . "' AND league_id='" . $this->_league_id . "' LIMIT 1";
			$result = $this->SQLQuery($sql) or die (mysql_error() . ": $sql");
			return TRUE;
		}
		$this->_emsg = "Unable to delete RosterPlayer info: control values not defined.";
        error_log ($this->_emsg);
		return FALSE;
	}

	/**
	 * @param integer $player_id
	 */
	function setPlayerID($player_id)
	{
		$this->_player_id = $player_id;
	}

	/**
	 * @return integer
	 */
	function getPlayerID()
	{
		return $this->_player_id;
	}

	/**
	 * @param integer $league_id
	 */
	function setLeagueID($league_id)
	{
		$this->_league_id = $league_id;
	}

	/**
	 * @return integer
	 */
	function getLeagueID()
	{
		return $this->_league_id;
	}

	/**
	 * @param integer $league_id
	 */
	function setFFLTeamID($fflteam_id)
	{
		$this->_fflteam_id = $fflteam_id;
	}

	/**
	 * @return integer
	 */
	function getFFLTeamID()
	{
		return $this->_fflteam_id;
	}

	/**
	 * Sets starter / bench status for a given player
	 *
	 * Auto-adjusts any boolean-compatible input to that used by the database.
	 *
	 * @param boolean $starter
	 */
	function setStarter($starter)
	{
		if ($starter)
		{	$this->_starter = 1;	 }
		else
		{	$this->_starter = 0;	}
	}

	/**
	 * Returns starter / bench status for a given player
	 *
	 * @return boolean
	 */
	function getStarter()
	{
		return $this->_starter;
	}

	/**
	 *
	 *
	 *
	 */
	function getRosterInfo($fflteam_id, &$roster_ids, &$starters)
	{
		$roster_ids = array();
		$starters = array();
		$sql = "SELECT player_id, starter FROM rosterplayers WHERE fflteam_id='" . $fflteam_id . "'";
		$this->SQLQuery($sql);
		for ($i = 0; $i < $this->SQLNumRows(); $i++)
		{
			$roster_ids[] = $this->SQLResult($i, "player_id");
			$starters[] = $this->SQLResult($i, "starter");
		}
	}

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