class_mcPUIX.inc.php 9.35 KB
<?php
interface imcPUIX {
	public function getDOMElement_edit(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, DOMElement &$param_DOMElement, $param_KindOf=null, array $param_DOMElemente=null);
	public function getDOMElement_show(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, DOMElement &$param_DOMElement, $param_KindOf=null, array $param_DOMElemente=null);
	public function manipulatePost_Data(Account &$param_HostAccount, iStorable &$param_iStorable, array &$param_Data);
	
	public function setRootTable();
}


abstract class  mcPUIX extends mcClass implements imcPUIX {
	const DBUIConfig = 'DBUIConfig';
	const PUIX_SUB_REFERENCELIST = 'PUIX_SUB_REFERENCELIST'; // mcPUIX::PUIX_SUB_REFERENCELIST
	
	const PDOValues = 'PDOValues';
	const PDOToSaveValues = 'PDOToSaveValues';
	
	const PDOLoadDepth = 'PDOLoadDepth';
	
	const DOMmcPUIX = 'mcPUIX';
	const DOMmcPUIX_edit = 'DOMmcPUIX_edit';
	const DOMmcPUIX_show = 'DOMmcPUIX_show';
	const DOMRow = 'DBUIRow';
	const DOMList = 'DBUIList';
	const DOMElement = 'DBUIElement';
	const DOMValues = 'DOMValues';	
	##
	
	

	// PUIXArray evt überprüfen
	const PUIXArray = 'PUIXArray';

//	const FORMValues = 'DBUIFormValues'; mcPUIX::FORM_DO_ROW
	
	const FORM_POST_VALUES = 'FORM_POST_VALUES';
	
	
	const FORM_REQUIRED = 'FORM_REQUIRED';		// mcPUIX::FORM_REQUIRED
	const FORM_NEW_ROW = 'FORM_NEW_ROW';		// mcPUIX::FORM_NEW_ROW
	const FORM_DO_VAR = 'FORM_DO_VAR';			// mcPUIX::FORM_DO_VAR
	const FORM_DO_ROW = 'FORM_DO_ROW';			// mcPUIX::FORM_DO_ROW
	const FORM_DO_SAVE = 'FORM_DO_SAVE';		// mcPUIX::FORM_DO_SAVE
	const FORM_DO_DELETE = 'FORM_DO_DELETE';	// mcPUIX::FORM_DO_DELETE
	const FORM_DO_NEW = 'FORM_DO_NEW';			// mcPUIX::FORM_DO_NEW
	const FORM_DO_SELECT = 'FORM_DO_SELECT';	// mcPUIX::FORM_DO_SELECT
	
	const FORM_TYPE_SEOLINK = 'FORM_TYPE_SEOLINK';
	const FORM_TYPE_BASISELEMENT_SHORT = 'FORM_TYPE_BASISELEMENT_SHORT';
	
	const STATE_LOADED = 'loaded';
	const STATE_CHANGED = 'changed';
	const STATE_SAVED = 'saved';
	private $DBTab_State = array();
	
	protected $RootTable;
	
	/**
	 *
	 * @var array('tablename' => array(mcPUIX::PUIXArray => array()))
	 */
	private $DBTab = array();
	/**
	 *
	 * @var aBasisElementAddon
	 */
	protected $PUIXHostObject = null;
	
	public $ThisClassName;
	
	public function __construct( $PUIXHostObject) {
		$this->mcID = mcObjectStatistic::getCount__construct($this);
		$this->PUIXHostObject = $PUIXHostObject;
		$this->ThisClassName = get_class($this);
		$this->setRootTable();
	}
	
	protected $SearchAttributes = null;
	public function setSearchAttributes(array $param_SearchAttributes) {
		$this->SearchAttributes = $param_SearchAttributes;
	}
	
	private function setTableValues($param_tablename, $param_tablevalues) {
		$this->DBTab[$param_tablename] = $param_tablevalues;
	}
	public function getTableValues($param_tablename) {
		return $this->DBTab[$param_tablename];
	}	
	public function loadPDOTable(Account &$param_HostAccount, iStorable &$param_iStorable, $param_SQLWhere='', $param_depth=null) {
		$param_tablename = $this->RootTable;
		
		if($param_SQLWhere==='' && !is_null($this->SearchAttributes)) {
			$param_SQLWhere = ' where  ';
			$bool_AND = false;
			foreach($this->SearchAttributes as $col => $val) {
				if($col === mcPUIX::PDOLoadDepth) {
					$param_depth = $val;
				} 
				else if($col !== mcPUIX::PUIX_SUB_REFERENCELIST) {
					if($bool_AND) {
						$param_SQLWhere .= ' AND ';
					} else {
						$bool_AND = true;
					}
					$param_SQLWhere .= ' '.$col.'="'.$val.'" ';					
				}
			}
		}
		
		if(is_null($param_depth)) {
			$param_depth = 0;
		}
		
		$DBTable = mcPUIX_PDO::getTableAsDBUIArray($param_HostAccount, $param_iStorable, $param_tablename, $param_SQLWhere, $param_depth);
//		D::show($DBTable, '$DBTable '.$this->PUIXHostObject);
		$this->setTableValues($param_tablename, $DBTable);	
		$this->DBTab_State[$param_tablename] = mcPUIX::STATE_LOADED;
	}

	
	public function  setData(Account &$param_HostAccount, iStorable &$param_iStorable, $param_values) {
		$param_tablename = $this->RootTable;
		D::ulli(__CLASS__.'::'.__FUNCTION__.': ' . $param_tablename.' ## '.mcPUIX::STATE_CHANGED);
		
		if(is_object($this->PUIXHostObject)) {
			if(mcArray::checkKeyHasFullArray($param_values, get_class($this->PUIXHostObject))) { 
				$values = $param_values[get_class($this->PUIXHostObject)];
			} else {
				return false;
			}
		} else {
			$values = $param_values;
		}

		if(mcArray::checkKeyHasFullArray($values, $this->ThisClassName, mcPUIX::PUIXArray, mcPUIX::FORM_POST_VALUES)) {
			$this->manipulatePost_Data($param_HostAccount, $param_iStorable, $values[$this->ThisClassName][mcPUIX::PUIXArray][mcPUIX::FORM_POST_VALUES]);
		}

		$this->setTableValues($param_tablename, $values[$this->ThisClassName]);	
		$this->DBTab_State[$param_tablename] = mcPUIX::STATE_CHANGED;		
		
	}

	public function savePDOTable(Account &$param_HostAccount, iStorable &$param_iStorable) { 
		$param_tablename = $this->RootTable;
		$DBUIArray_Values = $this->getTableValues($param_tablename);
		
//		D::show($this->DBTab , '$this->DBTab');
				
		$ManipulateTableConfig = null;
		$DBUIConfig = mcPUIX_CONFIG::getTableConfig($param_tablename, $ManipulateTableConfig);
//		D::show($DBUIConfig, '$DBUIConfig');
		if(mcArray::checkKeyHasFullArray($DBUIConfig, mcPUIX::PUIXArray, mcPUIX::DBUIConfig, $param_tablename, 'TABLE', mcPUIX::PUIX_SUB_REFERENCELIST, 'TABLENAME')) {
			$Tablename_LIST = mcPUIX_CONFIG::getReferenceTableName($param_tablename);
			$ManipulateTableConfig = null;
			$DBUIConfig_LIST = mcPUIX_CONFIG::getTableConfig($Tablename_LIST, $ManipulateTableConfig);
			$DBUIConfig[mcPUIX::PUIXArray][mcPUIX::DBUIConfig][$Tablename_LIST] = $DBUIConfig_LIST[mcPUIX::PUIXArray][mcPUIX::DBUIConfig][$Tablename_LIST];

		}
		
//		D::show($DBUIArray_Values, $param_tablename);
		$PreparedArray = mcPUIX_PDO::prepareArrayForDBOperation($param_tablename, $DBUIConfig, $DBUIArray_Values);
		
//		D::show($PreparedArray, '$PreparedArray = mcPUIX_PDO::prepareArrayForDBOperation');
		
		$DBUIArrayNew = mcPUIX_PDO::updateDatabaseTable($param_HostAccount, $param_iStorable, $DBUIConfig, $PreparedArray);
		$this->setTableValues($param_tablename, $DBUIArrayNew);
		$this->DBTab_State[$param_tablename] = mcPUIX::STATE_SAVED;
		
		if(is_array($this->SearchAttributes)) {
			$this->loadPDOTable($param_HostAccount, $param_iStorable);
		}
	}
	
	protected function getFormPathToThis() {
			$formpath = '';
			if(is_object($this->PUIXHostObject)) {
				$formpath .= '['.get_class($this->PUIXHostObject).']';
			}
			$formpath .= '['.$this->ThisClassName.']['.mcPUIX::PUIXArray.']['.mcPUIX::FORM_POST_VALUES.']';
			return $formpath;
	}
	
	public function getObjDOMElement(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, $param_KindOf=null, array $param_DOMElemente=null) {

		$DOMElement = $param_DOMDocument->createElement(mcPUIX::DOMmcPUIX);
		$DOMElement->setAttribute('class', get_class($this));
		$DOMElement->setAttribute('label', Language::getWord(get_class($this)));

		if($param_KindOf=='form') {
			$DOMElement_edit = $param_DOMDocument->createElement(mcPUIX::DOMmcPUIX_edit);
			$DOMElement_edit->setAttribute('edit', true);

			$DOMElement_edit->setAttribute('formpath', $this->getFormPathToThis());
			$DOMElement->appendChild($DOMElement_edit);					
			$this->getDOMElement_edit($param_HostAccount, $param_iStorable, $param_DOMDocument, $DOMElement_edit, $param_KindOf, $param_DOMElemente);
		}
		
		$DOMElement_show = $param_DOMDocument->createElement(mcPUIX::DOMmcPUIX_show);
		$DOMElement->appendChild($DOMElement_show);					
		$this->getDOMElement_show($param_HostAccount, $param_iStorable, $param_DOMDocument, $DOMElement_show, $param_KindOf, $param_DOMElemente);
		
		return $DOMElement;

	}

	protected static $unsetCONFIG = true;
	public static function setmcPUIX_CONFIG(array $param_Configs) {
		if(mcPUIX::$unsetCONFIG) {
			foreach($param_Configs as $tablename => $values) {
//				D::show($values, $tablename);
				mcPUIX_CONFIG::setTableConfig($tablename, $values);
			}			
			mcPUIX::$unsetCONFIG = false;
		}
	}	
	protected static $Tables = array ();
	
	public function walk_ListElements(Account &$param_HostAccount, iStorable &$param_iStorable, $param_tablename, array $param_callbackfncForList=null, array $param_callbackfncForListElements=null) {
		if(mcArray::checkKeyHasFullArray($this->DBTab, $param_tablename, mcPUIX::PUIXArray, mcPUIX::PDOValues) ) {

			$callbackfncForList = false;
			if(is_array($param_callbackfncForList) && !empty ($param_callbackfncForList)) {
				$callbackfncForList = true;
			}			
			
			$callbackfncForListElements = false;
			if(is_array($param_callbackfncForListElements) && !empty ($param_callbackfncForListElements)) {
				$callbackfncForListElements = true;
			}
			
			foreach($this->DBTab[$param_tablename][mcPUIX::PUIXArray][mcPUIX::PDOValues] as &$ListData) {
				if($callbackfncForList) {
					foreach($param_callbackfncForList as $fncForList) {
						$this->$fncForList($param_HostAccount, $param_iStorable, $ListData);
					}						
				}				
				foreach($ListData as &$ListElement) {
					if($callbackfncForListElements && mcArray::checkKeyHasFullArray($ListElement, mcPUIX::PDOValues)) {
						foreach($ListElement[mcPUIX::PDOValues] as $ListElementData) {
							foreach($param_callbackfncForListElements as $fncForElements) {
								$this->$fncForElements($param_HostAccount, $param_iStorable, $ListData, $ListElementData);
							}
						}
					}
				}
			}			
		}
	}

	
	
}
?>