<?php
/**
* Defines the OFFL_LPL (Lead Pipe Lock) 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_fflteam.php");
require_once($DOC_ROOT . "/lib/classes/offl_player.php");
require_once($DOC_ROOT . "/lib/classes/offl_rosterplayer.php");
/**
* The OFFL_LPL class provides an interface to the users and teams involved in an OFFL league.
*
* This class is being revised for the next OFFL release to incorporate the new {@link OFFL_RosterPlayer} class.
*
* @package offl
*/
class OFFL_LPL extends OFFL_DBObject
{
/**
* @var integer
*/
var $_user_id = NULL;
/**
* @var integer
*/
var $_league_id = NULL;
/**
* @var integer
*/
var $_year = NULL;
/**
* @var integer
*/
var $_week = NULL;
/**
* @var integer
*/
var $_nflteam_id = NULL;
/**
* @var integer Integral boolean (1/0)
*/
var $_correct = 0;
/**
* Internal control variable for new item construction (used for save())
* @var boolean
*/
var $_new = TRUE;
/**
* constructor, populates if optional parameter $league_id is set
*
* @param integer $league_id FFL League ID number to populate object with
* @see populate()
*/
function OFFL_LPL($user_id = NULL, $league_id = NULL, $year = NULL, $week = NULL)
{
OFFL_DBObject::OFFL_DBObject();
if(!is_null($user_id) && !is_null($league_id) && !is_null($year) && !is_null($week))
{
$this->_user_id = $user_id;
$this->_league_id = $league_id;
$this->_year = $year;
$this->_week = $week;
$this->populate();
}
}
/**
* Pulls relevant league info from the database into member variables
*
* populate() is only useful if {@link $_league_id} has been set in advance. If not, an error is logged.
*/
function populate()
{
if(is_null($this->_user_id) || is_null($this->_league_id) || is_null($this->_year) || is_null($this->_week))
{
$this->_emsg = "Control variables are not set. Cannot populate OFFL_LPL object.";
error_log ($this->_emsg);
return FALSE;
}
$sql = "SELECT nflteam_id, correct FROM leadpipelock WHERE user_id=" . $this->_user_id . " AND league_id=" . $this->_league_id . " AND year=" . $this->_year . " AND week=" . $this->_week;
$this->SQLQuery($sql) or die (mysql_error() . ": $sql");
if(mysql_num_rows($result) == 0)
{
$this->_emsg = "No LPL records found for " . $this->_user_id . "/" . $this->_league_id . "/" . $this->_year . "/" . $this->_week . ".";
// error_log ($this->_emsg);
return FALSE;
}
$this->_nflteam_id = $this->SQLResult(0, "nflteam_id");
$this->_correct = $this->SQLResult(0, "correct");
$this->SQLFreeResult();
$this->_new = FALSE;
return TRUE;
}
/**
* Saves league info to the database
*
*
*/
function save()
{
if($this->_new)
{
// insert
$sql = "INSERT INTO leadpipelock (user_id, league_id, year, week, nflteam_id) VALUES (" . $this->_user_id . ", " . $this->_league_id . ", " . $this->_year . ", " . $this->_week . ", " . $this->_nflteam_id . ")";
$this->_new = FALSE;
}
else
{
// update
$sql = "UPDATE leadpipelock SET nflteam_id=" . $this->_nflteam_id . ", correct=" . $this->_correct . " WHERE user_id=" . $this->_user_id . " AND league_id=" . $this->_league_id . " AND year=" . $this->_year . " AND week=" . $this->_week;
}
$result = $this->SQLQuery($sql) or die (mysql_error() . ": $sql");
return $result; // boolean
}
/**
* Sets $_user_id
*
* @param integer $user_id
*/
function setUserID($user_id)
{
$this->_user_id = $user_id;
}
/**
* Returns $_user_id
*
* @return integer
*/
function getUserID()
{
return $this->_user_id;
}
/**
* Sets $_league_id
*
* @param integer $league_id
*/
function setLeagueID($league_id)
{
$this->_league_id = $league_id;
}
/**
* Returns $_league_id
*
* @return integer
*/
function getLeagueID()
{
return $this->_league_id;
}
/**
* Sets $_year
*
* @param integer $year
*/
function setYear($year)
{
$this->_year = $year;
}
/**
* Returns $_year
*
* @return integer
*/
function getYear()
{
return $this->_year;
}
/**
* Sets $_week
*
* @param integer $week
*/
function setWeek($week)
{
$this->_week = $week;
}
/**
* Returns $_week
*
* @return integer
*/
function getweek()
{
return $this->_week;
}
/**
* Sets $_nflteam_id
*
* @param integer $nflteam_id
*/
function setNFLTeamID($nflteam_id)
{
$this->_nflteam_id = $nflteam_id;
}
/**
* Returns $_nflteam_id
*
* @return integer
*/
function getNFLTeamID()
{
return $this->_nflteam_id;
}
/**
* Sets $_correct, converting to internal integral boolean type
*
* @param boolean $correct
*/
function setCorrect($correct)
{
if ($correct)
{
$this->_correct = 1;
}
else
{
$this->_correct = 0;
}
}
/**
* Returns $_correct, converted to boolean
*
* @return boolean
*/
function getCorrect()
{
if ($this->_correct == 1)
{
return TRUE;
}
return FALSE;
}
function getLPLPicks($league_id = NULL, $year = NULL, $week = NULL, $where = NULL, $order = NULL)
{
$ret_arr = array();
$sql = 'SELECT * FROM leadpipelock';
if (isset($where))
{ $sql .= ' WHERE ' . $where; }
else
{
if (isset($league_id) || isset($year) || isset($week))
{
$wherecount = 0;
$sql .= ' WHERE ';
if (isset($league_id))
{
$sql .= 'league_id=' . $league_id;
$wherecount++;
}
if (isset($year))
{
if ($wherecount)
{ $sql .= ' AND '; }
$sql .= 'year=' . $year;
$wherecount++;
}
if (isset($week))
{
if ($wherecount)
{ $sql .= ' AND '; }
$sql .= 'week=' . $week;
$wherecount++;
}
}
}
if (isset($order))
{ $sql .= ' ORDER BY ' . $order; }
else
{ $sql .= ' ORDER BY user_id'; }
$this->SQLQuery($sql) or die (mysql_error() . ': ' . $sql);
for ($i = 0; $i < $this->SQLNumRows(); $i++)
{
$lpl = new OFFL_LPL(NULL, $league_id, $year, $week);
$lpl->setUserID($this->SQLResult($i, 'user_id'));
$lpl->setNFLTeamID($this->SQLResult($i, 'nflteam_id'));
$lpl->_new = FALSE;
$ret_arr[] = $lpl;
}
$this->SQLFreeResult();
return $ret_arr;
}
} // end OFFL_LPL class
?>