<?php
/**
 * Klasa obsługi tablicy mf_product_attribute_category
 *
 */
class MfProductAttributeCategoryDAL extends DefaultDAL{


	protected static $objClassName =  'MfProductAttributeCategory';
	protected static $objClassTable = 'mf_product_attribute_category';
	protected static $objClassTablePK = 'id_mf_product_attribute_category';
	private static $optClass;

	


	public static function Save($obj) {
		if($obj->GetId()=='-1') {
			return self::DefaultInsert($dalObj);
		} else {
			return self::DefaultUpdate($dalObj);
		}
	}

	public static function Insert(DalData $dalObj) {
		return self::DefaultInsert($dalObj);
	}

	public static function Update(DalData $dalObj) {
		return self::DefaultUpdate($dalObj);
	}

	public static function GetById($id, $lang = 'pl') {
		$dalData = self::GetDalDataObj();
		$dalData->setCondition(array(self::GetObjClassName().'.'.self::GetObjClassTablePK()=>$id, 'lang' => $lang));
		if (class_exists(self::GetObjClassName().'Description')) {			
			$dalData->setJoin(array(self::GetObjClassName().'Description' => ' LEFT JOIN '.self::GetObjClassTable().'_description ON '.self::GetObjClassTable().'.id_'.self::GetObjClassTable().'='.self::GetObjClassTable().'_description.id_'.self::GetObjClassTable().''));		
		}
		$dalData->setLimit(1);
		$result = self::GetResult($dalData);
		if ((count($result) > 0) && (is_object($result[0]))) {
			return $result[0];
		} else {
			//throw new Exception('Brak rekordu w tablicy '.self::GetObjClassTable().' o id <b>'.$id.'</b>!');
			return self::GetEmptyObj();
			
			
		}
	}

	public static function Delete(DalData $dalObj) {
		return self::DefaultDelete($dalObj);
	}

	public static function GetResult(DalData $dalObj) {
		return self::DefaultGetResult($dalObj);
	}

	public static function GetResultByLink($table, $id ,$destination = false, $data = array(), $queryFields = array(), $limit = 0, $sortBy = null,$count = null)
	{
		$dalData = new DalData();
		$dalData->setObjClassName(self::GetObjClassName());
		$dalData->setObjClassTable(self::GetObjClassTable());
		$dalData->setObjClassTablePK(self::GetObjClassTablePK());
		$dalData->setOptClass(self::GetOptClass());
		$dalData->setCondition($data);
		$dalData->setQueryFields($queryFields);
		$dalData->setLimit($limit);
		$dalData->setSortBy($sortBy);
		$dalData->setCount($count);
		$dalData->setDataArray("mf_link_id", $id);
		$dalData->setDataArray("mf_link_table", $table);
		$dalData->setDataArray("mf_link_destination", $destination);
		return self::DefaultGetResultByLink($dalData);
	}


	public static function GetObjClassName() {
		if(self::$objClassName != '') {
			$class = self::$objClassName;
		} else {
			$class = ereg_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;
	}

	/**
	 *
	 * @return DalData $dalData
	 */
	public static function GetDalDataObj($params = array()) {

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

		return $dalData;
	}

}

?>