summaryrefslogtreecommitdiffstats
path: root/library/Reporting/Web/Widget/HeaderOrFooter.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Reporting/Web/Widget/HeaderOrFooter.php')
-rw-r--r--library/Reporting/Web/Widget/HeaderOrFooter.php95
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}"));
+ }
+ }
+}