diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:28:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:28:59 +0000 |
commit | 978a1651bac3faf5e91ddba327bf39aeb6a4cb63 (patch) | |
tree | f0d1fee61877df200ccfb1c0af58a39cd551fb46 /library/Reporting/Web/Widget/HeaderOrFooter.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-reporting-978a1651bac3faf5e91ddba327bf39aeb6a4cb63.tar.xz icingaweb2-module-reporting-978a1651bac3faf5e91ddba327bf39aeb6a4cb63.zip |
Adding upstream version 0.10.0.upstream/0.10.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Reporting/Web/Widget/HeaderOrFooter.php')
-rw-r--r-- | library/Reporting/Web/Widget/HeaderOrFooter.php | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/library/Reporting/Web/Widget/HeaderOrFooter.php b/library/Reporting/Web/Widget/HeaderOrFooter.php new file mode 100644 index 0000000..dcb37e7 --- /dev/null +++ b/library/Reporting/Web/Widget/HeaderOrFooter.php @@ -0,0 +1,95 @@ +<?php + +namespace Icinga\Module\Reporting\Web\Widget; + +use Icinga\Module\Reporting\Common\Macros; +use ipl\Html\Html; +use ipl\Html\HtmlDocument; + +class HeaderOrFooter extends HtmlDocument +{ + use Macros; + + const HEADER = 'header'; + + const FOOTER = 'footer'; + + protected $type; + + protected $data; + + protected $tag = 'div'; + + public function __construct($type, array $data) + { + $this->type = $type; + $this->data = $data; + } + + protected function resolveVariable($variable) + { + switch ($variable) { + case 'report_title': + $resolved = Html::tag('span', ['class' => 'title']); + break; + case 'time_frame': + $resolved = Html::tag('p', $this->getMacro('time_frame')); + break; + case 'time_frame_absolute': + $resolved = Html::tag('p', $this->getMacro('time_frame_absolute')); + break; + case 'page_number': + $resolved = Html::tag('span', ['class' => 'pageNumber']); + break; + case 'total_number_of_pages': + $resolved = Html::tag('span', ['class' => 'totalPages']); + break; + case 'page_of': + $resolved = Html::tag('p', Html::sprintf( + '%s / %s', + Html::tag('span', ['class' => 'pageNumber']), + Html::tag('span', ['class' => 'totalPages']) + )); + break; + case 'date': + $resolved = Html::tag('span', ['class' => 'date']); + break; + default: + $resolved = $variable; + break; + } + + return $resolved; + } + + protected function createColumn(array $data, $key) + { + $typeKey = "${key}_type"; + $valueKey = "${key}_value"; + $type = isset($data[$typeKey]) ? $data[$typeKey] : null; + + switch ($type) { + case 'text': + $column = Html::tag('p', $data[$valueKey]); + break; + case 'image': + $column = Html::tag('img', ['height' => 13, 'src' => Template::getDataUrl($data[$valueKey])]); + break; + case 'variable': + $column = $this->resolveVariable($data[$valueKey]); + break; + default: + $column = Html::tag('div'); + break; + } + + return $column; + } + + protected function assemble() + { + for ($i = 1; $i <= 3; ++$i) { + $this->add($this->createColumn($this->data, "{$this->type}_column{$i}")); + } + } +} |