Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/lib/classes/offl_nflteam.php
<?php
/**
 * Defines the {@link OFFL_NFLTeam} 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");
require_once($DOC_ROOT . "/lib/classes/offl_player.php");
/**
 * Defines interfaces for info related to NFL franchises, including {@link getRoster() roster retrieval}.
 *
 * This class is populated at FFL install time and there's no reason to use the save or setXXX functions.
 * They're provided only for completeness.
 *
 * @package offl
 */
class OFFL_NFLTeam extends OFFL_DBObject
{
	/**
	 * @var integer
	 */
	var $_nflteam_id = NULL;
	/**
	 * @var string
	 */
	var $_nflteam_city = NULL;
	/**
	 * @var string
	 */
	var $_nflteam_name = NULL;
	/**
	 * @var string
	 */
	var $_nflteam_abbv = NULL;

	/**
	 * Constructor
	 *
	 * @param integer $nflteam_id Optional: If set, loads NFL team from database
	 */
	function OFFL_NFLTeam ($nflteam_id = NULL)
	{
		OFFL_DBObject::OFFL_DBObject();

		if (!is_null($nflteam_id))
		{
			$this->_nflteam_id = $nflteam_id;
			$this->populate();
		}
	}

	/**
	 * Yanks info from database
	 *
	 * @return boolean TRUE on success, FALSE otherwise
	 */
	function populate ()
	{
		if(empty($this->_nflteam_id))
		{
			$this->_emsg = "\$_nflteam_id is not set.	Cannot populate NFLTeam object.";
			error_log ($this->_emsg);
			return FALSE;
		}
		$sql = "select * from nflteams where nflteam_id=$this->_nflteam_id";
		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");

		if(mysql_num_rows($result) == 0)
		{
			$this->_emsg = "No person records found for nflteam_id $this->_nflteam_id.";
			error_log ($this->_emsg);
			return FALSE;
		}
		$this->_nflteam_city = htmlspecialchars(stripslashes(mysql_result($result,0,"nflteam_city")));
		$this->_nflteam_name = htmlspecialchars(stripslashes(mysql_result($result,0,"nflteam_name")));
		$this->_nflteam_abbv = htmlspecialchars(stripslashes(mysql_result($result,0,"nflteam_abbv")));
		mysql_free_result($result);
		return TRUE;
	}

	/**
	 * Saves info into database.  Determines UPDATE or INSERT automagically.
	 */
	function save ()
	{
		$sql;
		if(empty($this->_nflteam_id))
		{
			// insert
			$sql = "INSERT INTO nflteams (nflteam_city, nflteam_name, nflteam_abbv) VALUES ('" . mysql_escape_string($this->_nflteam_city) . "', '" . mysql_escape_string($this->_nflteam_name) . "', '" . mysql_escape_string($this->_nflteam_abbv) . "')";
		}
		else
		{
			// update
			$sql = "UPDATE nflteams SET nflteam_city='" . mysql_escape_string($this->_nflteam_city) . "', nflteam_name='" . mysql_escape_string($this->_nflteam_name) ."', nflteam_abbv='" . mysql_escape_string($this->_nflteam_abbv) ."' WHERE nflteam_id=" . $this->_nflteam_id;
		}

		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");
		return $result;
	}

	/**
	 * @return integer
	 */
	function getNFLTeamID()
	{
		return $this->_nflteam_id;
	}

	/**
	 * @param string $nflteam_city i.e. "Tennessee" or "Indianapolis"
	 */
	function setNFLTeamCity($nflteam_city)
	{
		$this->_nflteam_city = $nflteam_city; 
	}

	/**
	 * @return string
	 */
	function getNFLTeamCity()
	{
		return $this->_nflteam_city;
	}

	/**
	 * @param string $nflteam_name i.e. "Titans" or "Colts"
	 */
	function setNFLTeamName($nflteam_name)
	{
		$this->_nflteam_name = $nflteam_name; 
	}

	/**
	 * @return string
	 */
	function getNFLTeamName()
	{
		return $this->_nflteam_name;
	}

	/**
	 * @param string $nflteam_abbv i.e. "TEN" or "IND"
	 */
	function setNFLTeamAbbv($nflteam_abbv)
	{
		$this->_nflteam_name = $nflteam_abbv; 
	}

	/**
	 * @return string
	 */
	function getNFLTeamAbbv()
	{
		return $this->_nflteam_abbv;
	}

	/**
	 * Returns an array of all players on this NFL team
	 * @return array An array of OFFL_Player objects
	 */
	function getRoster()
	{
		$retArr = array();
		$sql = "SELECT player_id FROM players WHERE nflteam_id=" . $this->_nflteam_id . " order by lname, fname";
		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");

		for($i=0; $i<mysql_num_rows($result); $i++)
		{
			$player = new OFFL_Player(mysql_result($result,$i,"nflteam_id"));
			array_push($retArr, $player);
		}
	
		mysql_free_result($result);

		return $retArr;
	}

	/**
	 * Returns an OFFL_NFLTeam object by NFL.com abbreviation
	 *
	 * @param string $abbv i.e. "TEN" or "IND"
	 * @return OFFL_NFLTeam
	 */
	function getNFLTeamByAbbv($abbv)
	{
		$sql = "SELECT nflteam_id FROM nflteams WHERE nflteam_abbv='" . mysql_escape_string($abbv) . "'";
		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");

		$team = new OFFL_NFLTeam(mysql_result($result,0,"nflteam_id"));

		mysql_free_result($result);

		return $team;
	}

	/**
	 * Returns an OFFL_NFLTeam object by NFL.com abbreviation
	 *
	 * @param string $abbv i.e. "TEN" or "IND"
	 * @return OFFL_NFLTeam
	 */
	function getNFLTeamBySchedName($schedName)
	{
		$sql = "SELECT nflteam_id FROM nflteams WHERE nflteam_schedulename='" . mysql_escape_string($schedName) . "'";
		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");

		$team = new OFFL_NFLTeam(mysql_result($result,0,"nflteam_id"));

		mysql_free_result($result);

		return $team;
	}

	/**
	 * Returns an array of all registered NFL teams
	 *
	 * @return array An array of OFFL_NFLTeam objects
	 */
	function getAllNFLTeams()
	{
		$retArr = array();
		$sql = "SELECT nflteam_id FROM nflteams ORDER BY nflteam_city, nflteam_name";
		
		//$sql = "SELECT nflteam_id FROM nflteams WHERE nflteam_id <= 4 ORDER BY nflteam_city, nflteam_name";
		//$sql = "SELECT nflteam_id FROM nflteams WHERE nflteam_id >= 5 AND nflteam_id <= 8 ORDER BY nflteam_city, nflteam_name";
		//$sql = "SELECT nflteam_id FROM nflteams WHERE nflteam_id >= 9 AND nflteam_id <= 12 ORDER BY nflteam_city, nflteam_name";
		//$sql = "SELECT nflteam_id FROM nflteams WHERE nflteam_id >= 13 AND nflteam_id <= 16 ORDER BY nflteam_city, nflteam_name";
		//$sql = "SELECT nflteam_id FROM nflteams WHERE nflteam_id >= 17 AND nflteam_id <= 20 ORDER BY nflteam_city, nflteam_name";
		//$sql = "SELECT nflteam_id FROM nflteams WHERE nflteam_id >= 21 AND nflteam_id <= 24 ORDER BY nflteam_city, nflteam_name";
		//$sql = "SELECT nflteam_id FROM nflteams WHERE nflteam_id >= 25 AND nflteam_id <= 28 ORDER BY nflteam_city, nflteam_name";
		//$sql = "SELECT nflteam_id FROM nflteams WHERE nflteam_id >= 29 AND nflteam_id <= 32 ORDER BY nflteam_city, nflteam_name";
		
		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");

		for($i=0; $i<mysql_num_rows($result); $i++)
		{
			$team = new OFFL_NFLTeam(mysql_result($result,$i,"nflteam_id"));
			array_push($retArr, $team);
		}

		mysql_free_result($result);

		return $retArr;
	}

} // end OFFL_NFLTeam class

?>
Return current item: Online Fantasy Football League