<?php
/**
 * @author Krku
 * @date 2009-05-15 10:30:31
 */

/**
 * Description of PHPClass_1
 */
class PictureDAL extends DefaultDAL {
    protected static $objClassName;
    protected static $objClassTable;
    protected static $objClassTablePK;
    private static $optClass;

    public static function Save($obj) {
        return self::DefaultSave(self::GetObjClassTable(), self::GetObjClassTablePK(), $obj);
    }

    public static function Insert($obj) {
    	$dalData = new DalData();
		$dalData->setObjClassTable(self::GetObjClassTable());
		$dalData->setObj($obj);
        return self::DefaultInsert($dalData);
    }

    public static function Update($obj) {
    	//Utils::ArrayDisplay($obj);
        self::DefaultUpdate(self::GetObjClassTable(), self::GetObjClassTablePK(), $obj);
    }

    public static function Delete($id) {
        self::DefaultDelete(self::GetObjClassTable(), self::GetObjClassTablePK(), $id);
    }

    public static function GetArrayObjAll() {
        return self::GetResult(array());
    }

    public static function GetResult($data,$queryFields = array(),$limit = 0, $sortBy = null,$count = null, $cache = true) {
        return self::DefaultGetResult(self::GetOptClass(), self::GetObjClassTable(), self::GetObjClassName(), $data, $queryFields, $limit, $sortBy, $count, $cache);
    }

    public static function GetById($id) {
    	$dalData = self::GetDalDataObj();
		$dalData->setCondition(array(self::GetObjClassTablePK()=>$id));
		$dalData->setLimit(1);
		
	
    	
        return self::DefaultGetById($dalData);
    }

    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;
	}
    
    	
		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;
	}
}
?>
