From a80d99fdeb49d7af0107c4abbe7a2646b2566997 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 16 Nov 2010 16:24:57 +0000 Subject: [PATCH] Plugin::GetDelegationChain() added Multi inheritance of ORM reltions fix --- engine/classes/Action.class.php | 11 +---------- engine/classes/EntityORM.class.php | 5 ++++- engine/modules/plugin/Plugin.class.php | 26 ++++++++++++++++++++++---- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/engine/classes/Action.class.php b/engine/classes/Action.class.php index 463e3090..96bdd380 100644 --- a/engine/classes/Action.class.php +++ b/engine/classes/Action.class.php @@ -215,16 +215,7 @@ abstract class Action extends Object { * @param string $sTemplate Путь до шаблона относительно каталога шаблонов экшена */ protected function SetTemplateAction($sTemplate) { - $sAction = $this->GetActionClass(); - $sActionDelegater = $this->Plugin_GetDelegater('action',$this->GetActionClass()); - while(empty($sRootDelegater)) { - if($sAction==$sActionDelegater) { - $sRootDelegater = $sAction; - } - $sAction = $sActionDelegater; - $sActionDelegater = $this->Plugin_GetDelegater('action',$sActionDelegater); - } - $aDelegates = $this->Plugin_collectAllDelegatesRecursive(array($sRootDelegater),'action'); + $aDelegates = $this->Plugin_GetDelegationChain('action',$this->GetActionClass()); $sActionTemplatePath = $sTemplate.'.tpl'; foreach($aDelegates as $sAction) { if(preg_match('/^(Plugin([\w]+)_)?Action([\w]+)$/i',$sAction,$aMatches)) { diff --git a/engine/classes/EntityORM.class.php b/engine/classes/EntityORM.class.php index 507a4bfa..a9e15ee8 100644 --- a/engine/classes/EntityORM.class.php +++ b/engine/classes/EntityORM.class.php @@ -38,6 +38,7 @@ abstract class EntityORM extends Entity { public function __construct($aParam=false) { parent::__construct($aParam); + $this->aRelations=$this->_getRelations(); } public function _GetPrimaryKey() { @@ -200,7 +201,9 @@ abstract class EntityORM extends Entity { } public function _getRelations() { - return $this->aRelations; + $sParentName=get_parent_class($this); + $oEntityParent=new $sParentName(); + return array_merge($oEntityParent->_getRelations(),$this->aRelations); } public function _getRelationsData() { diff --git a/engine/modules/plugin/Plugin.class.php b/engine/modules/plugin/Plugin.class.php index 041338c4..fa1386a7 100644 --- a/engine/modules/plugin/Plugin.class.php +++ b/engine/modules/plugin/Plugin.class.php @@ -436,15 +436,33 @@ class ModulePlugin extends Module { return null; } - public function collectAllDelegatesRecursive($aDelegates,$sType) { + public function GetDelegationChain($sType,$sTo) { + $sRootDelegater = $this->GetRootDelegater($sType,$sTo); + return $this->collectAllDelegatesRecursive($sType,array($sRootDelegater)); + } + + public function GetRootDelegater($sType,$sTo) { + $sItem = $sTo; + $sItemDelegater = $this->GetDelegater($sType,$sTo); + while(empty($sRootDelegater)) { + if($sItem==$sItemDelegater) { + $sRootDelegater = $sItem; + } + $sItem = $sItemDelegater; + $sItemDelegater = $this->GetDelegater($sType,$sItemDelegater); + } + return $sRootDelegater; + } + + public function collectAllDelegatesRecursive($sType,$aDelegates) { foreach($aDelegates as $sClass) { if($aNewDelegates=$this->GetDelegates($sType,$sClass)) { - $aDelegates = array_merge($this->collectAllDelegatesRecursive($aNewDelegates,$sType),$aDelegates); + $aDelegates = array_merge($this->collectAllDelegatesRecursive($sType,$aNewDelegates),$aDelegates); } } return $aDelegates; - } - + } + /** * Возвращает делегирующий объект по имени делегата *