<?php
/**
* Contains the implementation of the {@link OFFL_WaiverPlayer} class
*
* @package offl
* @author Brad Schwie <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 player auction values in particular league.
*
* @package offl
*/
class OFFL_AuctionValue extends OFFL_DBObject
{
/**
* @var integer
*/
var $_player_id = NULL;
/**
* @var integer
*/
var $_league_id = NULL;
/**
* @var integer
*/
var $_auction_value = NULL;
/**
* Constructor
*
* Both parameters should be set together or not at all
* @param integer $player_id Optional: If set, loads auction value from database
* @param integer $league_id Optional: If set, loads auction value from database
* @see populate()
*/
function OFFL_AuctionValue ($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_AuctionValue object.";
error_log ($this->_emsg);
return FALSE;
}
$sql = "SELECT auction_value FROM auctionvalues WHERE player_id=" . $this->_player_id . " AND league_id=" . $this->_league_id;
$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");
if(mysql_num_rows($result) == 0)
{
$this->_emsg = "No auction values found for player_id " . $this->_player_id . " and league_id " . $this->_league_id . ".";
error_log ($this->_emsg);
return FALSE;
}
$this->_auction_value = mysql_result($result,0,"auction_value");
mysql_free_result($result);
return TRUE;
}
/**
* Saves the transaction to the database
*
* @return boolean TRUE if successful, FALSE otherwise
*/
function save()
{
if (is_null($this->_player_id) || is_null($this->_league_id))
{ return FALSE; }
$sql = "INSERT INTO auctionvalues (player_id, league_id, auction_value) VALUES (" . $this->_player_id . ", " . $this->_league_id . ", '" . $this->_auction_value . "')";
$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");
return TRUE;
}
/**
* Deletes this auction value
*
* {@link $_player_id} and {@link $_league_id} must be set
*
* @return boolean TRUE on success, FALSE otherwise
*/
function deleteAuctionValue()
{
if (isset($this->_player_id) && isset($this->_league_id))
{
$sql = "DELETE FROM auctionvalues WHERE player_id=" . $this->_player_id . " AND league_id=" . $this->_league_id;
$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");
return TRUE;
}
else
{
$this->_emsg = "Unable to delete auction value: control values not defined.";
error_log ($this->_emsg);
return FALSE;
}
}
/**
* Deletes all auction values
*
* {@link $_player_id} and {@link $_league_id} must be set
*
* @return boolean TRUE on success, FALSE otherwise
*/
function deleteAllAuctionValues()
{
if (isset($this->_player_id) && isset($this->_league_id))
{
$sql = "DELETE FROM auctionvalues";
$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");
return TRUE;
}
else
{
$this->_emsg = "Unable to delete auction values: 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 $player_id
*/
function setLeagueID($league_id)
{
$this->_league_id = $league_id;
}
/**
* @return integer
*/
function getLeagueID()
{
return $this->_league_id;
}
/**
* @param integer $auction_value
*/
function setAuctionValue($auction_value)
{
$this->_auction_value = $auction_value;
}
/**
* @return integer
*/
function getAuctionValue()
{
return $this->_auction_value;
}
/**
* Looks up all players on waivers, optionally for a single league
* @param integer $league_id Optional: if set, returns claims only for this league
* @return array Array of {@link OFFL_WaiverPlayer} objects
*/
function getAllAuctionValues($league_id=NULL)
{
$retArr = array();
$sql = "SELECT player_id, league_id FROM auctionvalues WHERE auction_value IS NOT NULL";
if (isset($league_id))
{ $sql .= " AND league_id=" . $league_id; }
$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");
for($i=0; $i<mysql_num_rows($result); $i++)
{
$w = new OFFL_AuctionValue(mysql_result($result,$i,"player_id"), mysql_result($result,$i,"league_id"));
array_push($retArr, $w);
}
mysql_free_result($result);
return $retArr;
}
} // end OFFL_AuctionValue class
?>