Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/lib/classes/offl_tradeprotest.php
<?php
/**
 * Defines the {@link OFFL_TradeProtest} 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 trade protests.
 *
 * @package offl
 */
class OFFL_TradeProtest extends OFFL_DBObject
{
	/**
	 * @var integer OFFL_TradeProtest UID
	 */
	var $_protest_id;
	/**
	 * @var integer {@link OFFL_Trade} UID this protest references
	 */
	var $_trade_id;
	/**
	 * @var integer {@link OFFL_FFLTeam} UID filing this protest
	 */
	var $_fflteam_id;

	/**
	 * Constructor
	 *
	 * @param integer $protest_id Optional: If set, loads trade protest from database
	 * @see populate()
	 */
	function OFFL_TradeProtest ($protest_id = NULL)
	{
		OFFL_DBObject::OFFL_DBObject();

		if(isset($protest_id))
		{
			$this->_protest_id = $protest_id;
			$this->populate();
		}
	}

	/**
	 * Pulls info from database.  {@link $_protest_id} must be set.
	 * @return boolean TRUE if successful, FALSE otherwise.
	 */
	function populate ()
	{
		if(is_null($this->_protest_id))
		{
			$this->_emsg = "\$_protest_id is not set.  Cannot populate OFFL_TradeProtest object.";
			error_log ($this->_emsg);
			return FALSE;
		}
		$sql = "SELECT * FROM tradeprotests WHERE protest_id=" . $this->_protest_id;
		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");

		if(mysql_num_rows($result) == 0)
		{
			$this->_emsg = "No trade protest records found for protest_id " . $this->_protest_id . ".";
	        error_log ($this->_emsg);
			return FALSE;
		}
        $this->_protest_id = mysql_result($result,0,"protest_id");
        $this->_trade_id = mysql_result($result,0,"trade_id");
        $this->_fflteam_id = mysql_result($result,0,"fflteam_id");
		mysql_free_result($result);
		return TRUE;
	}

	/**
	 * Saves the user to the database.  Determines SELECT vs INSERT automagically.
	 */
	function save ()
	{
		if (is_null($this->_protest_id)) // insert a new waiver
		{
			$sql = "INSERT INTO tradeprotests (trade_id, fflteam_id) VALUES (" . $this->_trade_id . ", " . $this->_fflteam_id . ")";
		}
		else // update an existing waiver
		{
			$sql = "UPDATE tradeprotests SET trade_id=" . $this->_trade_id . ", fflteam_id=" . $this->_fflteam_id . " WHERE protest_id=" . $this->_protest_id;
		}
	    $result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");
		return $result;
	}

	/**
	 * @return integer
	 */
	function getProtestID()
	{
		return $this->_protest_id;
	}

	/**
	 * @param integer $trade_id
	 */
	function setTradeID($trade_id)
	{
		$this->_trade_id = $trade_id;
	}

	/**
	 * @return integer
	 */
	function getTradeID()
	{
		return $this->_trade_id;
	}

	/**
	 * @param integer $fflteam_id
	 */
	function setFFLTeamID($fflteam_id)
	{
		$this->_fflteam_id = $fflteam_id;
	}

	/**
	 * @return integer
	 */
	function getFFLTeamID()
	{
		return $this->_fflteam_id;
	}

	/**
	 * Checks number of trade protests lodged against this trade.  {@link $_trade_id} must be set.
	 *
	 * This function should probably move to the {@link OFFL_Trade} class.  Check that when rewriting it.
	 * @return integer Number of associated trade protests found, FALSE if {@link $_trade_id} not set
	 */
	function getNumberOfTradeProtests()
	{
		if(is_null($this->_trade_id))
		{
			$this->_emsg = "\$_trade_id is not set.  Cannot retrieve OFFL_TradeProtest objects.";
			error_log ($this->_emsg);
			return FALSE;
		}
		$sql = "SELECT protest_id FROM tradeprotests WHERE trade_id=" . $this->_trade_id;
		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");
		$count = mysql_num_rows($result);
		mysql_free_result($result);
		return $count;
	}

	/**
	 * Deletes this protest from the database
	 * @return boolean TRUE on success, FALSE otherwise ({@link $_protest_id} not defined)
	 */
	function deleteTradeProtest()
	{
		if(isset($this->_protest_id))
		{
			$sql = "DELETE FROM tradeprotests WHERE protest_id=" . $this->_protest_id;
			$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");
			mysql_free_result($result);
			return TRUE;
		}
		$this->_emsg = "Unable to delete trade protest: protest_id not defined.";
        error_log ($this->_emsg);
		return FALSE;
	}

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