diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index 539117970..2ae59862f 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -355,7 +355,7 @@ class DisplayBlock { // In case of search, the context filtering is done by the search itself - if (($this->m_sStyle != 'links') && ($this->m_sStyle != 'search')) + if (($this->m_sStyle != 'links') && ($this->m_sStyle != 'search') && ($this->m_sStyle != 'list_search')) { $oAppContext = new ApplicationContext(); $sClass = $this->m_oFilter->GetClass(); @@ -616,6 +616,7 @@ class DisplayBlock } break; + case 'list_search': case 'list': $aClasses = $this->m_oSet->GetSelectedClasses(); $aAuthorizedClasses = array(); diff --git a/application/ui.extkeywidget.class.inc.php b/application/ui.extkeywidget.class.inc.php index 6978a7cb4..79bce0d61 100644 --- a/application/ui.extkeywidget.class.inc.php +++ b/application/ui.extkeywidget.class.inc.php @@ -403,7 +403,7 @@ EOF // Current extkey value, so we can display event if it is not available anymore (eg. archived). $iCurrentExtKeyId = (is_null($oObj)) ? 0 : $oObj->Get($this->sAttCode); - $oBlock = new DisplayBlock($oFilter, 'list', false, array('query_params' => array('this' => $oObj, 'current_extkey_id' => $iCurrentExtKeyId))); + $oBlock = new DisplayBlock($oFilter, 'list_search', false, array('query_params' => array('this' => $oObj, 'current_extkey_id' => $iCurrentExtKeyId))); $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/pages/ajax.searchform.php b/pages/ajax.searchform.php index 68d6fdaf2..d4ab06b19 100644 --- a/pages/ajax.searchform.php +++ b/pages/ajax.searchform.php @@ -71,7 +71,7 @@ try } //IssueLog::Info('Search OQL: "'.$oFilter->ToOQL().'"'); - $oDisplayBlock = new DisplayBlock($oFilter, 'list', false); + $oDisplayBlock = new DisplayBlock($oFilter, 'list_search', false); foreach($aListParams as $key => $value) { diff --git a/sources/application/search/searchform.class.inc.php b/sources/application/search/searchform.class.inc.php index edcad8aac..6f7acd285 100644 --- a/sources/application/search/searchform.class.inc.php +++ b/sources/application/search/searchform.class.inc.php @@ -89,7 +89,7 @@ class SearchForm { $sRootClass = $sClassName; } - //should the search be opend on load? + //should the search be opened on load? if (isset($aExtraParams['open'])) { $bOpen = $aExtraParams['open']; @@ -192,9 +192,16 @@ class SearchForm $bIsRemovable = false; } + $bUseApplicationContext = true; + if (isset($aExtraParams['selection_mode']) && ($aExtraParams['selection_mode'])) + { + // Don't use application context for selections + $bUseApplicationContext = false; + } + $aFields = $this->GetFields($oSet); $oSearch = $oSet->GetFilter(); - $aCriterion = $this->GetCriterion($oSearch, $aFields, $aArgs, $bIsRemovable); + $aCriterion = $this->GetCriterion($oSearch, $aFields, $aArgs, $bIsRemovable, $bUseApplicationContext); $aClasses = $oSearch->GetSelectedClasses(); $sClassAlias = ''; foreach($aClasses as $sAlias => $sClass) @@ -478,18 +485,19 @@ class SearchForm return array('values' => $aAllowedValues); } - /** - * @param \DBObjectSearch $oSearch - * @param array $aFields - * @param array $aArgs - * @param bool $bIsRemovable - * - * @return array - * - * @throws \CoreException - * @throws \MissingQueryArgument - */ - public function GetCriterion($oSearch, $aFields, $aArgs = array(), $bIsRemovable = true) + /** + * @param \DBObjectSearch $oSearch + * @param array $aFields + * @param array $aArgs + * @param bool $bIsRemovable + * @param bool $bUseApplicationContext + * + * @return array + * + * @throws \CoreException + * @throws \MissingQueryArgument + */ + public function GetCriterion($oSearch, $aFields, $aArgs = array(), $bIsRemovable = true, $bUseApplicationContext = true) { $aOrCriterion = array(); $bIsEmptyExpression = true; @@ -533,56 +541,57 @@ class SearchForm } } - // Context induced criteria are read-only - $oAppContext = new ApplicationContext(); - $sClass = $oSearch->GetClass(); - $aCallSpec = array($sClass, 'MapContextParam'); - $aContextParams = array(); - if (is_callable($aCallSpec)) - { - foreach($oAppContext->GetNames() as $sContextParam) - { - $sParamCode = call_user_func($aCallSpec, $sContextParam); //Map context parameter to the value/filter code depending on the class - if (!is_null($sParamCode)) - { - $sParamValue = $oAppContext->GetCurrentValue($sContextParam, null); - if (!is_null($sParamValue)) - { - $aContextParams[$sParamCode] = $sParamValue; - } - } - } - } - if ($bIsEmptyExpression) { // Add default criterion $aOrCriterion = $this->GetDefaultCriterion($oSearch, $aContextParams); } - foreach($aContextParams as $sParamCode => $sParamValue) + if ($bUseApplicationContext) { - // Check that the code exists in the concerned class - if (!MetaModel::IsValidAttCode($oSearch->GetClass(), $sParamCode)) + // Context induced criteria are read-only + $oAppContext = new ApplicationContext(); + $sClass = $oSearch->GetClass(); + $aCallSpec = array($sClass, 'MapContextParam'); + $aContextParams = array(); + if (is_callable($aCallSpec)) { - continue; + foreach ($oAppContext->GetNames() as $sContextParam) + { + $sParamCode = call_user_func($aCallSpec, $sContextParam); //Map context parameter to the value/filter code depending on the class + if (!is_null($sParamCode)) + { + $sParamValue = $oAppContext->GetCurrentValue($sContextParam, null); + if (!is_null($sParamValue)) + { + $aContextParams[$sParamCode] = $sParamValue; + } + } + } } - // Add Context criteria in read only mode - $sAlias = $oSearch->GetClassAlias(); - $oFieldExpression = new FieldExpression($sParamCode, $sAlias); - $oScalarExpression = new \ScalarExpression($sParamValue); - $oExpression = new \BinaryExpression($oFieldExpression, '=', $oScalarExpression); - $aCriterion = $oExpression->GetCriterion($oSearch, $aArgs); - $aCriterion['is_removable'] = false; - foreach($aOrCriterion as &$aAndExpression) + foreach ($aContextParams as $sParamCode => $sParamValue) { - $aAndExpression['and'][] = $aCriterion; + // Check that the code exists in the concerned class + if (!MetaModel::IsValidAttCode($oSearch->GetClass(), $sParamCode)) + { + continue; + } + + // Add Context criteria in read only mode + $sAlias = $oSearch->GetClassAlias(); + $oFieldExpression = new FieldExpression($sParamCode, $sAlias); + $oScalarExpression = new \ScalarExpression($sParamValue); + $oExpression = new \BinaryExpression($oFieldExpression, '=', $oScalarExpression); + $aCriterion = $oExpression->GetCriterion($oSearch, $aArgs); + $aCriterion['is_removable'] = false; + foreach ($aOrCriterion as &$aAndExpression) + { + $aAndExpression['and'][] = $aCriterion; + } } } - - return array('or' => $aOrCriterion); }