mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
Advanced Search: Support of external fields (as strings)
SVN:b1162[5583]
This commit is contained in:
@@ -124,9 +124,14 @@ class CriterionToOQL extends CriterionConversionAbstract
|
||||
|
||||
protected static function EmptyToOql($sRef, $aCriteria)
|
||||
{
|
||||
if (isset($aCriteria['widget']) && ($aCriteria['widget'] == AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC))
|
||||
if (isset($aCriteria['widget']))
|
||||
{
|
||||
return "ISNULL({$sRef})";
|
||||
switch ($aCriteria['widget'])
|
||||
{
|
||||
case AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC:
|
||||
case AttributeDefinition::SEARCH_WIDGET_TYPE_EXTERNAL_FIELD:
|
||||
return "ISNULL({$sRef})";
|
||||
}
|
||||
}
|
||||
|
||||
return "({$sRef} = '')";
|
||||
|
||||
@@ -63,6 +63,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
|
||||
$aAndCriterion = array();
|
||||
$aMappingOperatorToFunction = array(
|
||||
AttributeDefinition::SEARCH_WIDGET_TYPE_STRING => 'TextToSearchForm',
|
||||
AttributeDefinition::SEARCH_WIDGET_TYPE_EXTERNAL_FIELD => 'ExternalFieldToSearchForm',
|
||||
AttributeDefinition::SEARCH_WIDGET_TYPE_DATE => 'DateTimeToSearchForm',
|
||||
AttributeDefinition::SEARCH_WIDGET_TYPE_DATE_TIME => 'DateTimeToSearchForm',
|
||||
AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC => 'NumericToSearchForm',
|
||||
@@ -80,6 +81,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
|
||||
}
|
||||
$aCriteria['is_removable'] = $bIsRemovable;
|
||||
|
||||
$sClass = '';
|
||||
if (isset($aCriteria['ref']))
|
||||
{
|
||||
$aRef = explode('.', $aCriteria['ref']);
|
||||
@@ -420,6 +422,46 @@ class CriterionToSearchForm extends CriterionConversionAbstract
|
||||
return $aCriteria;
|
||||
}
|
||||
|
||||
protected static function ExternalFieldToSearchForm($aCriteria, $aFields)
|
||||
{
|
||||
$sOperator = $aCriteria['operator'];
|
||||
$sValue = $aCriteria['values'][0]['value'];
|
||||
|
||||
$bStartWithPercent = substr($sValue, 0, 1) == '%' ? true : false;
|
||||
$bEndWithPercent = substr($sValue, -1) == '%' ? true : false;
|
||||
|
||||
switch (true)
|
||||
{
|
||||
case ($sOperator == 'ISNULL'):
|
||||
case ('' == $sValue and ($sOperator == 'LIKE')):
|
||||
$aCriteria['operator'] = CriterionConversionAbstract::OP_EMPTY;
|
||||
break;
|
||||
case ('' == $sValue and $sOperator == '!='):
|
||||
$aCriteria['operator'] = CriterionConversionAbstract::OP_NOT_EMPTY;
|
||||
break;
|
||||
case ($sOperator == 'LIKE' && $bStartWithPercent && $bEndWithPercent):
|
||||
$aCriteria['operator'] = CriterionConversionAbstract::OP_CONTAINS;
|
||||
$sValue = substr($sValue, 1, -1);
|
||||
$aCriteria['values'][0]['value'] = $sValue;
|
||||
$aCriteria['values'][0]['label'] = "$sValue";
|
||||
break;
|
||||
case ($sOperator == 'LIKE' && $bStartWithPercent):
|
||||
$aCriteria['operator'] = CriterionConversionAbstract::OP_ENDS_WITH;
|
||||
$sValue = substr($sValue, 1);
|
||||
$aCriteria['values'][0]['value'] = $sValue;
|
||||
$aCriteria['values'][0]['label'] = "$sValue";
|
||||
break;
|
||||
case ($sOperator == 'LIKE' && $bEndWithPercent):
|
||||
$aCriteria['operator'] = CriterionConversionAbstract::OP_STARTS_WITH;
|
||||
$sValue = substr($sValue, 0, -1);
|
||||
$aCriteria['values'][0]['value'] = $sValue;
|
||||
$aCriteria['values'][0]['label'] = "$sValue";
|
||||
break;
|
||||
}
|
||||
|
||||
return $aCriteria;
|
||||
}
|
||||
|
||||
protected static function DateTimeToSearchForm($aCriteria, $aFields)
|
||||
{
|
||||
if (!array_key_exists('is_relative', $aCriteria) || !$aCriteria['is_relative'])
|
||||
|
||||
@@ -417,8 +417,15 @@ class SearchForm
|
||||
{
|
||||
if (!is_null($oAttDef) && ($oAttDef->GetSearchType() != AttributeDefinition::SEARCH_WIDGET_TYPE_RAW))
|
||||
{
|
||||
$sLabel = $oAttDef->GetLabel();
|
||||
|
||||
if (method_exists($oAttDef, 'GetLabelForSearchField'))
|
||||
{
|
||||
$sLabel = $oAttDef->GetLabelForSearchField();
|
||||
}
|
||||
else
|
||||
{
|
||||
$sLabel = $oAttDef->GetLabel();
|
||||
}
|
||||
|
||||
if (method_exists($oAttDef, 'GetTargetClass'))
|
||||
{
|
||||
$sTargetClass = $oAttDef->GetTargetClass();
|
||||
|
||||
Reference in New Issue
Block a user