diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:29:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:29:16 +0000 |
commit | 8a985929ed84cdb458a13c66b25f84e41133b24f (patch) | |
tree | 102a3d6e3cb731c6d23263095d0098f99572626d /library/Reporting/Web/Widget | |
parent | Adding upstream version 0.10.0. (diff) | |
download | icingaweb2-module-reporting-upstream.tar.xz icingaweb2-module-reporting-upstream.zip |
Adding upstream version 1.0.1.upstream/1.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Reporting/Web/Widget')
-rw-r--r-- | library/Reporting/Web/Widget/CompatDropdown.php | 1 | ||||
-rw-r--r-- | library/Reporting/Web/Widget/CoverPage.php | 18 | ||||
-rw-r--r-- | library/Reporting/Web/Widget/HeaderOrFooter.php | 10 | ||||
-rw-r--r-- | library/Reporting/Web/Widget/Template.php | 44 |
4 files changed, 38 insertions, 35 deletions
diff --git a/library/Reporting/Web/Widget/CompatDropdown.php b/library/Reporting/Web/Widget/CompatDropdown.php index cdd7b40..f5d4b03 100644 --- a/library/Reporting/Web/Widget/CompatDropdown.php +++ b/library/Reporting/Web/Widget/CompatDropdown.php @@ -1,4 +1,5 @@ <?php + // Icinga Reporting | (c) 2021 Icinga GmbH | GPLv2 namespace Icinga\Module\Reporting\Web\Widget; diff --git a/library/Reporting/Web/Widget/CoverPage.php b/library/Reporting/Web/Widget/CoverPage.php index 545ef6a..5b95a45 100644 --- a/library/Reporting/Web/Widget/CoverPage.php +++ b/library/Reporting/Web/Widget/CoverPage.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Reporting\Web\Widget; use Icinga\Module\Reporting\Common\Macros; use ipl\Html\BaseHtmlElement; use ipl\Html\Html; +use ipl\Web\Compat\StyleWithNonce; class CoverPage extends BaseHtmlElement { @@ -138,15 +139,22 @@ class CoverPage extends BaseHtmlElement protected function assemble() { if ($this->hasBackgroundImage()) { - $this - ->getAttributes() - ->add('style', "background-image: url('" . Template::getDataUrl($this->getBackgroundImage()) . "');"); + $coverPageBackground = (new StyleWithNonce()) + ->setModule('reporting') + ->addFor($this, [ + 'background-image' => sprintf("url('%s')", Template::getDataUrl($this->getBackgroundImage())) + ]); + + $this->addHtml($coverPageBackground); } $content = Html::tag('div', ['class' => 'cover-page-content']); - if ($this->hasColor()) { - $content->getAttributes()->add('style', "color: {$this->getColor()};"); + $coverPageLogo = (new StyleWithNonce()) + ->setModule('reporting') + ->addFor($content, ['color' => $this->getColor()]); + + $content->addHtml($coverPageLogo); } if ($this->hasLogo()) { diff --git a/library/Reporting/Web/Widget/HeaderOrFooter.php b/library/Reporting/Web/Widget/HeaderOrFooter.php index dcb37e7..3ec9a7f 100644 --- a/library/Reporting/Web/Widget/HeaderOrFooter.php +++ b/library/Reporting/Web/Widget/HeaderOrFooter.php @@ -10,9 +10,9 @@ class HeaderOrFooter extends HtmlDocument { use Macros; - const HEADER = 'header'; + public const HEADER = 'header'; - const FOOTER = 'footer'; + public const FOOTER = 'footer'; protected $type; @@ -64,9 +64,9 @@ class HeaderOrFooter extends HtmlDocument protected function createColumn(array $data, $key) { - $typeKey = "${key}_type"; - $valueKey = "${key}_value"; - $type = isset($data[$typeKey]) ? $data[$typeKey] : null; + $typeKey = "{$key}_type"; + $valueKey = "{$key}_value"; + $type = $data[$typeKey] ?? null; switch ($type) { case 'text': diff --git a/library/Reporting/Web/Widget/Template.php b/library/Reporting/Web/Widget/Template.php index e780a3d..0f07703 100644 --- a/library/Reporting/Web/Widget/Template.php +++ b/library/Reporting/Web/Widget/Template.php @@ -1,17 +1,15 @@ <?php + // Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 namespace Icinga\Module\Reporting\Web\Widget; use Icinga\Module\Reporting\Common\Macros; -use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Model; use ipl\Html\BaseHtmlElement; -use ipl\Html\Html; -use ipl\Sql\Select; class Template extends BaseHtmlElement { - use Database; use Macros; protected $tag = 'div'; @@ -38,39 +36,35 @@ class Template extends BaseHtmlElement return sprintf('data:%s;base64,%s', $image['mime_type'], $image['content']); } - public static function fromDb($id) + /** + * Create template from the given model + * + * @param Model\Template $templateModel + * + * @return static + */ + public static function fromModel(Model\Template $templateModel): self { $template = new static(); - $select = (new Select()) - ->from('template') - ->columns('*') - ->where(['id = ?' => $id]); - - $row = $template->getDb()->select($select)->fetch(); - - if ($row === false) { - return null; - } - - $row->settings = json_decode($row->settings, true); + $templateModel->settings = json_decode($templateModel->settings, true); $coverPage = (new CoverPage()) - ->setColor($row->settings['color']) - ->setTitle($row->settings['title']); + ->setColor($templateModel->settings['color']) + ->setTitle($templateModel->settings['title']); - if (isset($row->settings['cover_page_background_image'])) { - $coverPage->setBackgroundImage($row->settings['cover_page_background_image']); + if (isset($templateModel->settings['cover_page_background_image'])) { + $coverPage->setBackgroundImage($templateModel->settings['cover_page_background_image']); } - if (isset($row->settings['cover_page_logo'])) { - $coverPage->setLogo($row->settings['cover_page_logo']); + if (isset($templateModel->settings['cover_page_logo'])) { + $coverPage->setLogo($templateModel->settings['cover_page_logo']); } $template ->setCoverPage($coverPage) - ->setHeader(new HeaderOrFooter(HeaderOrFooter::HEADER, $row->settings)) - ->setFooter(new HeaderOrFooter(HeaderOrFooter::FOOTER, $row->settings)); + ->setHeader(new HeaderOrFooter(HeaderOrFooter::HEADER, $templateModel->settings)) + ->setFooter(new HeaderOrFooter(HeaderOrFooter::FOOTER, $templateModel->settings)); return $template; } |