class_mcPUIX.inc.php 10.4 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 getDOMElement_editSpecial(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, DOMElement &$param_DOMElement, $param_KindOf=null, array $param_DOMElemente=null);
	public function setRootTable();
}


abstract class  mcPUIX extends mcClass implements imcPUIX {
	const DBUIConfig = 'DBUIConfig';
	const PUIX_SUB_REFERENCELIST = 'PUIX_SUB_REFERENCELIST';
	
	const PDOValues = 'PDOValues';
	const PDOToSaveValues = 'PDOToSaveValues';
	
	const PDO_OR = 'OR';
	const PDO_AND = 'AND';
	const PDO_XOR = 'XOR';
	const PDO_NEW = 'PDO_NEW';
	const PDO_NEWID = 'PDO_NEWID';
	const PDO_Operator = 'PDO_Operator';
	const PDO_Special = 'PDO_Special';
	const PDO_Operand = 'PDO_Operand';
	const PDO_bindValueArray = 'PDO_bindValueArray';
	
	
	const PDOLoadDepth = 'PDOLoadDepth';
	const PDOLoadDepth_OnlyNew = 'PDOLoadDepth_OnlyNew';
	
	const ERRORMESSAGE ='ERRORMESSAGE';
	
	const DOMmcPUIX = 'mcPUIX';
	const DOMmcPUIX_edit = 'DOMmcPUIX_edit';
	const DOMmcPUIX_edit_special = 'DOMmcPUIX_edit_special';
	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) {
		$DBTable = mcPUIX_PDO::getTableAsDBUIArray($param_HostAccount, $param_iStorable, $this->RootTable, $this->SearchAttributes, $param_SQLWhere, $param_depth);
		if(is_array($DBTable))  {
//			D::show($DBTable, '$DBTable');
			$this->setTableValues($this->RootTable, $DBTable);	
			$this->DBTab_State[$this->RootTable] = mcPUIX::STATE_LOADED;			
		}
	}

	
	public function __toString() {
		$var_string = parent::__toString();
		$var_string .= '-['.$this->PUIXHostObject.']';
		return $var_string;
	}	
	
	/**
	 *
	 * @param Account $param_HostAccount
	 * @param iStorable $param_iStorable
	 * @param array $param_values -- array(
	 *				get_class($this->PUIXHostObject) => array(		// not necessary if $this->PUIXHostObject not exists
	 *					get_class($this) => array(
	 *						mcPUIX::PUIXArray =>  array(
	 *							mcPUIX::FORM_POST_VALUES => array()
	 *						)
	 *					) 
	 *				) 
	 *			)
	 * @return boolean 
	 */
	public function setData(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_values) {
		$param_tablename = $this->RootTable;

		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) { 
		D::cf(get_class($this).'   '.$this->RootTable);
		$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_edit_special = $param_DOMDocument->createElement(mcPUIX::DOMmcPUIX_edit_special);
			$this->getDOMElement_editSpecial($param_HostAccount, $param_iStorable, $param_DOMDocument, $DOMElement_edit_special, $param_KindOf, $param_DOMElemente);
			$DOMElement_edit->appendChild($DOMElement_edit_special);					
		}
		
		$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) ) {
//D::show($this->DBTab[$param_tablename][mcPUIX::PUIXArray][mcPUIX::PDOValues], $this);
			$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);
							}
						}
					}
				}
			}			
		}
	}

	
	
}
?>