diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:46:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:46:47 +0000 |
commit | 4ada86876033fa171e2896d7e3d3c5645d8062db (patch) | |
tree | f0d1fee61877df200ccfb1c0af58a39cd551fb46 /application/controllers/TemplateController.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-reporting-4ada86876033fa171e2896d7e3d3c5645d8062db.tar.xz icingaweb2-module-reporting-4ada86876033fa171e2896d7e3d3c5645d8062db.zip |
Adding upstream version 0.10.0.upstream/0.10.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/controllers/TemplateController.php')
-rw-r--r-- | application/controllers/TemplateController.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/application/controllers/TemplateController.php b/application/controllers/TemplateController.php new file mode 100644 index 0000000..bb37b3c --- /dev/null +++ b/application/controllers/TemplateController.php @@ -0,0 +1,89 @@ +<?php +// Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting\Controllers; + +use DateTime; +use GuzzleHttp\Psr7\ServerRequest; +use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Web\Controller; +use Icinga\Module\Reporting\Web\Forms\TemplateForm; +use Icinga\Module\Reporting\Web\Widget\Template; +use ipl\Sql\Select; + +class TemplateController extends Controller +{ + use Database; + + public function indexAction() + { + $this->createTabs()->activate('preview'); + + $template = Template::fromDb($this->params->getRequired('id')); + + if ($template === null) { + throw new \Exception('Template not found'); + } + + $template + ->setMacros([ + 'date' => (new DateTime())->format('jS M, Y'), + 'time_frame' => 'Time Frame', + 'time_frame_absolute' => 'Time Frame (absolute)', + 'title' => 'Icinga Report Preview' + ]) + ->setPreview(true); + + $this->addContent($template); + } + + public function editAction() + { + $this->assertPermission('reporting/templates'); + + $this->createTabs()->activate('edit'); + + $select = (new Select()) + ->from('template') + ->columns(['id', 'settings']) + ->where(['id = ?' => $this->params->getRequired('id')]); + + $template = $this->getDb()->select($select)->fetch(); + + if ($template === false) { + throw new \Exception('Template not found'); + } + + $template->settings = json_decode($template->settings, true); + + $form = (new TemplateForm()) + ->setTemplate($template); + + $form->handleRequest(ServerRequest::fromGlobals()); + + $this->redirectForm($form, 'reporting/templates'); + + $this->addContent($form); + } + + protected function createTabs() + { + $tabs = $this->getTabs(); + + if ($this->hasPermission('reporting/templates')) { + $tabs->add('edit', [ + 'title' => $this->translate('Edit template'), + 'label' => $this->translate('Edit Template'), + 'url' => 'reporting/template/edit?id=' . $this->params->getRequired('id') + ]); + } + + $tabs->add('preview', [ + 'title' => $this->translate('Preview template'), + 'label' => $this->translate('Preview'), + 'url' => 'reporting/template?id=' . $this->params->getRequired('id') + ]); + + return $tabs; + } +} |