class_aLosp.inc.php 6.2 KB
<?php
/**
 * @file	aLosp.inc.php
 * @category freeSN
 * @mailto	code [at] netz.coop
 * @version 0.4.200901
 * @link http://netz.coop
 * 
 *  @copyright Copyright by netz.coop e.G. 2015
 *  
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

//	AbstractLospClass => aLosp
abstract class aLosp implements iLosp {

	protected $DB;
	protected $VirtualData;
	protected $RequestProfileID;

	public $ThisClassName;

	public function __toString() {

		if(is_subclass_of($this, 'BasisElement')) {
			$var_string = "obj(".get_class($this)." ID[".$this->ID."]BEN[".$this->BasisElementNumber."])";
			//		} else if(is_subclass_of($this, 'iBasisElement')) {
			//			$var_string = "obj(".get_class($this)."";
			//			if(is_object($this->MText)) {
			//				$var_string .=		" MTextID[".$this->MText->getObjVar('ID')."])";
			//			} else if (is_object($this->Obj)) {
			//				$var_string .=		" MTextID[".$this->Obj->getObjVar('ID')."])";
			//			} else {
			//				$var_string .=		" kein MText)";
			//			}
		} else if(is_subclass_of($this, 'iBasisElementAddon')) {
			$var_string = 'obj('.get_class($this).') - ';

			if(property_exists($this,'BasisClipboard') && is_object($this->BasisClipboard)) {
				$var_string .='[BC('.property_exists($this,'BasisClipboard').')';
				$var_string .= 'PartOfID('.$this->BasisClipboard->getObjVar('PartOfID').')->'.get_class($this->BasisClipboard).'::'.$this->BasisClipboard->getObjVar('CategoryName');
				$var_string .=']';
			}

			if(property_exists($this,'MText') && is_object($this->MText)) {
				$var_string .= ' [BE('.property_exists($this,'MText').')';
				$var_string .= 'ID('.$this->MText->getObjVar('ID').')';
				$var_string .= ']';
			}


		} else if(is_subclass_of($this, 'BasisDesign')) {
			$var_string = "obj(".$this->BEClassName." ".get_class($this)."['.$this->ID.']) ";
		} else if(get_class($this)=== 'RightManagementBC') {
			$var_string = "obj(".get_class($this)."['.$this->PartOfObj.']) ";
		} else  {
			$var_string = "obj(".get_class($this)."['.$this->ID.']) komisch";
		}
		return $var_string;
	}

	/**
	 * return the Obj Var param_ObjVar
	 *
	 * @param string param_ObjVar
	 * @return
	 */
	public function &getObjVar($param_ObjVar) {
		$ObjVar = trim($param_ObjVar);
		return $this->$ObjVar;
	}

	public function setObjVar($param_ObjVar, $param_Value) {
		//		if(get_class($this)=='Category') {
		//			D::li($this."->setObjVar($param_ObjVar, ".count($param_Value).")");
		//		}
		$ObjVar = trim($param_ObjVar);
		if(!is_object($param_Value)){
			$this->$ObjVar = Converter::decodeString($param_Value);
		} else {
			$this->$ObjVar =  $param_Value;
		}
	}


	/**
	 * return Value from Object Var Array
	 * @param string param_ObjVar Object Var
	 * @param string param_ObjVarArrayKey description
	 */
	public function getObjVarArrayValue($param_ObjVar, $param_ObjVarArrayKey) {
		if(is_array($this->$param_ObjVar) && array_key_exists($param_ObjVarArrayKey, $this->$param_ObjVar)) {
			return $this->$param_ObjVar[$param_ObjVarArrayKey];
		} else {
			return false;
		}
	}

	/**
	 * set Value in Object Var Array
	 * @param array param_ObjVar array( ObjVar => ArrayKey) -> self::ObjVar[ArrayKey]
	 */
	public function setObjVarArrayValue($param_ObjVar, $param_ObjVarArrayKey, $param_Value) {

		if(is_array($this->$param_ObjVar)) {
			$this->$param_ObjVar[$param_ObjVarArrayKey] = $param_Value;
		}
	}



	/**
	 * lädt das Objekt aus der Datenbank
	 *
	 *
	 * @param param_Parameter zusätzliche Parameter
	 *
	 * @return object wenn erfolgreich || false wenn fehlgeschlagen
	 */
	public function loadObject(Account &$param_HostAccount, iStorable &$param_iStorable, $param_Parameter=null){
		$this->RequestProfileID = $param_HostAccount->getActiveProfileID();
		if($param_iStorable->loadObject($this, $param_HostAccount, $param_Parameter)) {
			return $this;
		} else {
			return false;
		}
	}

	public function saveObject(Account &$param_HostAccount, iStorable &$param_iStorable) {
		$param_iStorable->saveObject($this, $param_HostAccount);
		return $param_iStorable->loadObject($this, $param_HostAccount);
	}

	public function setVirtualData(array $param_VirtualData) {
		foreach($param_VirtualData as $CallbackFunctionName => $Data) {
			$this->VirtualData[$CallbackFunctionName] = $Data['result'];
		}
	}
	/**
	 * @todo funktion sollte überflüssig sein, da Converter::decodeString nix macht ausser param zurückgeben!!!??? 100615
	 */
	public function setData(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_Data) {
		if($param_Data!=null) {

			$keys = array_keys($param_Data);
			$count_i = count($param_Data);
			for($i=0; $i<$count_i; $i++) {
				if(property_exists($this, $keys[$i])) {
					if(!is_object($param_Data[$keys[$i]])){
						$this->$keys[$i] = Converter::decodeString($param_Data[$keys[$i]]);						
					} else {
						$this->$keys[$i] =  $param_Data[$keys[$i]];
					}
				}
			}			
			return true;
		} else {
			return false;
		}
	}

	public function getObjDOMElement(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, $param_KindOf=null, array $param_DOMElemente=null) {

		if(is_subclass_of($this, 'BasisElement')) {
			$DOMElement = $param_DOMDocument->createElement('BasisElement');
		} else {
			$DOMElement = $param_DOMDocument->createElement(get_class($this));
		}
		$DOMElement->setAttribute('class', get_class($this));

		$DOMElement->setAttribute('label', Language::getWord(get_class($this)));

		if($param_KindOf=='form') {
			$DOMElement->setAttribute('edit', 'true');
		}

		if(is_array($this->VirtualData)) {
			return DOMElementHelper::arrayToXml($param_DOMDocument, $this->VirtualData, $DOMElement);
		} else {
			return $DOMElement;
		}

		//		return $DOMElement;
	}

}

?>