From c95b8cf939588e45cd00e26ecb185fc48d8fab91 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Tue, 16 Apr 2013 11:24:34 +0000 Subject: [PATCH] #702 Ignoring the class when looking up for a polymorphic ext key SVN:trunk[2681] --- application/ui.extkeywidget.class.inc.php | 4 ++++ core/dbobjectsearch.class.php | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/application/ui.extkeywidget.class.inc.php b/application/ui.extkeywidget.class.inc.php index d975dedc7..620a1ea6e 100644 --- a/application/ui.extkeywidget.class.inc.php +++ b/application/ui.extkeywidget.class.inc.php @@ -355,6 +355,10 @@ EOF } $oFilter = DBObjectSearch::FromOQL($sFilter); + if (strlen($sRemoteClass) > 0) + { + $oFilter->ChangeClass($sRemoteClass); + } $oFilter->SetModifierProperty('UserRightsGetSelectFilter', 'bSearchMode', $this->bSearchMode); $oBlock = new DisplayBlock($oFilter, 'list', false, array('query_params' => array('this' => $oObj))); $oBlock->Display($oP, $this->iId.'_results', array('this' => $oObj, 'cssCount'=> '#count_'.$this->iId, 'menu' => false, 'selection_mode' => true, 'selection_type' => 'single', 'table_id' => 'select_'.$this->sAttCode)); // Don't display the 'Actions' menu on the results diff --git a/core/dbobjectsearch.class.php b/core/dbobjectsearch.class.php index 4c3ff4235..6de8e22bb 100644 --- a/core/dbobjectsearch.class.php +++ b/core/dbobjectsearch.class.php @@ -118,6 +118,25 @@ class DBObjectSearch return key($this->m_aClasses); } + /** + * Change the class (only subclasses are supported as of now, because the conditions must fit the new class) + * Defaults to the first selected class (most of the time it is also the first joined class + */ + public function ChangeClass($sNewClass, $sAlias = null) + { + if (is_null($sAlias)) + { + $sAlias = $this->GetClassAlias(); + } + $sCurrClass = $this->GetClassName($sAlias); + if (!MetaModel::IsParentClass($sCurrClass, $sNewClass)) + { + throw new Exception("Could not change the search class from '$sCurrClass' to '$sNewClass'. Only child classes are permitted."); + } + $this->m_aSelectedClasses[$sAlias] = $sNewClass; + $this->m_aClasses[$sAlias] = $sNewClass; + } + public function SetSelectedClasses($aNewSet) { $this->m_aSelectedClasses = array();