<?php
/**
 * Klasa do obsługi strony głownej
 *
 */
class MfHomeSiteBanerDAL extends DefaultDAL {

	protected static $objClassName;
	protected static $objClassTable;
	protected static $objClassTablePK;
	private static $optClass;

	public static function Save( $obj) {
		$id = null;
		if($obj->GetId()==-1) {
			$id = self::Insert($obj);
		} else {
			self::Update($obj);
			$id = $obj->GetId();
		}

		return $id;
	}


	/**
     * @param Feed $obj
     *
     */
	public static function Insert($obj) {

		$dalData = new DalData();
		$dalData->setObjClassTable(self::GetObjClassTable());
		$dalData->setObj($obj);
		$id = self::DefaultInsert($dalData);

		return $id;
	}
	/**
     * @param Text $obj
     *
     */
	public static function Update($obj) {
		//Utils::ArrayDisplay($obj);
		$dalData = new DalData();
		$dalData->setObjClassTable(self::GetObjClassTable());
		$dalData->setObjClassTablePK(self::GetObjClassTablePK());
		$dalData->setObj($obj);
		return self::DefaultUpdate($dalData);
	}

	/**
     *
     * @param integer $id
     *
     */
	public static function Delete($obj) {
		$dalData = new DalData();
		$dalData->setObjClassTable(self::GetObjClassTable());
		$dalData->setObjClassTablePK(self::GetObjClassTablePK());
		$dalData->setObj($obj);
		
		MfFileDescriptionDAL::DeleteByParentId($obj->GetId());
		
		return self::DefaultDelete($dalData);
	}

	/**
     *
     * @param  $id
     */
	public static function GetById($id) {
		$dalData = self::GetDalDataObj();
		$dalData->setCondition(array(self::GetObjClassTable().'.'.self::GetObjClassTablePK()=>$id));
		$dalData->setLimit(1);
		$result = self::GetResult($dalData);
		if ((count($result) > 0) && (is_object($result[0]))) {
			return $result[0];
		} else {
			return self::GetEmptyObj();
			//throw new Exception('Brak rekordu w tablicy '.self::GetObjClassTable().' o id <b>'.$id.'</b>!');
		}
	}
	
	public static function GetResult(DalData $dalData) {
		//$dalData->setJoin(array('MfFileDescription' => ' LEFT JOIN mf_file_description ON mf_file.id_mf_file=mf_file_description.id_mf_file'));
		return self::DefaultGetResult($dalData);
	}

	
	public static function GetEmptyObj() {
		//Utils::ArrayDisplay('tu jestem ');
		$obj = new MfHomeSiteBaner(-1);
		return $obj;
	}

	public static function GetArrayObjAll() {

	}


	/**
	 * Pusty konstruktor
	 *
	 */
	public function __construct() {

	}

	public static function GetObjClassName() {
		if(self::$objClassName != '') {
			$class = self::$objClassName;
		} else {
			$class = str_replace('DAL', '', __CLASS__);
		}

		return $class;
	}

	public static function GetOptClass() {
		if(self::$optClass!=null) {
			return self::$optClass;
		} else {
			return self::GetObjClassName();
		}
	}

	public static function GetObjClassTablePK() {
		if(self::$objClassTablePK != '') {
			$return = self::$objClassTablePK;
		} else {
			$class = self::GetObjClassName();
			$classObj = new $class();
			$return = $classObj->GetClassTablePK();
		}
		return $return;
	}

	public static function GetObjClassTable() {
		if(self::$objClassTable!='') {
			$return = self::$objClassTable;
		} else {
			$class = self::GetObjClassName();
			$classObj = new $class();
			$return = $classObj->GetTableName();
		}

		return $return;
	}
	
		/**
		 * Enter description here...
		 *
		 * @return DalData
		 */
		public static function GetDalDataObj() {

		$dalData = new DalData();
		$dalData->setObjClassName(self::GetObjClassName());
		$dalData->setObjClassTable(self::GetObjClassTable());
		$dalData->setObjClassTablePK(self::GetObjClassTablePK());
		$dalData->setOptClass(self::GetOptClass());
		//$dalData->setDatabaseType('dbTemp');

		return $dalData ;
	}
}
?>