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

SVN:trunk[1998]
This commit is contained in:
Romain Quetiez
2012-05-21 15:11:30 +00:00
parent c47b2b57ec
commit 8e3b2d7da6
3 changed files with 37 additions and 10 deletions

View File

@@ -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>');
}
}

View File

@@ -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}'");
}
}
}