浏览代码

New type of attribute: percentage

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1679 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 13 年之前
父节点
当前提交
6124ee93da
共有 1 个文件被更改,包括 27 次插入0 次删除
  1. 27 0
      core/attributedef.class.inc.php

+ 27 - 0
core/attributedef.class.inc.php

@@ -947,6 +947,33 @@ class AttributeInteger extends AttributeDBField
 }
 
 /**
+ * Display an integer between 0 and 100 as a percentage / horizontal bar graph 
+ *
+ * @package     iTopORM
+ */
+class AttributePercentage extends AttributeInteger
+{
+	public function GetAsHTML($sValue, $oHostObject = null)
+	{
+		$iWidth = 5; // Number of em...
+		if ($sValue > 90)
+		{
+			$sColor = "#cc3300";
+		}
+		else if ($sValue > 50)
+		{
+			$sColor = "#cccc00";
+		}
+		else
+		{
+			$sColor = "#33cc00";
+		}
+		$iPercentWidth = $iWidth * $sValue / 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 %";
+	}
+}
+
+/**
  * Map a decimal value column (suitable for financial computations) to an attribute
  * internally in PHP such numbers are represented as string. Should you want to perform
  * a calculation on them, it is recommended to use the BC Math functions in order to