XML data from dashboard

This commit is contained in:
Eric Espie
2026-02-03 11:02:39 +01:00
parent b2041e3b63
commit 0b17e1f9b3
3 changed files with 60 additions and 17 deletions

View File

@@ -91,6 +91,20 @@ abstract class Dashboard
$this->FromDOMDocument($oDoc);
}
/**
* @param string $sXml
*
* @throws \Exception
*/
public function ToXML(): string
{
$oDomNode = $this->CreateEmptyDashboard();
$aModelData = $this->ToModelData();
$this->oXMLSerializer->Serialize($aModelData, $oDomNode, 'DashboardGrid', 'Dashboard');
return $oDomNode->ownerDocument->saveXML();
}
/**
* @param \DOMDocument $oDoc
*/
@@ -484,4 +498,33 @@ JS
$this->aGridDashlets[] = $aGridDashlet;
}
}
public function ToModelData(): array
{
$aModelData = [];
$aModelData['id'] = $this->sId;
$aModelData['layout'] = $this->sLayoutClass;
$aModelData['title'] = $this->sTitle;
$aModelData['refresh'] = $this->bAutoReload ? $this->iAutoReloadSec : 0;
foreach ($this->aGridDashlets as $aGridDashlet) {
$aPosDashlet = [];
$aPosDashlet['position_x'] = $aGridDashlet['position_x'] ?? 0;
$aPosDashlet['position_y'] = $aGridDashlet['position_y'] ?? 0;
$aPosDashlet['width'] = $aGridDashlet['width'] ?? 2;
$aPosDashlet['height'] = $aGridDashlet['height'] ?? 1;
/** @var Dashlet $oDashlet */
$oDashlet = $aGridDashlet['dashlet'];
$aDashlet = [];
$aDashlet['type'] = $oDashlet->GetDashletType();
$sId = $oDashlet->GetID();
$aDashlet['id'] = $sId;
$aDashlet['properties'] = $oDashlet->ToModelData();
$aPosDashlet['dashlet'] = $aDashlet;
$aModelData['pos_dashlets'][$sId] = $aPosDashlet;
}
return $aModelData;
}
}