<?php
/**
* Contains the implementation of the {@link OFFL_TradePlayer} 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 which players are involved in a pending trade ("trade lock") in a particular league.
*
* This was part of the player class in earlier versions of FFL, but has been broken out to accomodate multiple leagues.
*
* The trade lock notion is that players involved in a pending trade (accepted but not yet completed, either due to protest
* period or roster conflict) are not eligible for drop or trade, as that would preempt a legal transaction. This tracks the
* status of those players. Trade lock has an expiry, rather than a simple boolean status, so that trades held up by roster
* violations cannot be strung out indefinitely in order to "hold hostage" another team's roster. However, the timestamp itself
* is contained in the {@link OFFL_Trade} class, so trade lock here is a simple boolean.
*
* @package offl
*/
class OFFL_TradePlayer extends OFFL_DBObject
{
/**
* @var integer
*/
var $_player_id = NULL;
/**
* @var integer
*/
var $_league_id = NULL;
/**
* @var integer
*/
var $_tradelock = 0;
/**
* Constructor
*
* Both parameters should be set together or not at all
* @param integer $player_id Optional: If set, loads trade/player from database
* @param integer $league_id Optional: If set, loads trade/player from database
* @see populate()
*/
function OFFL_TradePlayer ($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_TradePlayer object.";
error_log ($this->_emsg);
return FALSE;
}
$sql = "SELECT tradelock FROM tradeplayers 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 trade/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->_tradelock = mysql_result($result,0,"tradelock");
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 tradeplayers (player_id, league_id, tradelock) VALUES (" . $this->_player_id . ", " . $this->_league_id . ", " . $this->_tradelock . ")";
$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");
return $result;
}
/**
* Deletes this player/waiver note
*
* {@link $_player_id} and {@link $_league_id} must be set
*
* @return boolean TRUE on success, FALSE otherwise
*/
function deleteTradePlayer()
{
if (isset($this->_player_id) && isset($this->_league_id))
{
$sql = "DELETE FROM tradeplayers 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;
}
$this->_emsg = "Unable to delete TradePlayer 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 $tradelock
*/
function setTradelock($tradelock)
{
$this->_tradelock = $tradelock;
}
/**
* @return integer
*/
function getTradelock()
{
return $this->_tradelock;
}
} // end OFFL_TradePlayer class
?>