mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 23:32:17 +02:00
Export feature
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
namespace Combodo\iTop\Application\Dashboard\Controller;
|
||||
|
||||
use appUserPreferences;
|
||||
use Combodo\iTop\Application\Dashlet\DashletFactory;
|
||||
use Combodo\iTop\Application\TwigBase\Controller\Controller;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Button\ButtonUIBlockFactory;
|
||||
@@ -15,14 +16,19 @@ use Combodo\iTop\Application\UI\Base\Component\TurboForm\TurboFormUIBlockFactory
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlockUIBlockFactory;
|
||||
use Combodo\iTop\Application\WebPage\AjaxPage;
|
||||
use Combodo\iTop\Application\WebPage\DownloadPage;
|
||||
use Combodo\iTop\Application\WebPage\JsonPage;
|
||||
use Combodo\iTop\Forms\Block\FormBlockService;
|
||||
use Combodo\iTop\PropertyType\Serializer\XMLSerializer;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use DBObjectSearch;
|
||||
use DBObjectSet;
|
||||
use Exception;
|
||||
use IssueLog;
|
||||
use ModelReflectionRuntime;
|
||||
use RuntimeDashboard;
|
||||
use SecurityException;
|
||||
use UserRights;
|
||||
use utils;
|
||||
|
||||
class DashboardController extends Controller
|
||||
@@ -133,4 +139,44 @@ class DashboardController extends Controller
|
||||
$oPage->SetOutputDataOnly(true);
|
||||
return $oPage;
|
||||
}
|
||||
|
||||
public function OperationExport()
|
||||
{
|
||||
$oPage = new DownloadPage('');
|
||||
$sDashboardId = utils::ReadParam('id', '', false, 'raw_data');
|
||||
$sDashboardFile = APPROOT.utils::ReadParam('file', '', false, 'raw_data');
|
||||
|
||||
$sDashboardFileSanitized = utils::RealPath($sDashboardFile, APPROOT);
|
||||
if (false === $sDashboardFileSanitized) {
|
||||
throw new SecurityException('Invalid dashboard file !');
|
||||
}
|
||||
|
||||
if (!appUserPreferences::GetPref('display_original_dashboard_'.$sDashboardId, false)) {
|
||||
// Search for an eventual user defined dashboard
|
||||
$oUDSearch = new DBObjectSearch('UserDashboard');
|
||||
$oUDSearch->AddCondition('user_id', UserRights::GetUserId(), '=');
|
||||
$oUDSearch->AddCondition('menu_code', $sDashboardId, '=');
|
||||
$oUDSet = new DBObjectSet($oUDSearch);
|
||||
if ($oUDSet->Count() > 0) {
|
||||
// Assuming there is at most one couple {user, menu}!
|
||||
$oUserDashboard = $oUDSet->Fetch();
|
||||
$sDashboardDefinition = $oUserDashboard->Get('contents');
|
||||
} else {
|
||||
$sDashboardDefinition = @file_get_contents($sDashboardFileSanitized);
|
||||
}
|
||||
} else {
|
||||
$sDashboardDefinition = @file_get_contents($sDashboardFileSanitized);
|
||||
}
|
||||
|
||||
$oDashboard = RuntimeDashboard::GetDashboard($sDashboardFile, $sDashboardId);
|
||||
if (!is_null($oDashboard)) {
|
||||
$oPage->TrashUnexpectedOutput();
|
||||
$oPage->SetContentType('text/xml');
|
||||
$oPage->SetContentDisposition('attachment', 'dashboard_'.$oDashboard->GetTitle().'.xml');
|
||||
|
||||
$oPage->add($sDashboardDefinition);
|
||||
}
|
||||
|
||||
return $oPage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -769,4 +769,27 @@ JS
|
||||
$this->aGridDashlets[] = $aGridDashlet;
|
||||
}
|
||||
}
|
||||
|
||||
public function ToModelData(): mixed
|
||||
{
|
||||
$this->sLayoutClass = DashboardLayoutGrid::class;
|
||||
$this->sTitle = $aDashboardValues['title'];
|
||||
$iRefresh = $aDashboardValues['refresh'];
|
||||
$this->bAutoReload = $iRefresh > 0;
|
||||
$this->iAutoReloadSec = $iRefresh;
|
||||
|
||||
foreach ($aDashboardValues['pos_dashlets'] as $sId => $aPosDashlet) {
|
||||
$aGridDashlet = [];
|
||||
$aGridDashlet['position_x'] = $aPosDashlet['position_x'] ?? 0;
|
||||
$aGridDashlet['position_y'] = $aPosDashlet['position_y'] ?? 0;
|
||||
$aGridDashlet['width'] = $aPosDashlet['width'] ?? 2;
|
||||
$aGridDashlet['height'] = $aPosDashlet['height'] ?? 1;
|
||||
$aDashlet = $aPosDashlet['dashlet'];
|
||||
$sType = $aDashlet['type'];
|
||||
$oDashlet = DashletFactory::GetInstance()->CreateDashlet($sType, $sId);
|
||||
$oDashlet->FromModelData($aDashlet['properties']);
|
||||
$aGridDashlet['dashlet'] = $oDashlet;
|
||||
$this->aGridDashlets[] = $aGridDashlet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user