Explorar o código

New type of attribute: percentage

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1680 a333f486-631f-4898-b8df-5754b55c2be0
dflaven %!s(int64=13) %!d(string=hai) anos
pai
achega
415cd72bf3
Modificáronse 1 ficheiros con 13 adicións e 4 borrados
  1. 13 4
      core/attributedef.class.inc.php

+ 13 - 4
core/attributedef.class.inc.php

@@ -955,12 +955,21 @@ class AttributePercentage extends AttributeInteger
 {
 	public function GetAsHTML($sValue, $oHostObject = null)
 	{
-		$iWidth = 5; // Number of em...
-		if ($sValue > 90)
+		$iWidth = 5; // Total width of the percentage bar graph, in em...
+		$iValue = (int)$sValue;
+		if ($iValue > 100)
+		{
+			$iValue = 100;
+		}
+		else if ($iValue < 0)
+		{
+			$iValue = 0;
+		}
+		if ($iValue > 90)
 		{
 			$sColor = "#cc3300";
 		}
-		else if ($sValue > 50)
+		else if ($iValue > 50)
 		{
 			$sColor = "#cccc00";
 		}
@@ -968,7 +977,7 @@ class AttributePercentage extends AttributeInteger
 		{
 			$sColor = "#33cc00";
 		}
-		$iPercentWidth = $iWidth * $sValue / 100;
+		$iPercentWidth = ($iWidth * $iValue) / 100;
 		return "<div style=\"width:{$iWidth}em;-moz-border-radius: 3px;-webkit-border-radius: 3px;border-radius: 3px;display:inline-block;border: 1px #ccc solid;\"><div style=\"width:{$iPercentWidth}em; display:inline-block;background-color:$sColor;\"><span></span></div></div>&nbsp;$sValue %";
 	}
 }