Przeglądaj źródła

Dashboard: fixed issue with Null values (group by)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2051 a333f486-631f-4898-b8df-5754b55c2be0
romainq 13 lat temu
rodzic
commit
ad50749c07
2 zmienionych plików z 37 dodań i 7 usunięć
  1. 1 1
      core/dbobject.class.php
  2. 36 6
      core/expression.class.inc.php

+ 1 - 1
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 '<em>'.Dict::S('UI:UndefinedObject').'</em>'; // Objects built in memory have negative IDs
 

+ 36 - 6
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;
 	}