<?php
/**
 * Model dla klasy MfProduct
 *
 * @author ModGen
 */

class MfProduct extends DataObject{


	/**
	 * nazwa tabeli
	 */
	static $tableName = 'mf_product';

	/**
	 * nazwa klucza tabeli
	 */
	static $classTablePK = 'id_mf_product';

	/**
	 * nazwa klasy
	 */
	static $className = __CLASS__;

	/**
	 * tablica mapująca pola klasy
	 */
	static $fields = array(
		'id_mf_product' => 'id',
		'publication' => 'publication',
		'weight' => 'weight',
		'date' => 'date',
		'id_mf_picture' => 'idMfPicture',
		'special' => 'special'
		//'id_structure' => 'idStructure'
	);


	protected $id;
	private $publication;
	private $weight;
	private $date;
	private $idMfPicture;
	private $special;
	private $idStructure;
	private $descriptionObj;



	// -- Konstruktor --


	function __construct( $id = -1 , $publication = null, $weight = null, $date = null, $idMfPicture = null, $special = null, $idStructure = null){
		$this->id = $id;
		$this->publication = $publication;
		$this->weight = $weight;
		$this->date = $date;
		$this->idMfPicture = $idMfPicture;
		$this->special = $special;
		$this->idStructure = $idStructure;
	}



	// -- Get-y i Set-y --

	public function getId(){
		return $this->id;
	}

	public function setId($id){
		$this->id = $id;
	}

	
	public function getPublication(){
		return $this->publication;
	}

	public function setPublication($publication){
		$this->publication = $publication;
	}

	
	public function getWeight(){
		return $this->weight;
	}

	public function setWeight($weight){
		$this->weight = $weight;
	}

	
	public function getDate(){
		return $this->date;
	}
	
	public function GetDatePublicationWithoutTime() {
		return substr($this->date, 0, -9);
	}

	public function GetDatePublicationTime() {
		if (!$this->date) {
			return '00';
		} else {
			return substr($this->date, 11, -6);
		}
		
	}

	public function setDate($date){
		$this->date = $date;
	}

	
	public function getIdMfPicture(){
		return $this->idMfPicture;
	}

	public function setIdMfPicture($idMfPicture){
		$this->idMfPicture = $idMfPicture;
	}

	
	public function getSpecial(){
		return $this->special;
	}

	public function setSpecial($special){
		$this->special = $special;
	}

	
	public function getIdStructure(){
		return $this->idStructure;
	}

	public function setIdStructure($idStructure){
		$this->idStructure = $idStructure;
	}

	

	public function GetDescriptionObj() {
		if(!is_object($this->descriptionObj)) {
			$dalData = MfProductDescriptionDAL::GetDalDataObj();
			$dalData->setCondition(array('publication' => 1, 'lang'=>$this->GetLang(), 'mf_product'=>$this->GetId()));
			
			$descriptionObj = MfProductDescriptionDAL::GetResult($dalData);
			if(isset($descriptionObj[0]) && is_object($descriptionObj[0])) {
				$this->SetDescriptionObj($descriptionObj[0]);
			} else {
				throw new UserException('Brak wersji jezykowej dla tego rekordu! ('.$this->GetId().' '.$this->GetLang().')');
			}
		}
		return $this->descriptionObj;
	}

	public function SetDescriptionObj($descriptionObj) {
		$this->descriptionObj = $descriptionObj;
	}
	public function SetMfProductDescription($descriptionObj) {
		$this->descriptionObj = $descriptionObj;
	}

	
	public function __call($name, $param) {

		$obj = $this->GetDescriptionObj();

		return $obj->$name($param);
	}
	


	/**
	* Pobiera nazwę tabeli reprezentującej obiekt w SQL
	* @return string
	*/
	public  function GetTableName(){
	return self::$tableName;
	}

	/**
	* Pobiera nazwę klucza głównego tabeli
	* @return string
	*/
	public function GetClassTablePK() {
		return self::$classTablePK;
	}

	/**
	* Pobiera tablice mapującą pola klasy na pola tabeli
	* @return array
	*/
	public  function GetFields(){
		return self::$fields;
	}

	/**
	* Pobiera nazwę klasy
	* @return string
	*/
	public  function GetClassName(){
		return self::$className;
	}



}

?>