mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 15:22:17 +02:00
Parser for Short Hand Syntax (->) Check method
SVN:b1312[5747]
This commit is contained in:
@@ -208,7 +208,34 @@ class ExternalFieldOqlExpression extends ExternalFieldExpression implements Chec
|
||||
*/
|
||||
public function Check(ModelReflection $oModelReflection, $aAliases, $sSourceQuery)
|
||||
{
|
||||
// TODO: Implement Check() method.
|
||||
$sParentAlias = null;
|
||||
foreach($this->aExpression as $i => $oFieldOqlExpression)
|
||||
{
|
||||
if (is_null($sParentAlias))
|
||||
{
|
||||
$oFieldOqlExpression->RefreshAlias($oModelReflection, $aAliases, $sSourceQuery);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oFieldOqlExpression->SetParent($sParentAlias);
|
||||
}
|
||||
$oFieldOqlExpression->Check($oModelReflection, $aAliases, $sSourceQuery);
|
||||
|
||||
$sClass = $aAliases[$oFieldOqlExpression->GetParent()];
|
||||
$sTargetClass = $oModelReflection->GetAttributeProperty($sClass, $oFieldOqlExpression->GetName(), 'targetclass');
|
||||
if (is_null($sTargetClass))
|
||||
{
|
||||
if ($i != (count($this->aExpression) - 1))
|
||||
{
|
||||
throw new OqlNormalizeException('Forbiden operation for attribute', $sSourceQuery, $oFieldOqlExpression->GetNameDetails(), $oModelReflection->GetFiltersList($sClass));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$aAliases[$sTargetClass] = $sTargetClass;
|
||||
$sParentAlias = $sTargetClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,6 +267,39 @@ class FieldOqlExpression extends FieldExpression implements CheckableExpression
|
||||
}
|
||||
|
||||
public function Check(ModelReflection $oModelReflection, $aAliases, $sSourceQuery)
|
||||
{
|
||||
$sClassAlias = $this->GetParent();
|
||||
$sFltCode = $this->GetName();
|
||||
if (empty($sClassAlias))
|
||||
{
|
||||
// Try to find an alias
|
||||
// Build an array of field => array of aliases
|
||||
$this->RefreshAlias($oModelReflection, $aAliases, $sSourceQuery);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!array_key_exists($sClassAlias, $aAliases))
|
||||
{
|
||||
throw new OqlNormalizeException('Unknown class [alias]', $sSourceQuery, $this->GetParentDetails(), array_keys($aAliases));
|
||||
}
|
||||
$sClass = $aAliases[$sClassAlias];
|
||||
if (!$oModelReflection->IsValidFilterCode($sClass, $sFltCode))
|
||||
{
|
||||
throw new OqlNormalizeException('Unknown filter code', $sSourceQuery, $this->GetNameDetails(), $oModelReflection->GetFiltersList($sClass));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by Check => throws exception if error
|
||||
*
|
||||
* @param \ModelReflection $oModelReflection
|
||||
* @param $aAliases
|
||||
* @param $sSourceQuery
|
||||
*
|
||||
* @throws \OqlNormalizeException
|
||||
*/
|
||||
public function RefreshAlias(ModelReflection $oModelReflection, $aAliases, $sSourceQuery)
|
||||
{
|
||||
$sClassAlias = $this->GetParent();
|
||||
$sFltCode = $this->GetName();
|
||||
@@ -264,18 +324,7 @@ class FieldOqlExpression extends FieldExpression implements CheckableExpression
|
||||
throw new OqlNormalizeException('Ambiguous filter code', $sSourceQuery, $this->GetNameDetails());
|
||||
}
|
||||
$sClassAlias = $aFieldClasses[$sFltCode][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!array_key_exists($sClassAlias, $aAliases))
|
||||
{
|
||||
throw new OqlNormalizeException('Unknown class [alias]', $sSourceQuery, $this->GetParentDetails(), array_keys($aAliases));
|
||||
}
|
||||
$sClass = $aAliases[$sClassAlias];
|
||||
if (!$oModelReflection->IsValidFilterCode($sClass, $sFltCode))
|
||||
{
|
||||
throw new OqlNormalizeException('Unknown filter code', $sSourceQuery, $this->GetNameDetails(), $oModelReflection->GetFiltersList($sClass));
|
||||
}
|
||||
$this->SetParent($sClassAlias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user