Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/lib/classes/offl_playerstat.php
<?php
/**
 * Defines the {@link OFFL_PlayerStat} 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");
/**
 * Defines interfaces for info related to player statistics records.
 *
 * Attention must be paid to fixing non-integral point values.  Additionally, {@link calculatePoints()}
 * needs revision pending conversion of {@link OFFL_Control} to 1.0 status.
 *
 * @package offl
 */
class OFFL_PlayerStat extends OFFL_DBObject {
	/**
	 * Used only for {@link calculatePoints()}
	 * @var integer
	 */
	var $_league_id = 0;
	/**
	 * @var integer
	 */
	var $_stat_id = NULL;
	/**
	 * @var integer
	 */
	var $_player_id = NULL;
	/**
	 * @var integer
	 */
	var $_year = NULL;
	/**
	 * @var integer
	 */
	var $_week = NULL;
	/**
	 * @var integer
	 */
	var $_nflteam_id = 0;
	/**
	 * @var integer
	 */
	var $_pass_att = 0;
	/**
	 * @var integer
	 */
	var $_pass_cmp = 0;
	/**
	 * @var integer
	 */
	var $_pass_yd = 0;
	/**
	 * @var integer
	 */
	var $_pass_td = 0;
	/**
	 * @var integer
	 */
	var $_rush_att = 0;
	/**
	 * @var integer
	 */
	var $_rush_yd = 0;
	/**
	 * @var integer
	 */
	var $_rush_td = 0;
	/**
	 * @var integer
	 */
	var $_rec_att = 0;
	/**
	 * @var integer
	 */
	var $_rec_yd = 0;
	/**
	 * @var integer
	 */
	var $_rec_td = 0;
	/**
	 * @var integer
	 */
	var $_kret_att = 0;
	/**
	 * @var integer
	 */
	var $_kret_yd = 0;
	/**
	 * @var integer
	 */
	var $_kret_td = 0;
	/**
	 * @var integer
	 */
	var $_pret_att = 0;
	/**
	 * @var integer
	 */
	var $_pret_yd = 0;
	/**
	 * @var integer
	 */
	var $_pret_td = 0;
	/**
	 * @var integer
	 */
	var $_int = 0;
	/**
	 * @var integer
	 */
	var $_fmbl_lost = 0;
	/**
	 * @var integer
	 */
	var $_twopt = 0;
	/**
	 * @var integer
	 */
	var $_fg_0_19 = 0;
	/**
	 * @var integer
	 */
	var $_fg_20_29 = 0;
	/**
	 * @var integer
	 */
	var $_fg_30_39 = 0;
	/**
	 * @var integer
	 */
	var $_fg_40_49 = 0;
	/**
	 * @var integer
	 */
	var $_fg_50p = 0;
	/**
	 * @var integer
	 */
	var $_fga = 0;
	/**
	 * @var integer
	 */
	var $_xp = 0;
	/**
	 * @var integer
	 */
	var $_xpa = 0;
	/**
	 * @var integer
	 */
	var $_def_pt = NULL;
	/**
	 * @var integer
	 */
	var $_def_yd = NULL;
	/**
	 * @var integer
	 */
	var $_def_pyd = NULL;
	/**
	 * @var integer
	 */
	var $_def_ryd = NULL;
	/**
	 * @var integer
	 */
	var $_def_sack = 0;
	/**
	 * @var integer
	 */
	var $_def_fmbl_rec = 0;
	/**
	 * @var integer
	 */
	var $_def_int = 0;
	/**
	 * @var integer
	 */
	var $_def_fmbl_td = 0;
	/**
	 * @var integer
	 */
	var $_def_int_td = 0;
	/**
	 * @var integer
	 */
	var $_def_ret_td = 0;
	/**
	 * @var integer
	 */
	var $_def_misc_td = 0;
	/**
	 * @var integer
	 */
	var $_def_safety = 0;
	/**
	 * @var integer
	 */
	var $_def_blk_kick = 0;

	/**
	 * Constructor
	 *
	 * @param integer $stat_id Optional: If set, loads given stat record from database
	 */
	function OFFL_PlayerStat ($stat_id = NULL)
	{
		OFFL_DBObject::OFFL_DBObject();

		if (isset($stat_id))
		{
			$this->_stat_id = $stat_id;
			$this->populate();
		}
	}

	/**
	 * Yanks info from database
	 *
	 * @return boolean TRUE on success, FALSE otherwise
	 */
	function populate ()
	{
		if(is_null($this->_stat_id))
		{
			$this->_emsg = "\$_stat_id is not set.	Cannot populate PlayerStat object.";
			error_log ($this->_emsg);
			return FALSE;
		}
		$sql = "SELECT * FROM `playerstats` WHERE stat_id=" . $this->_stat_id;
		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");

		if(mysql_num_rows($result) == 0)
		{
			$this->_emsg = "No stat records found for stat_id " . $this->_stat_id . ".";
			error_log ($this->_emsg);
			return FALSE;
		}
		$this->_player_id = mysql_result($result,0,"player_id");
		$this->_year = mysql_result($result,0,"year");
		$this->_week = mysql_result($result,0,"week");
		$this->_nflteam_id = mysql_result($result,0,"nflteam_id");
		$this->_pass_att = mysql_result($result,0,"pass_att");
		$this->_pass_cmp = mysql_result($result,0,"pass_cmp");
		$this->_pass_yd = mysql_result($result,0,"pass_yd");
		$this->_pass_td = mysql_result($result,0,"pass_td");
		$this->_rush_att = mysql_result($result,0,"rush_att");
		$this->_rush_yd = mysql_result($result,0,"rush_yd");
		$this->_rush_td = mysql_result($result,0,"rush_td");
		$this->_rec_att = mysql_result($result,0,"rec_att");
		$this->_rec_yd = mysql_result($result,0,"rec_yd");
		$this->_rec_td = mysql_result($result,0,"rec_td");
		$this->_kret_att = mysql_result($result,0,"kret_att");
		$this->_kret_yd = mysql_result($result,0,"kret_yd");
		$this->_kret_td = mysql_result($result,0,"kret_td");
		$this->_pret_att = mysql_result($result,0,"pret_att");
		$this->_pret_yd = mysql_result($result,0,"pret_yd");
		$this->_pret_td = mysql_result($result,0,"pret_td");
		$this->_int = mysql_result($result,0,"int");
		$this->_fmbl_lost = mysql_result($result,0,"fmbl_lost");
		$this->_twopt = mysql_result($result,0,"twopt");
		$this->_fg_0_19 = mysql_result($result,0,"fg_0_19");
		$this->_fg_20_29 = mysql_result($result,0,"fg_20_29");
		$this->_fg_30_39 = mysql_result($result,0,"fg_30_39");
		$this->_fg_40_49 = mysql_result($result,0,"fg_40_49");
		$this->_fg_50p = mysql_result($result,0,"fg_50p");
		$this->_fga = mysql_result($result,0,"fga");
		$this->_xp = mysql_result($result,0,"xp");
		$this->_xpa = mysql_result($result,0,"xpa");
		$this->_def_pt = mysql_result($result,0,"def_pt");
		$this->_def_yd = mysql_result($result,0,"def_yd");
		$this->_def_pyd = mysql_result($result,0,"def_pyd");
		$this->_def_ryd = mysql_result($result,0,"def_ryd");
		$this->_def_sack = mysql_result($result,0,"def_sack");
		$this->_def_fmbl_rec = mysql_result($result,0,"def_fmbl_rec");
		$this->_def_int = mysql_result($result,0,"def_int");
		$this->_def_fmbl_td = mysql_result($result,0,"def_fmbl_td");
		$this->_def_int_td = mysql_result($result,0,"def_int_td");
		$this->_def_ret_td = mysql_result($result,0,"def_ret_td");
		$this->_def_misc_td = mysql_result($result,0,"def_misc_td");
		$this->_def_safety = mysql_result($result,0,"def_safety");
		$this->_def_blk_kick = mysql_result($result,0,"def_blk_kick");

		mysql_free_result($result);
		return TRUE;
	}

	/**
	 * Saves info into database.  Determines UPDATE or INSERT automagically.
	 */
	function save ()
	{
		if(is_null($this->_def_pt))
		{	$this->_def_pt = "NULL";	}
		if(is_null($this->_def_yd))
		{	$this->_def_yd = "NULL";	}
		if(is_null($this->_def_pyd))
		{	$this->_def_pyd = "NULL";	}
		if(is_null($this->_def_ryd))
		{	$this->_def_ryd = "NULL";	}

// Occasional malformed web pages may cause these values to be registered as "NULL"
// If there's a way to recurse through these, that'd be preferable (just leave out the _def_ vbls above)
		if(is_null($this->_pass_att))
		{	$this->_pass_att = 0;		}
		if(is_null($this->_pass_cmp))
		{	$this->_pass_cmp = 0;		}
		if(is_null($this->_pass_yd))
		{	$this->_pass_yd = 0;		}
		if(is_null($this->_pass_td))
		{	$this->_pass_td = 0;		}
		if(is_null($this->_rush_att))
		{	$this->_rush_att = 0;		}
		if(is_null($this->_rush_yd))
		{	$this->_rush_yd = 0;		}
		if(is_null($this->_rush_td))
		{	$this->_rush_td = 0;		}
		if(is_null($this->_rec_att))
		{	$this->_rec_att = 0;		}
		if(is_null($this->_rec_yd))
		{	$this->_rec_yd = 0;		}
		if(is_null($this->_rec_td))
		{	$this->_rec_td = 0;		}

		if (is_null($this->_stat_id)) // insert entry
		{
			$sql = "INSERT INTO `playerstats` (`player_id`, `year`, `week`, `nflteam_id`, `pass_att`, `pass_cmp`, `pass_yd`, `pass_td`, `rush_att`, `rush_yd`, `rush_td`, `rec_att`, `rec_yd`, `rec_td`, `kret_att`, `kret_yd`, `kret_td`, `pret_att`, `pret_yd`, `pret_td`, `int`, `fmbl_lost`, `twopt`, `fg_0_19`, `fg_20_29`, `fg_30_39`, `fg_40_49`, `fg_50p`, `fga`, `xp`, `xpa`, `def_pt`, `def_yd`, `def_pyd`, `def_ryd`, `def_sack`, `def_fmbl_rec`, `def_int`, `def_fmbl_td`, `def_int_td`, `def_ret_td`, `def_misc_td`, `def_safety`, `def_blk_kick`) VALUES (" . $this->_player_id . ", " . $this->_year . ", " . $this->_week . ", " . $this->_nflteam_id . ", " . $this->_pass_att . ", " . $this->_pass_cmp . ", " . $this->_pass_yd . ", " . $this->_pass_td . ", " . $this->_rush_att . ", " . $this->_rush_yd . ", " . $this->_rush_td . ", " . $this->_rec_att . ", " . $this->_rec_yd . ", " . $this->_rec_td . ", " . $this->_kret_att . ", " . $this->_kret_yd . ", " . $this->_kret_td . ", " . $this->_pret_att . ", " . $this->_pret_yd . ", " . $this->_pret_td . ", " . $this->_int . ", " . $this->_fmbl_lost . ", " . $this->_twopt . ", " . $this->_fg_0_19 . ", " . $this->_fg_20_29 . ", " . $this->_fg_30_39 . ", " . $this->_fg_40_49 . ", " . $this->_fg_50p . ", " . $this->_fga . ", " . $this->_xp . ", " . $this->_xpa . ", " . $this->_def_pt . ", " . $this->_def_yd . ", " . $this->_def_pyd . ", " . $this->_def_ryd . ", " . $this->_def_sack . ", " . $this->_def_fmbl_rec . ", " . $this->_def_int . ", " . $this->_def_fmbl_td . ", " . $this->_def_int_td . ", " . $this->_def_ret_td . ", " . $this->_def_misc_td . ", " . $this->_def_safety . ", " . $this->_def_blk_kick . ")";
		}
		else // update entry
		{
			$sql = "UPDATE `playerstats` SET `player_id`=" . $this->_player_id . ", `year`=" . $this->_year . ", `week`=" . $this->_week . ", `nflteam_id`=" . $this->_nflteam_id . ", `pass_att`=" . $this->_pass_att . ", `pass_cmp`=" . $this->_pass_cmp . ", `pass_yd`=" . $this->_pass_yd . ", `pass_td`=" . $this->_pass_td . ", `rush_att`=" . $this->_rush_att . ", `rush_yd`=" . $this->_rush_yd . ", `rush_td`=" . $this->_rush_td . ", `rec_att`=" . $this->_rec_att . ", `rec_yd`=" . $this->_rec_yd . ", `rec_td`=" . $this->_rec_td . ", `kret_att`=" . $this->_kret_att . ", `kret_yd`=" . $this->_kret_yd . ", `kret_td`=" . $this->_kret_td . ", `pret_att`=" . $this->_pret_att . ", `pret_yd`=" . $this->_pret_yd . ", `pret_td`=" . $this->_pret_td . ", `int`=" . $this->_int . ", `fmbl_lost`=" . $this->_fmbl_lost . ", `twopt`=" . $this->_twopt . ", `fg_0_19`=" . $this->_fg_0_19 . ", `fg_20_29`=" . $this->_fg_20_29 . ", `fg_30_39`=" . $this->_fg_30_39 . ", `fg_40_49`=" . $this->_fg_40_49 . ", `fg_50p`=" . $this->_fg_50p . ", `fga`=" . $this->_fga . ", `xp`=" . $this->_xp . ", `xpa`=" . $this->_xpa . ", `def_pt`=" . $this->_def_pt . ", `def_yd`=" . $this->_def_yd . ", `def_pyd`=" . $this->_def_pyd . ", `def_ryd`=" . $this->_def_ryd . ", `def_sack`=" . $this->_def_sack . ", `def_fmbl_rec`=" . $this->_def_fmbl_rec . ", `def_int`=" . $this->_def_int . ", `def_fmbl_td`=" . $this->_def_fmbl_td . ", `def_int_td`=" . $this->_def_int_td . ", `def_ret_td`=" . $this->_def_ret_td . ", `def_misc_td`=" . $this->_def_misc_td . ", `def_safety`=" . $this->_def_safety . ", `def_blk_kick`=" . $this->_def_blk_kick . " WHERE `stat_id`=" . $this->_stat_id;
		}
		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");
		return $result;
	}

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

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

	/**
	 * @return integer
	 */
	function getStatID ()
	{
		return $this->_stat_id;
	}

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

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

	/**
	 * @param integer $year
	 */
	function setYear ($year)
	{
		$this->_year = $year;
	}

	/**
	 * @return integer
	 */
	function getYear ()
	{
		return $this->_year;
	}

	/**
	 * @param integer $week
	 */
	function setWeek ($week)
	{
		$this->_week = $week;
	}

	/**
	 * @return integer
	 */
	function getWeek ()
	{
		return $this->_week;
	}

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

	/**
	 * @param integer $nflteam_id
	 */
	function setNFLTeamID ($nflteam_id)
	{
		$this->_nflteam_id = $nflteam_id;
	}

	/**
	 * @param integer $pass_att
	 */
	function setPassAtt ($pass_att)
	{
		$this->_pass_att = $pass_att;
	}

	/**
	 * @return integer
	 */
	function getPassAtt ()
	{
		return $this->_pass_att;
	}

	/**
	 * @param integer $pass_cmp
	 */
	function setPassCmp ($pass_cmp)
	{
		$this->_pass_cmp = $pass_cmp;
	}

	/**
	 * @return integer
	 */
	function getPassCmp ()
	{
		return $this->_pass_cmp;
	}

	/**
	 * @param integer $pass_yd
	 */
	function setPassYd ($pass_yd)
	{
		$this->_pass_yd = $pass_yd;
	}

	/**
	 * @return integer
	 */
	function getPassYd ()
	{
		return $this->_pass_yd;
	}

	/**
	 * @param integer $pass_td
	 */
	function setPassTD ($pass_td)
	{
		$this->_pass_td = $pass_td;
	}

	/**
	 * @return integer
	 */
	function getPassTD ()
	{
		return $this->_pass_td;
	}

	/**
	 * @param integer $rush_att
	 */
	function setRushAtt ($rush_att)
	{
		$this->_rush_att = $rush_att;
	}

	/**
	 * @return integer
	 */
	function getRushAtt ()
	{
		return $this->_rush_att;
	}

	/**
	 * @param integer $rush_yd
	 */
	function setRushYd ($rush_yd)
	{
		$this->_rush_yd = $rush_yd;
	}

	/**
	 * @return integer
	 */
	function getRushYd ()
	{
		return $this->_rush_yd;
	}

	/**
	 * @param integer $rush_td
	 */
	function setRushTD ($rush_td)
	{
		$this->_rush_td = $rush_td;
	}

	/**
	 * @return integer
	 */
	function getRushTD ()
	{
		return $this->_rush_td;
	}

	/**
	 * @param integer $rec_att
	 */
	function setRecAtt ($rec_att)
	{
		$this->_rec_att = $rec_att;
	}

	/**
	 * @return integer
	 */
	function getRecAtt ()
	{
		return $this->_rec_att;
	}

	/**
	 * @param integer $rec_yd
	 */
	function setRecYd ($rec_yd)
	{
		$this->_rec_yd = $rec_yd;
	}

	/**
	 * @return integer
	 */
	function getRecYd ()
	{
		return $this->_rec_yd;
	}

	/**
	 * @param integer $rec_td
	 */
	function setRecTD ($rec_td)
	{
		$this->_rec_td = $rec_td;
	}

	/**
	 * @return integer
	 */
	function getRecTD ()
	{
		return $this->_rec_td;
	}

	/**
	 * @param integer $kret_att
	 */
	function setKRetAtt ($kret_att)
	{
		$this->_kret_att = $kret_att;
	}

	/**
	 * @return integer
	 */
	function getKRetAtt ()
	{
		return $this->_kret_att;
	}

	/**
	 * @param integer $kret_yd
	 */
	function setKRetYd ($kret_yd)
	{
		$this->_kret_yd = $kret_yd;
	}

	/**
	 * @return integer
	 */
	function getKRetYd ()
	{
		return $this->_kret_yd;
	}

	/**
	 * @param integer $kret_td
	 */
	function setKRetTD ($kret_td)
	{
		$this->_kret_td = $kret_td;
	}

	/**
	 * @return integer
	 */
	function getKRetTD ()
	{
		return $this->_kret_td;
	}

	/**
	 * @param integer $pret_att
	 */
	function setPRetAtt ($pret_att)
	{
		$this->_pret_att = $pret_att;
	}

	/**
	 * @return integer
	 */
	function getPRetAtt ()
	{
		return $this->_pret_att;
	}

	/**
	 * @param integer $pret_yd
	 */
	function setPRetYd ($pret_yd)
	{
		$this->_pret_yd = $pret_yd;
	}

	/**
	 * @return integer
	 */
	function getPRetYd ()
	{
		return $this->_pret_yd;
	}

	/**
	 * @param integer $pret_td
	 */
	function setPRetTD ($pret_td)
	{
		$this->_pret_td = $pret_td;
	}

	/**
	 * @return integer
	 */
	function getPRetTD ()
	{
		return $this->_pret_td;
	}

	/**
	 * @param integer $int
	 */
	function setInt ($int)
	{
		$this->_int = $int;
	}

	/**
	 * @return integer
	 */
	function getInt ()
	{
		return $this->_int;
	}

	/**
	 * @param integer $fmbl_lost
	 */
	function setFmblLost ($fmbl_lost)
	{
		$this->_fmbl_lost = $fmbl_lost;
	}

	/**
	 * @return integer
	 */
	function getFmblLost ()
	{
		return $this->_fmbl_lost;
	}

	/**
	 * @param integer $twopt
	 */
	function setTwoPt ($twopt)
	{
		$this->_twopt = $twopt;
	}

	/**
	 * @return integer
	 */
	function getTwoPt ()
	{
		return $this->_twopt;
	}

	/**
	 * @param integer $fg_0_19
	 */
	function setFG_0_19 ($fg_0_19)
	{
		$this->_fg_0_19 = $fg_0_19;
	}

	/**
	 * @return integer
	 */
	function getFG_0_19 ()
	{
		return $this->_fg_0_19;
	}

	/**
	 * @param integer $fg_20_29
	 */
	function setFG_20_29 ($fg_20_29)
	{
		$this->_fg_20_29 = $fg_20_29;
	}

	/**
	 * @return integer
	 */
	function getFG_20_29 ()
	{
		return $this->_fg_20_29;
	}

	/**
	 * @param integer $fg_30_39
	 */
	function setFG_30_39 ($fg_30_39)
	{
		$this->_fg_30_39 = $fg_30_39;
	}

	/**
	 * @return integer
	 */
	function getFG_30_39 ()
	{
		return $this->_fg_30_39;
	}

	/**
	 * @param integer $fg_40_49
	 */
	function setFG_40_49 ($fg_40_49)
	{
		$this->_fg_40_49 = $fg_40_49;
	}

	/**
	 * @return integer
	 */
	function getFG_40_49 ()
	{
		return $this->_fg_40_49;
	}

	/**
	 * @param integer $fg_50p
	 */
	function setFG_50p ($fg_50p)
	{
		$this->_fg_50p = $fg_50p;
	}

	/**
	 * @return integer
	 */
	function getFG_50p ()
	{
		return $this->_fg_50p;
	}

	/**
	 * @param integer $fga
	 */
	function setFGA ($fga)
	{
		$this->_fga = $fga;
	}

	/**
	 * @return integer
	 */
	function getFGA ()
	{
		return $this->_fga;
	}

	/**
	 * @return integer
	 */
	function getFGMiss()
	{
		$fgm = $this->_fga - $this->_fg_0_19 - $this->_fg_20_29 - $this->_fg_30_39 - $this->_fg_40_49 - $this->_fg_50p;
		return $fgm;
	}

	/**
	 * @param integer $xp
	 */
	function setXP ($xp)
	{
		$this->_xp = $xp;
	}

	/**
	 * @return integer
	 */
	function getXP ()
	{
		return $this->_xp;
	}

	/**
	 * @param integer $xpa
	 */
	function setXPA ($xpa)
	{
		$this->_xpa = $xpa;
	}

	/**
	 * @return integer
	 */
	function getXPA ()
	{
		return $this->_xpa;
	}

	/**
	 * @return integer
	 */
	function getXPMiss()
	{
		return $this->_xpa - $this->_xp;
	}

	/**
	 * @param integer $def_pt
	 */
	function setDEFPt ($def_pt)
	{
		$this->_def_pt = $def_pt;
	}

	/**
	 * @return integer
	 */
	function getDEFPt ()
	{
		return $this->_def_pt;
	}

	/**
	 * @param integer $def_yd
	 */
	function setDEFYd ($def_yd)
	{
		$this->_def_yd = $def_yd;
	}

	/**
	 * @return integer
	 */
	function getDEFYd ()
	{
		return $this->_def_yd;
	}

	/**
	 * @param integer $def_pyd
	 */
	function setDEFPYd ($def_pyd)
	{
		$this->_def_pyd = $def_pyd;
	}

	/**
	 * @return integer
	 */
	function getDEFPYd ()
	{
		return $this->_def_pyd;
	}

	/**
	 * @param integer $def_ryd
	 */
	function setDEFRYd ($def_ryd)
	{
		$this->_def_ryd = $def_ryd;
	}

	/**
	 * @return integer
	 */
	function getDEFRYd ()
	{
		return $this->_def_ryd;
	}

	/**
	 * @param integer $def_sack
	 */
	function setDEFSack ($def_sack)
	{
		$this->_def_sack = $def_sack;
	}

	/**
	 * @return integer
	 */
	function getDEFSack ()
	{
		return $this->_def_sack;
	}

	/**
	 * @param integer $def_fmbl_rec
	 */
	function setDEFFmblRec ($def_fmbl_rec)
	{
		$this->_def_fmbl_rec = $def_fmbl_rec;
	}

	/**
	 * @return integer
	 */
	function getDEFFmblRec ()
	{
		return $this->_def_fmbl_rec;
	}

	/**
	 * @param integer $def_int
	 */
	function setDEFInt ($def_int)
	{
		$this->_def_int = $def_int;
	}

	/**
	 * @return integer
	 */
	function getDEFInt ()
	{
		return $this->_def_int;
	}

	/**
	 * @param integer $def_fmbl_td
	 */
	function setDEFFmblTD ($def_fmbl_td)
	{
		$this->_def_fmbl_td = $def_fmbl_td;
	}

	/**
	 * @return integer
	 */
	function getDEFFmblTD ()
	{
		return $this->_def_fmbl_td;
	}

	/**
	 * @param integer $def_int_td
	 */
	function setDEFIntTD ($def_int_td)
	{
		$this->_def_int_td = $def_int_td;
	}

	/**
	 * @return integer
	 */
	function getDEFIntTD ()
	{
		return $this->_def_int_td;
	}

	/**
	 * @param integer $def_ret_td
	 */
	function setDEFRetTD ($def_ret_td)
	{
		$this->_def_ret_td = $def_ret_td;
	}

	/**
	 * @return integer
	 */
	function getDEFRetTD ()
	{
		return $this->_def_ret_td;
	}

	/**
	 * @param integer $def_misc_td
	 */
	function setDEFMiscTD ($def_misc_td)
	{
		$this->_def_misc_td = $def_misc_td;
	}

	/**
	 * @return integer
	 */
	function getDEFMiscTD ()
	{
		return $this->_def_misc_td;
	}

	/**
	 * @param integer $def_safety
	 */
	function setDEFSafety ($def_safety)
	{
		$this->_def_safety = $def_safety;
	}

	/**
	 * @return integer
	 */
	function getDEFSafety ()
	{
		return $this->_def_safety;
	}

	/**
	 * @param integer $def_blk_kick
	 */
	function setDEFBlkKick ($def_blk_kick)
	{
		$this->_def_blk_kick = $def_blk_kick;
	}

	/**
	 * @return integer
	 */
	function getDEFBlkKick ()
	{
		return $this->_def_blk_kick;
	}

	/**
	 * Looks up a stat record by {@link OFFL_Player::$_player_id player_id} / year / week
	 * @param integer $player_id
	 * @param integer $year
	 * @param integer $week
	 * @param integer $league_id Optional: set to initialize internal league_id parameter
	 * @return OFFL_PlayerStat Returns appropriate stat record, or FALSE if not found
	 */
	function getStatsByPlayerIDYearWeek($player_id, $year, $week, $league_id=NULL)
	{
		$sql = "SELECT stat_id FROM `playerstats` WHERE player_id=" . $player_id . " AND year=" . $year . " AND week=" . $week;

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

		if(mysql_num_rows($result) == 0)
		{
		//	$this->_emsg = "No stat records found for player_id $player_id / year $year / week $week.";
		//	error_log ($this->_emsg);
			return FALSE;
		}

		$stat = new OFFL_PlayerStat(mysql_result($result,0,"stat_id"));
		mysql_free_result($result);

		if (isset($league_id))
		{	$stat->setLeagueID($league_id);	}

		return $stat;
	}

	/**
	 * Calculates the point total of this particular stat record *for a given {@link OFFL_League league}*
	 *
	 * {@link $_league_id} must be set to get correct results
	 * @return number Fantasy point value for this stat record.
	 */
	function calculatePoints()
	// assumes the correct stat record is loaded / populated / etc
	{
		$points = 0; // sum of total points
		$parameter = new OFFL_Control($this->_league_id); // loads scoring parameters
		$trunc = $parameter->getValue("SCORING_FRAC_POINTS");
		if ($trunc == "Yes") // swap "score fractional points" to "truncate fractional points"
			$trunc = FALSE;
		else
			$trunc = TRUE;
		$posonly = $parameter->getValue("SCORING_NEG_POINTS");
		if ($posonly == "Yes") // swap "negative points allowed" for "positive points only"
			$posonly = FALSE;
		else
			$posonly = TRUE;

		// these categories are all scored per-item.
		// field goals / xps are not (if negative scores assigned for misses)
		// defense points / yards are scored in inverse scaling fashion.
		$individ_player_scoring = array("_pass_att", "_pass_cmp", "_pass_yd", "_pass_td", "_rush_att", "_rush_yd", "_rush_td", "_rec_att", "_rec_yd", "_rec_td", "_kret_att", "_kret_yd", "_kret_td", "_pret_att", "_pret_yd", "_pret_td", "_int", "_fmbl_lost", "_twopt");

		foreach ($individ_player_scoring as $cat)
		{
			$scorefactor = $parameter->getValue("SCORING" . strtoupper($cat));

			if ( !($posonly && ($this->$cat <= 0)) )
			// prevents negative yardage penalty if set (TDs, etc, will never be negative anyway)
			{
				$tmpscore = $scorefactor * $this->$cat;
				if ($trunc)
				{
					if ($tmpscore < 0)
						$tmpscore = ceil($tmpscore);
					else
						$tmpscore = floor($tmpscore);
				}
				
				$points += $tmpscore;	// need to check syntax here
										// might be $this->{$cat}
			}
		}

		// INCENTIVE BONUSES
		if ($this->_pass_yd >= 300)
		{
			$scorefactor = $parameter->getValue("SCORING_PASS_300YD");
			if ($trunc)
			{
				if ($scorefactor < 0)
					$scorefactor = ceil($scorefactor);
				else
					$scorefactor = floor($scorefactor);
			}
			$points += $scorefactor;
		}
		if ($this->_rush_yd >= 100)
		{
			$scorefactor = $parameter->getValue("SCORING_RUSH_100YD");
			if ($trunc)
			{
				if ($scorefactor < 0)
					$scorefactor = ceil($scorefactor);
				else
					$scorefactor = floor($scorefactor);
			}
			$points += $scorefactor;
		}
		if ($this->_rec_yd >= 100)
		{
			$scorefactor = $parameter->getValue("SCORING_REC_100YD");
			if ($trunc)
			{
				if ($scorefactor < 0)
					$scorefactor = ceil($scorefactor);
				else
					$scorefactor = floor($scorefactor);
			}
			$points += $scorefactor;
		}

		$fgs_made = 0;
		$fg_scoring = array("_fg_0_19", "_fg_20_29", "_fg_30_39", "_fg_40_49", "_fg_50p");
		foreach ($fg_scoring as $cat)
		{
			$scorefactor = $parameter->getValue("SCORING" . strtoupper($cat));

			$tmpscore = $scorefactor * $this->$cat;
			if ($trunc)
			{
				if ($tmpscore < 0)
					$tmpscore = ceil($tmpscore);
				else
					$tmpscore = floor($tmpscore);
			}
			
			$points += $tmpscore;	// need to check syntax here
										// might be $this->{$cat}
			$fgs_made += $this->$cat;
		}

		$scorefactor = $parameter->getValue("SCORING_FG_MISSED");

		$tmpscore = $scorefactor * ($this->_fga - $fgs_made);
		if ($trunc)
		{
			if ($tmpscore < 0)
				$tmpscore = ceil($tmpscore);
			else
				$tmpscore = floor($tmpscore);
		}
		
		$points += $tmpscore;	// need to check syntax here
								// might be $this->{$cat}
		
		// XP stuff
		$scorefactor = $parameter->getValue("SCORING_XP");
		$tmpscore = $scorefactor * $this->_xp;
		if ($trunc)
		{
			if ($tmpscore < 0)
				$tmpscore = ceil($tmpscore);
			else
				$tmpscore = floor($tmpscore);
		}
		
		$points += $tmpscore;	// need to check syntax here
									// might be $this->{$cat}

		$scorefactor = $parameter->getValue("SCORING_XP_MISSED");
		$tmpscore = $scorefactor * ($this->_xpa - $this->_xp);
		if ($trunc)
		{
			if ($tmpscore < 0)
				$tmpscore = ceil($tmpscore);
			else
				$tmpscore = floor($tmpscore);
		}
		
		$points += $tmpscore;	// need to check syntax here
									// might be $this->{$cat}

		// DEFENSE SECTION
		// points
		if (!is_null($this->_def_pt))
			for ($i = 1; $i < 8; $i++)
			{
				$pointlimit = $parameter->getValue("SCORING_DEF_PT_LIMIT_" . $i);
				$scorefactor = $parameter->getValue("SCORING_DEF_PT_" . $i);

				if ($this->_def_pt <= $pointlimit)
				{
					if ($trunc)
					{
						if ($scorefactor < 0)
							$scorefactor = ceil($scorefactor);
						else
							$scorefactor = floor($scorefactor);
					}

					$points += $scorefactor;
					break;
				}
			}

		// yards
		if (!is_null($this->_def_yd))
			for ($i = 1; $i < 8; $i++)
			{
				$yardlimit = $parameter->getValue("SCORING_DEF_YD_LIMIT_" . $i);
				$scorefactor = $parameter->getValue("SCORING_DEF_YD_" . $i);

				if ($this->_def_yd <= $yardlimit)
				{
					$points += $scorefactor;
					if ($trunc)
						$points = floor($points);
					break;
				}
			}

		$def_scoring = array("_def_sack", "_def_fmbl_rec", "_def_int", "_def_fmbl_td", "_def_int_td", "_def_ret_td", "_def_misc_td", "_def_safety", "_def_blk_kick");

		foreach ($def_scoring as $cat)
		{
			$scorefactor = $parameter->getValue("SCORING" . strtoupper($cat));
			$points += $scorefactor * $this->$cat;	// need to check syntax here
													// might be $this->{$cat}
			if ($trunc)
				$points = floor($points);
		}

		return $points;
	}

	/**
	 * Alias for {@link calculatePoints()}
	 * @return number Fantasy point value for this stat record.
	 */
	function getPoints()
	{
		return $this->calculatePoints();
	}

	/**
	 * Returns years with stat records, optionally isolated to one player
	 * @param integer $player_id Optional: if set, returns only for this player
	 * @return array Array of integers
	 */
	function getStatYears($player_id=NULL)
	{
		$retArr = array();
		$sql = "SELECT DISTINCT year FROM playerstats";
		if (isset($player_id))
		{	$sql .= " WHERE player_id=" . $player_id;	}
		$sql .= " ORDER BY year";
		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");

		for($i=0; $i<mysql_num_rows($result); $i++)
		{	array_push($retArr, mysql_result($result,$i,"year"));	}

		mysql_free_result($result);

		return $retArr;
	}

	/**
	 * Returns weeks with stat records for a given year, optionally isolated to one player
	 * @param integer $year
	 * @param integer $player_id Optional: if set, returns only for this player
	 * @return array Array of integers
	 */
	function getStatWeeks($year, $player_id=NULL)
	{
		$retArr = array();
		$sql = "SELECT DISTINCT week FROM playerstats WHERE year=" . $year;
		if (isset($player_id))
		{	$sql .= " AND player_id=" . $player_id;	}
		$sql .= " ORDER BY week";
		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");

		for($i=0; $i<mysql_num_rows($result); $i++)
		{	array_push($retArr, mysql_result($result,$i,"week"));	}

		mysql_free_result($result);

		return $retArr;
	}

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