Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/lib/classes/offl_position.php
<?php
/**
 * Defines the {@link OFFL_Position} 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 FFL player positions.
 *
 * This class is populated at FFL install time and there's no reason to use the save or setXXX functions.
 * They're provided only for completeness.
 *
 * @package offl
 */
class OFFL_Position extends OFFL_DBObject
{
	/**
	 * @var integer
	 */
	var $_position_id = NULL;
	/**
	 * @var string
	 */
	var $_position_abbv = NULL;
	/**
	 * @var string
	 */
	var $_position_name = NULL;

	/**
	 * Constructor
	 *
	 * @param integer $position_id Optional: If set, loads given position from database
	 */
	function OFFL_Position ($position_id = NULL)
	{
		OFFL_DBObject::OFFL_DBObject();

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

	    if(mysql_num_rows($result) == 0)
		{
	        $this->_emsg = "No records found for position_id $this->_position_id.";
			error_log ($this->_emsg);
			return FALSE;
	    }
        $this->_position_abbv = htmlspecialchars(stripslashes(mysql_result($result,0,"position_abbv")));
		$this->_position_name = htmlspecialchars(stripslashes(mysql_result($result,0,"position_name")));
	    mysql_free_result($result);
		return TRUE;
	}

	/**
	 * Saves info into database.  Determines UPDATE or INSERT automagically.
	 */
	function save ()
	{
		if(is_null($this->_position_id))
	    { // insert
		    $sql = "INSERT INTO positions (position_abbv, position_name) VALUES ('" . mysql_escape_string($this->_position_abbv) . "', '" . mysql_escape_string($this->_position_name) . "')";
	    }
		else
	    { // update
		    $sql = "UPDATE positions SET position_abbv='" . mysql_escape_string($this->_position_abbv) . "', position_name='" . mysql_escape_string($this->_position_name) . "' WHERE position_id=" . $this->_position_id;
	    }
	    $result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");
		return $result;
	}

	/**
	 * @return integer
	 */
	function getPositionID()
	{
		return $this->_position_id;
	}

	/**
	 * @param string $position_abbv
	 */
	function setPositionAbbv($position_abbv)
	{
		$this->_position_abbv = $position_abbv; 
	}

	/**
	 * @return string
	 */
	function getPositionAbbv()
	{
		return $this->_position_abbv;
	}

	/**
	 * @param string $position_name
	 */
	function setpositionName($position_name)
	{
		$this->_position_name = $position_name; 
	}

	/**
	 * @return string
	 */
	function getpositionName()
	{
		return $this->_position_name;
	}


	/**
	 * @return array Returns an array of all OFFL_Position objects
	 */
	function getAllPositions()
	{
		$retArr = array();
	    $sql = "SELECT position_id FROM positions ORDER BY position_id";
		$result = mysql_query($sql,$this->_conn) or die (mysql_error() . ": $sql");

	    for($i=0; $i<mysql_num_rows($result); $i++)
		{
		    $pos = new OFFL_Position(mysql_result($result,$i,"position_id"));
		    array_push($retArr, $pos);
	    }
  		mysql_free_result($result);

		return $retArr;
	}

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