From 5ecf5815b8949d18d3b5fc11de7f80063cbdd5f9 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Tue, 29 May 2012 14:02:25 +0000 Subject: [PATCH] Dashboard: fixed issue with Null values (group by) SVN:trunk[2051] --- core/dbobject.class.php | 2 +- core/expression.class.inc.php | 42 ++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/core/dbobject.class.php b/core/dbobject.class.php index ce6e940a2..6a8c15357 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -615,7 +615,7 @@ abstract class DBObject return $oAtt->GetAsCSV($this->GetOriginal($sAttCode), $sSeparator, $sTextQualifier, $this); } - protected static function MakeHyperLink($sObjClass, $sObjKey, $sLabel = '', $sUrlMakerClass = null, $bWithNavigationContext = true) + public static function MakeHyperLink($sObjClass, $sObjKey, $sLabel = '', $sUrlMakerClass = null, $bWithNavigationContext = true) { if ($sObjKey <= 0) return ''.Dict::S('UI:UndefinedObject').''; // Objects built in memory have negative IDs diff --git a/core/expression.class.inc.php b/core/expression.class.inc.php index dd51e37a8..f0dcbcd94 100644 --- a/core/expression.class.inc.php +++ b/core/expression.class.inc.php @@ -366,12 +366,26 @@ class ScalarExpression extends UnaryExpression { public function __construct($value) { - if (!is_scalar($value)) + if (!is_scalar($value) && !is_null($value)) { throw new CoreException('Attempt to create a scalar expression from a non scalar', array('var_type'=>gettype($value))); } parent::__construct($value); } + + // recursive rendering + public function Render(&$aArgs = null, $bRetrofitParams = false) + { + if (is_null($this->m_value)) + { + $sRet = 'NULL'; + } + else + { + $sRet = CMDBSource::Quote($this->m_value); + } + return $sRet; + } } class TrueExpression extends ScalarExpression @@ -496,15 +510,31 @@ class FieldExpression extends UnaryExpression $sClass = $aSelectedClasses[$sParentAlias]; $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + // Set a default value for the general case + $sRes = $oAttDef->GetAsHtml($sValue); + + // Exceptions... if ($oAttDef->IsExternalKey()) { - $sTargetClass = $oAttDef->GetTargetClass(); - $oObject = MetaModel::GetObject($sTargetClass, (int)$sValue); - $sRes = $oObject->GetHyperlink(); + $sObjClass = $oAttDef->GetTargetClass(); + $iObjKey = (int)$sValue; + if ($iObjKey > 0) + { + $oObject = MetaModel::GetObject($sObjClass, $iObjKey); + $sRes = $oObject->GetHyperlink(); + } + else + { + // Undefined + $sRes = DBObject::MakeHyperLink($sObjClass, 0); + } } - else + elseif ($oAttDef->IsExternalField()) { - $sRes = $oAttDef->GetAsHtml($sValue); + if (is_null($sValue)) + { + $sRes = Dict::S('UI:UndefinedObject'); + } } return $sRes; }