diff --git a/core/oql/expression.class.inc.php b/core/oql/expression.class.inc.php index ef5f82946..088b4dfcf 100644 --- a/core/oql/expression.class.inc.php +++ b/core/oql/expression.class.inc.php @@ -2108,7 +2108,10 @@ class VariableExpression extends UnaryExpression */ public function Evaluate(array $aArgs) { - throw new Exception('not implemented yet'); + if (!isset($aArgs[$this->m_sName])) { + throw new MissingQueryArgument('Missing query argument', array('expecting'=>$this->m_sName)); + } + return $aArgs[$this->m_sName]; } /** diff --git a/sources/Forms/Block/Expression/ExpressionFormBlock.php b/sources/Forms/Block/Expression/ExpressionFormBlock.php index 4bc276fb7..fb522782a 100644 --- a/sources/Forms/Block/Expression/ExpressionFormBlock.php +++ b/sources/Forms/Block/Expression/ExpressionFormBlock.php @@ -10,10 +10,9 @@ use Combodo\iTop\Forms\Block\AbstractFormBlock; use Combodo\iTop\Forms\IO\Format\BooleanIOFormat; use Combodo\iTop\Forms\IO\Format\RawFormat; use Combodo\iTop\Forms\Register\IORegister; -use Combodo\iTop\Forms\FormsException; +use Expression; use IssueLog; use Symfony\Component\Form\FormEvents; -use Throwable; /** * @@ -54,27 +53,14 @@ class ExpressionFormBlock extends AbstractFormBlock try{ $sExpression = $this->GetOption('expression'); - $sValue = preg_replace_callback( - self::EXPRESSION_PATTERN, - function(array $aMatches) use ($sEventType): ?string { - $oInput = $this->GetInput($aMatches['input']); - if(!$oInput->HasEventValue($sEventType)){ - throw new FormsException('Unable to compute expression: input '.$aMatches['input'].' has no value for event '.$sEventType.'.'); - } - $value = $oInput->GetValue($sEventType); - if (is_string($value)) { - $value = "'$value'"; - } - return $value; - }, - $sExpression); - - $result = ''; - try { - eval('$result = '.$sValue.';'); - } catch (Throwable $e) { - IssueLog::Exception(__METHOD__.' expression '.json_encode($sValue).' failed with exception: '.$e->getMessage(), $e); + $oExpression = Expression::FromOQL($sExpression); + $aParamsToResolve = $oExpression->GetParameters(); + $aResolvedParams = []; + foreach ($aParamsToResolve as $sParamToResolve) { + $aResolvedParams[$sParamToResolve] = $this->GetInputValue($sParamToResolve); } + $result = $oExpression->Evaluate($aResolvedParams); + $this->GetOutput(self::OUTPUT_RESULT)->SetValue($sEventType, new BooleanIOFormat(boolval($result))); $this->GetOutput(self::OUTPUT_RESULT_INVERT)->SetValue($sEventType, new BooleanIOFormat(!boolval($result))); $this->GetOutput(self::OUTPUT_VALUE)->SetValue($sEventType, new RawFormat($result));