N°1659 - Don't use anymore the current organization in the external key search (and n-n)

This commit is contained in:
Eric
2018-11-15 17:07:31 +01:00
parent b0c120d7fd
commit e44ed248ef
4 changed files with 63 additions and 53 deletions

View File

@@ -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();

View File

@@ -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
}

View File

@@ -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)
{

View File

@@ -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);
}