Advanced Search: Support of undefined values for enum and external keys

SVN:b1162[5495]
This commit is contained in:
Eric Espié
2018-03-22 17:36:29 +00:00
parent 62895eedb7
commit 35c016482b

View File

@@ -25,6 +25,7 @@ namespace Combodo\iTop\Application\Search\CriterionConversion;
use AttributeDateTime;
use AttributeDefinition;
use AttributeExternalKey;
use Combodo\iTop\Application\Search\AjaxSearchException;
use Combodo\iTop\Application\Search\CriterionConversionAbstract;
use Combodo\iTop\Application\Search\SearchForm;
@@ -149,6 +150,8 @@ class CriterionToOQL extends CriterionConversionAbstract
return "1";
}
$bFilterOnUndefined = false;
$sFilterOnUndefined = '';
try
{
$aAttributeDefs = \MetaModel::ListAttributeDefs($sClass);
@@ -182,6 +185,25 @@ class CriterionToOQL extends CriterionConversionAbstract
}
}
}
// search for "undefined"
for ($i = 0; $i < count($aValues); $i++)
{
$aValue = $aValues[$i];
if (isset($aValue['value']) && ($aValue['value'] === 'null'))
{
if ($oAttDef instanceof AttributeExternalKey)
{
$sFilterOnUndefined = "({$sRef} = 0)";
}
else
{
$sFilterOnUndefined = "ISNULL({$sRef})";
}
$bFilterOnUndefined = true;
unset($aValues[$i]);
break;
}
}
}
}
} catch (\CoreException $e)
@@ -195,6 +217,21 @@ class CriterionToOQL extends CriterionConversionAbstract
}
$sInList = implode("','", $aInValues);
if ($bFilterOnUndefined)
{
if (count($aValues) === 0)
{
return "{$sFilterOnUndefined}";
}
if (count($aInValues) == 1)
{
return "(({$sRef} = '$sInList') OR {$sFilterOnUndefined})";
}
return "({$sRef} IN ('$sInList') OR {$sFilterOnUndefined})";
}
if (count($aInValues) == 1)
{
return "({$sRef} = '$sInList')";