class_BasisDesign.inc.php 5.47 KB
<?php
/**
 * @file	BasisDesign.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/>.
 * 
 */
abstract class BasisDesign extends aLosp implements iBasisDesign {

	/**
	 * @var int Object ID
	 */
	protected $ID;

	/**
	 * @var array CSS Keys
	 */
	protected $Values = array();

	/**
	 * @var string Klassenname wofür dieses Design sein soll
	 */
	protected $BEClassName;

	protected $Miscellaneous = null;
	protected $DefaultBC = null;
	protected $CDate;
	protected $CSS;
	protected $Author_ProfileID;
	
	//public function __construct(iBasicSql $param_DB, $param_BEClassName=null, $param_ID=null) {
	public function __construct(iStorable &$param_DB, $param_BEClassName=null, $param_ID=null) {
		$this->DB = $param_DB;
		$this->ID = $param_ID;
		$this->BEClassName = $param_BEClassName;
		$this->ThisClassName = get_class($this);		
	}	
	
	public static $Cache_BasisDesignArray = array();
	public static function &loadElement(Account &$param_HostAccount, iStorable &$param_iStorable, $param_Class, $param_ID, $param_BEClassName=null) {		
		
		if($param_ID && array_key_exists($param_ID, self::$Cache_BasisDesignArray) && self::$Cache_BasisDesignArray[$param_ID] ) {
			return self::$Cache_BasisDesignArray[$param_ID];
		} else {
			if(is_subclass_of($param_Class,"BasisDesign") && is_subclass_of($param_iStorable,"iBasicSql")){
				$new = new $param_Class($param_iStorable, $param_BEClassName, $param_ID);
				$new->loadObject($param_HostAccount, $param_iStorable);
				self::$Cache_BasisDesignArray[$param_ID] =& $new;
				return $new;
			} else {
				return false;
			}
		}
	
	}
	/**
	 * only CSS, Miscellaneous Value[menu_sort]
	 * 
	 * @param $param_ImportData
	 */
	public function import($param_ImportData) {
		if(get_class($param_ImportData)=='SimpleXMLElement') {
			
			//import Attribute
			$var_attr=$param_ImportData->attributes();
			$this->CSS = (string)$var_attr['CSS'];			 
			//$Author_ProfileID geht keinen was an
			if($param_ImportData->Miscellaneous)
				$this->Miscellaneous = (string)$param_ImportData->Miscellaneous[0];
			
			//import Values			
			foreach($param_ImportData->Values[0]->children() as $for_cvalue) {
							
				if((string)$for_cvalue['key']==CONSTKindOf::DESIGN_MENUSORT){
					$this->Values = array((string)$for_cvalue['key'] => (string)$for_cvalue['value']);						
				}				
			}
		}
		
	}
	public function setData(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_Data) {
		
		if(array_key_exists('Values', $param_Data)) {
			$param_Data['Values'] = Form::formValuesToArrayValues($param_Data['Values']);
		}
		parent::setData($param_HostAccount, $param_iStorable, $param_Data);		
	}

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

		$DOMElement = parent::getObjDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument, $param_KindOf, $param_DOMElemente);
		$DOMElement->setAttribute('ID', $this->ID);
		$DOMElement->setAttribute('BEClassName', $this->BEClassName);
		$DOMElement->setAttribute('CDate', $this->CDate);
		$DOMElement->setAttribute('CSS', $this->CSS);
		$DOMElement->setAttribute('Author_ProfileID', $this->Author_ProfileID);
		
		$DOMElement->appendChild($param_DOMDocument->createElement('DefaultBC',$this->DefaultBC));
		
		if( $this->Miscellaneous != null){
			BasisElement::setMultimediaInText($this->Miscellaneous,CONSTKindOf::MULTIMEDIA_SIZE_SMALL);						
			$DOMElement->appendChild($param_DOMDocument->createElement('Miscellaneous',$this->Miscellaneous));
		}

		if(is_array($this->Values) && count($this->Values)>0) {
			$DOMElement->appendChild(DOMElementHelper::valuesToXml($param_DOMDocument, $this->Values));
		}
		return $DOMElement;
	}
	/*
	 * transforms the Data BasisElementDesign input Array into one css String	 *
	 *
	 * @param array param_DataBasisElementDesign
	 * @return String css
	 */
	public static function fnc_transformToCssString($param_DataBasisElementDesign){
//		D::show($param_DataBasisElementDesign, fnc_transformToCssString, 1,1);

		$whiteList='/([^(A-Za-z0-9_#:\[\]\/\-\.])/';
		$return_css='';
		if(array_key_exists('input', $param_DataBasisElementDesign) && array_key_exists('CSS', $param_DataBasisElementDesign)){

			foreach($param_DataBasisElementDesign['input'] as $key => $value){
				$return_css.=$key.'{';

				foreach($value as $key => $value){


					$return_css.=$key.':';

					if(preg_match($whiteList,$value)==0){
						if($key == 'background-image'){
							$value='url("'.$value.'")';
						}
						$return_css.=$value;
					}
					$return_css.=';';


				}
				$return_css.='}';
			}
		}
//D::li($return_css,1,1)		;
		return ($param_DataBasisElementDesign['CSS']=$return_css);
	}
	
	public function getDefaultBC(){
		return $this->DefaultBC;
	
	}
}
?>