浏览代码

Dashboard: read user defined dashboards (setup needed to create new table)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1998 a333f486-631f-4898-b8df-5754b55c2be0
romainq 13 年之前
父节点
当前提交
640489b613
共有 3 个文件被更改,包括 37 次插入10 次删除
  1. 4 2
      application/dashboard.class.inc.php
  2. 32 8
      application/menunode.class.inc.php
  3. 1 0
      core/config.class.inc.php

+ 4 - 2
application/dashboard.class.inc.php

@@ -102,7 +102,8 @@ abstract class Dashboard
 				$oReflection = new ReflectionClass($sLayoutClass);
 				if (!$oReflection->isAbstract())
 				{
-					$aInfo = $sLayoutClass::GetInfo();
+					$aCallSpec = array($sLayoutClass, 'GetInfo');
+					$aInfo = call_user_func($aCallSpec);
 					$oPage->add('<input type="radio" name="layout_class" id="layout_'.$sLayoutClass.'"><label for="layout_'.$sLayoutClass.'"><img src="'.$sUrl.$aInfo['icon'].'" /></label>'); // title="" on either the img or the label does nothing !
 				}
 			}
@@ -127,7 +128,8 @@ abstract class Dashboard
 				$oReflection = new ReflectionClass($sDashletClass);
 				if (!$oReflection->isAbstract())
 				{
-					$aInfo = $sDashletClass::GetInfo();
+					$aCallSpec = array($sDashletClass, 'GetInfo');
+					$aInfo = call_user_func($aCallSpec);
 					$oPage->add('<span class="dashlet_icon ui-widget-content ui-corner-all" id="dashlet_'.$sDashletClass.'" title="'.$aInfo['label'].'" style="width:34px; height:34px; display:inline-block; margin:2px;"><img src="'.$sUrl.$aInfo['icon'].'" /></span>');
 				}
 			}

+ 32 - 8
application/menunode.class.inc.php

@@ -25,6 +25,7 @@
 
 require_once(APPROOT.'/application/utils.inc.php');
 require_once(APPROOT.'/application/template.class.inc.php');
+require_once(APPROOT."/application/user.dashboard.class.inc.php");
 
 
 /**
@@ -803,34 +804,57 @@ class DashboardMenuNode extends MenuNode
 		if ($this->sDashboardFile == '') return '';
 		return parent::GetHyperlink($aExtraParams);
 	}
-	
-	public function RenderContent(WebPage $oPage, $aExtraParams = array())
+
+	protected function GetDashboard()
 	{
 		$sDashboardDefinition = @file_get_contents($this->sDashboardFile);
 		if ($sDashboardDefinition !== false)
 		{
+			// Search for an eventual user defined dashboard, overloading the existing one
+			$oUDSearch = new DBObjectSearch('UserDashboard');
+			$oUDSearch->AddCondition('user_id', UserRights::GetUserId(), '=');
+			$oUDSearch->AddCondition('menu_code', $this->sMenuId, '=');
+			$oUDSet = new DBObjectSet($oUDSearch);
+			if ($oUDSet->Count() > 0)
+			{
+				// Assuming there is at most one couple {user, menu}!
+				$oUserDashboard = $oUDSet->Fetch();
+				$sDashboardDefinition = $oUserDashboard->Get('contents');
+			}
+
 			$oDashboard = new RuntimeDashboard($this->sMenuId);
 			$oDashboard->FromXml($sDashboardDefinition);
+		}
+		else
+		{
+			$oDashboard = null;
+		}
+		return $oDashboard;
+	}
+
+	public function RenderContent(WebPage $oPage, $aExtraParams = array())
+	{
+		$oDashboard = $this->GetDashboard();
+		if ($oDashboard != null)
+		{
 			$oDashboard->Render($oPage, false, $aExtraParams);
 		}
 		else
 		{
-			$oPage->p("Error: failed to load template file: '{$this->sDashboardFile}'"); // No need to translate ?
+			$oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
 		}
 	}
 	
 	public function RenderEditor(WebPage $oPage)
 	{
-		$sDashboardDefinition = @file_get_contents($this->sDashboardFile);
-		if ($sDashboardDefinition !== false)
+		$oDashboard = $this->GetDashboard();
+		if ($oDashboard != null)
 		{
-			$oDashboard = new RuntimeDashboard($this->sMenuId);
-			$oDashboard->FromXml($sDashboardDefinition);
 			$oDashboard->RenderEditor($oPage);
 		}
 		else
 		{
-			$oPage->p("Error: failed to load template file: '{$this->sDashboardFile}'"); // No need to translate ?
+			$oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'");
 		}
 	}
 }

+ 1 - 0
core/config.class.inc.php

@@ -648,6 +648,7 @@ class Config
 			'application/transaction.class.inc.php',
 			'application/menunode.class.inc.php',
 			'application/user.preferences.class.inc.php',
+			'application/user.dashboard.class.inc.php',
 			'application/audit.rule.class.inc.php',
 			'application/query.class.inc.php',
 // Romain - That's dirty, because those classes are in fact part of the core