Advanced Search: Fix shortcut menu with sub-classes

SVN:b1162[5470]
This commit is contained in:
Eric Espié
2018-03-20 14:12:16 +00:00
parent 1b80789288
commit 1301aa5c35
4 changed files with 45 additions and 16 deletions

View File

@@ -960,6 +960,7 @@ class FieldExpression extends UnaryExpression
*/
public function GetCriterion($oSearch, &$aArgs = null, $bRetrofitParams = false, $oAttDef = null)
{
$oAttDef = $this->GetAttDef($oSearch->GetJoinedClasses());
if (!is_null($oAttDef))
{
$sSearchType = $oAttDef->GetSearchType();
@@ -968,7 +969,6 @@ class FieldExpression extends UnaryExpression
{
$sSearchType = AttributeDefinition::SEARCH_WIDGET_TYPE;
}
return array(
'widget' => $sSearchType,
'ref' => $this->GetParent().'.'.$this->GetName(),
@@ -1532,25 +1532,35 @@ class FunctionExpression extends Expression
public function GetCriterion($oSearch, &$aArgs = null, $bRetrofitParams = false, $oAttDef = null)
{
if ($this->m_sVerb != 'DATE_SUB' && $this->m_sVerb != 'DATE_ADD' && $this->m_sVerb != 'NOW')
$aCriteria = array();
switch ($this->m_sVerb)
{
return parent::GetCriterion($oSearch, $aArgs, $bRetrofitParams, $oAttDef);
}
case 'ISNULL':
$aCriteria['operator'] = $this->m_sVerb;
foreach($this->m_aArgs as $oExpression)
{
$aCriteria = array_merge($oExpression->GetCriterion($oSearch, $aArgs, $bRetrofitParams, $oAttDef), $aCriteria);
}
break;
$aCriteria = array('widget' => 'date_time');
case 'NOW':
$aCriteria = array('widget' => 'date_time');
$aCriteria['is_relative'] = true;
$aCriteria['verb'] = $this->m_sVerb;
break;
foreach($this->m_aArgs as $oExpression)
{
$aCriteria = array_merge($oExpression->GetCriterion($oSearch, $aArgs, $bRetrofitParams, $oAttDef), $aCriteria);
}
case 'DATE_ADD':
case 'DATE_SUB':
$aCriteria = array('widget' => 'date_time');
foreach($this->m_aArgs as $oExpression)
{
$aCriteria = array_merge($oExpression->GetCriterion($oSearch, $aArgs, $bRetrofitParams, $oAttDef), $aCriteria);
}
$aCriteria['verb'] = $this->m_sVerb;
break;
if ($this->m_sVerb == 'NOW')
{
$aCriteria['is_relative'] = true;
}
else
{
$aCriteria['verb'] = $this->m_sVerb;
default:
return parent::GetCriterion($oSearch, $aArgs, $bRetrofitParams, $oAttDef);
}
return $aCriteria;

View File

@@ -122,6 +122,10 @@ class CriterionToOQL extends CriterionConversionAbstract
protected static function EmptyToOql($sRef, $aCriteria)
{
if ($aCriteria['widget'] == AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC)
{
return "ISNULL({$sRef})";
}
return "({$sRef} = '')";
}

View File

@@ -59,6 +59,7 @@ class CriterionToSearchForm extends CriterionConversionAbstract
AttributeDefinition::SEARCH_WIDGET_TYPE_ENUM => 'EnumToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_DATE => 'DateToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_DATE_TIME => 'DateTimeToSearchForm',
AttributeDefinition::SEARCH_WIDGET_TYPE_NUMERIC => 'NumericToSearchForm',
);
foreach($aAndCriterionRaw as $aCriteria)
@@ -374,4 +375,16 @@ class CriterionToSearchForm extends CriterionConversionAbstract
return $aCriteria;
}
protected static function NumericToSearchForm($aCriteria, $aFields)
{
if ($aCriteria['operator'] == 'ISNULL')
{
$aCriteria['operator'] = CriterionConversionAbstract::OP_EMPTY;
}
return $aCriteria;
}
}

View File

@@ -339,6 +339,7 @@ class CriterionConversionTest extends ItopDataTestCase
function OqlProvider()
{
return array(
array('OQL' => "SELECT Server WHERE ISNULL(nb_u)"),
array('OQL' => "SELECT Contact WHERE status = 'active'"),
array('OQL' => "SELECT Contact WHERE status = 'active' AND name LIKE 'toto%'"),
array('OQL' => "SELECT Contact WHERE status = 'active' AND org_id = 3"),
@@ -350,6 +351,7 @@ class CriterionConversionTest extends ItopDataTestCase
array('OQL' => "SELECT UserRequest WHERE start_date >= '2017-01-01 00:00:00' AND '2017-01-01 00:00:00' >= start_date"),
array('OQL' => "SELECT UserRequest WHERE start_date >= '2017-01-01 00:00:00' AND '2017-01-01 01:00:00' > start_date"),
array('OQL' => "SELECT UserRequest WHERE start_date >= '2017-01-01 00:00:00' AND '2017-01-02 00:00:00' > start_date"),
);
}
}