Advanced Search: read-only selection criteria to add an object

SVN:b1162[5557]
This commit is contained in:
Eric Espié
2018-03-28 14:57:54 +00:00
parent 2811eb66c5
commit 26ec1269a5
2 changed files with 26 additions and 8 deletions

View File

@@ -44,9 +44,11 @@ class CriterionToSearchForm extends CriterionConversionAbstract
*
* @param array $aClasses all the classes of the filter
*
* @param bool $bIsRemovable
*
* @return array
*/
public static function Convert($aAndCriterionRaw, $aFieldsByCategory, $aClasses)
public static function Convert($aAndCriterionRaw, $aFieldsByCategory, $aClasses, $bIsRemovable = true)
{
$aAllFields = array();
foreach($aFieldsByCategory as $aFields)
@@ -71,10 +73,17 @@ class CriterionToSearchForm extends CriterionConversionAbstract
foreach($aAndCriterionRaw as $aCriteria)
{
$aCriteria['label'] = trim($aCriteria['label'], "()");
$aCriteria['is_removable'] = $bIsRemovable;
if (!$bIsRemovable)
{
$aCriteria['widget'] = AttributeDefinition::SEARCH_WIDGET_TYPE_RAW;
}
// Check criteria validity
if (!array_key_exists('ref', $aCriteria) || !array_key_exists($aCriteria['ref'], $aAllFields))
{
$aCriteria['widget'] = AttributeDefinition::SEARCH_WIDGET_TYPE_RAW;
$aCriteria['label'] = Dict::S('UI:Search:Criteria:Raw:Filtered');
if (array_key_exists('ref', $aCriteria))
{

View File

@@ -128,9 +128,16 @@ class SearchForm
$aArgs = array();
}
$bIsRemovable = true;
if (isset($aExtraParams['selection_mode']) && $aExtraParams['selection_mode'])
{
// Mark all criterion as read-only and non-removable
$bIsRemovable = false;
}
$aFields = $this->GetFields($oSet);
$oSearch = $oSet->GetFilter();
$aCriterion = $this->GetCriterion($oSearch, $aFields, $aArgs);
$aCriterion = $this->GetCriterion($oSearch, $aFields, $aArgs, $bIsRemovable);
$oBaseSearch = $oSearch->DeepClone();
$oBaseSearch->ResetCondition();
@@ -149,17 +156,17 @@ class SearchForm
{
$aExtraParams['table_id'] = "search_form_result_{$sSearchFormId}";
}
if (!array_key_exists('table_inner_id', $aExtraParams))
if (!isset($aExtraParams['table_inner_id']))
{
$aListParams['table_inner_id'] = "table_inner_id_{$sSearchFormId}";
}
// When table_id is different of result_list_outer_selector
if (array_key_exists('table_id2', $aExtraParams))
if (isset($aExtraParams['table_id2']))
{
$aListParams['table_id'] = $aExtraParams['table_id2'];
}
$bOpen = false;
if (array_key_exists('open', $aExtraParams))
if (isset($aExtraParams['open']))
{
$bOpen = $aExtraParams['open'];
}
@@ -349,9 +356,11 @@ class SearchForm
*
* @param array $aArgs
*
* @param bool $bIsRemovable
*
* @return array
*/
public function GetCriterion($oSearch, $aFields, $aArgs = array())
public function GetCriterion($oSearch, $aFields, $aArgs = array(), $bIsRemovable = true)
{
$oExpression = $oSearch->GetCriteria();
@@ -377,7 +386,7 @@ class SearchForm
}
$aAndCriterion[] = $oAndSubExpr->GetCriterion($oSearch);
}
$aAndCriterion = CriterionToSearchForm::Convert($aAndCriterion, $aFields, $oSearch->GetJoinedClasses());
$aAndCriterion = CriterionToSearchForm::Convert($aAndCriterion, $aFields, $oSearch->GetJoinedClasses(), $bIsRemovable);
$aOrCriterion[] = array('and' => $aAndCriterion);
}