<?php
/*
* Obiekt konfiguracyjny dla DALi
*/
class DalData {

	/*
	* nazwa klasy
	*/
	private $objClassName;
	/*
	* tablica klasy
	*/
	private $objClassTable;
	/*
	* primary key
	*/
	private $objClassTablePK;
	/*
	* klasa opcjonalna
	*/
	private $optClass;
	/*
	* warunki
	*/
	private $condition = array(); //$data
	/*
	* lista pol do selecta
	*/
	private $queryFields = array();
	private $selectFields = array();
	/*
	* limit
	*/
	private $limit = 0;
	/*
	* order by
	*/
	private $sortBy = null;
	/*
	* group by
	*/
	private $groupBy = null;
	/*
	* count w wyniku
	*/
	private $count = null;
	/*
	* zapytanie cacheowane
	*/
	private $cache = true;
	/*
	* tablica do joina
	*/
	private $join = null;
	/*
	* czas cache
	*/
	private $cacheTime = 0;
	/*
	* cacheowanie obiektow wynikowych
	*/
	private $cacheObject = 0;
	/*
	* obiekt do przeslania do dal
	*/
	private $obj;
	private $updateFileldArray;
	private $id;
	private $fieldName;
	private $updateFieldId;
	/*
	* handler do bazy db/sqlite
	*/
	private $databaseType = 'db';
	private $dataArray = array();


	public function getUpdateFieldId() {
		return $this->updateFieldId;
	}

	public function setUpdateFieldId($updateFieldId) {
		$this->updateFieldId = $updateFieldId;
	}



	public function __construct($data = array()) {

		if(is_array($data))
		{
			foreach($data as $key => $value)
			{
				eval ('self::set' . $key . '($value);');
			}
		}
	}


	public function getCacheTime() {
		return $this->cacheTime;
	}

	public function setCacheTime($cacheTime) {
		$this->cacheTime = $cacheTime;
	}

	public function getObjClassName() {
		return $this->objClassName;
	}

	public function setObjClassName($objClassName) {
		$this->objClassName = $objClassName;
	}

	public function getObjClassTable() {
		return $this->objClassTable;
	}

	public function setObjClassTable($objClassTable) {
		$this->objClassTable = $objClassTable;
	}

	public function getObjClassTablePK() {
		return $this->objClassTablePK;
	}

	public function setObjClassTablePK($objClassTablePK) {
		$this->objClassTablePK = $objClassTablePK;
	}

	public function getOptClass() {
		return $this->optClass;
	}

	public function setOptClass($optClass) {
		$this->optClass = $optClass;
	}

	public function getCondition() {
		return $this->condition;
	}

	public function setCondition($condition) {
		$this->condition = $condition;
	}

	public function addCondition($field, $value, $condition = null, $split = null) {
		if ($condition === null) {
			$this->condition[$field] = $value;
		} else {
			$this->condition[$field] = array('value' => $value, 'split' => $split, 'condition' => $condition);
		}
	}

	public function getQueryFields() {
		return $this->queryFields;
	}

	public function setQueryFields($queryFields) {
		$this->queryFields = $queryFields;
	}

	public function getLimit() {
		return $this->limit;
	}

	public function setLimit($limit) {
		$this->limit = $limit;
	}

	public function getSortBy() {
		return $this->sortBy;
	}

	public function setSortBy($sortBy) {
		$this->sortBy = $sortBy;
	}

	public function getCount() {
		return $this->count;
	}

	public function setCount($count) {
		$this->count = $count;
	}

	public function getCache() {
		return $this->cache;
	}

	public function setCache($cache) {
		$this->cache = $cache;
	}

	public function getJoin() {
		return $this->join;
	}

	public function setJoin($join) {
		$this->join = $join;
	}

	public function addJoin($name, $join) {
		$this->join[$name] = $join;
	}

	public function getCacheObject() {
		return $this->cacheObject;
	}

	public function setCacheObject($cacheObject) {
		$this->cacheObject = $cacheObject;
	}

	public function getObj() {
		return $this->obj;
	}

	public function setObj($obj) {
		$this->obj = $obj;
	}

	public function getUpdateFileldArray() {
		return $this->updateFileldArray;
	}

	public function setUpdateFileldArray($updateFileldArray) {
		$this->updateFileldArray = $updateFileldArray;
	}

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

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

	public function getFieldName() {
		return $this->fieldName;
	}

	public function setFieldName($fieldName) {
		$this->fieldName = $fieldName;
	}

	public function getDatabaseType() {
		return $this->databaseType;
	}

	public function setDatabaseType($databaseType) {
		$this->databaseType = $databaseType;
	}

	public function getDataArray($key) {
		if(isset($this->dataArray[$key]))
		return $this->dataArray[$key];
		else
		return null;
	}

	public function setDataArray($key,$value) {
		$this->dataArray[$key] = $value;
	}

	public function getSelectFields() {
		return $this->selectFields;
	}

	public function getSelectFieldsQuery()
	{
		if(count($this->selectFields) > 0 )
		{
			$q = " , ";
			foreach($this->selectFields as $key => $value)
			{
				$q.= $value . " as " . $key . ",";
			}
			return substr($q, 0, strlen($q)-1);
		}
		else
		return null;
	}

	public function addSelectFields($selectFields,$key) {
		if($key == null)
		$this->selectFields[] = $selectFields;
		else
		$this->selectFields[$key] = $selectFields;
	}

	public function getGroupBy() {
		return $this->groupBy;
	}

	public function setGroupBy($groupBy) {
		$this->groupBy = $groupBy;
	}

	public function getFields()
	{
		if(!is_null($this->obj))return $this->obj->GetFields();
		else return false;
	}

}

?>