summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Table/IntlZfQueryBasedTable.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:17:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:17:47 +0000
commit5419d4428c86c488a43124f85e5407d7cbae6541 (patch)
tree772c4221a20fd7d1b3e7e67c6e21755a50e80fd7 /library/Director/Web/Table/IntlZfQueryBasedTable.php
parentAdding upstream version 1.10.2. (diff)
downloadicingaweb2-module-director-5419d4428c86c488a43124f85e5407d7cbae6541.tar.xz
icingaweb2-module-director-5419d4428c86c488a43124f85e5407d7cbae6541.zip
Adding upstream version 1.11.1.upstream/1.11.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Web/Table/IntlZfQueryBasedTable.php')
-rw-r--r--library/Director/Web/Table/IntlZfQueryBasedTable.php51
1 files changed, 51 insertions, 0 deletions
diff --git a/library/Director/Web/Table/IntlZfQueryBasedTable.php b/library/Director/Web/Table/IntlZfQueryBasedTable.php
new file mode 100644
index 0000000..81ef14c
--- /dev/null
+++ b/library/Director/Web/Table/IntlZfQueryBasedTable.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Icinga\Module\Director\Web\Table;
+
+use DateTime;
+use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
+use IntlDateFormatter;
+use Locale;
+
+abstract class IntlZfQueryBasedTable extends ZfQueryBasedTable
+{
+ protected function getDateFormatter()
+ {
+ return (new IntlDateFormatter(
+ Locale::getDefault(),
+ IntlDateFormatter::FULL,
+ IntlDateFormatter::NONE
+ ));
+ }
+
+ /**
+ * @param int $timestamp
+ */
+ protected function renderDayIfNew($timestamp)
+ {
+ $day = $this->getDateFormatter()->format((new DateTime())->setTimestamp($timestamp));
+
+ if ($this->lastDay !== $day) {
+ $this->nextHeader()->add(
+ $this::th($day, [
+ 'colspan' => 2,
+ 'class' => 'table-header-day'
+ ])
+ );
+
+ $this->lastDay = $day;
+ $this->nextBody();
+ }
+ }
+
+ protected function getTime(int $timeStamp)
+ {
+ $timeFormatter = $this->getDateFormatter();
+
+ $timeFormatter->setPattern(
+ in_array(Locale::getDefault(), ['en_US', 'en_US.UTF-8']) ? 'h:mm:ss a': 'H:mm:ss'
+ );
+
+ return $timeFormatter->format((new DateTime())->setTimestamp($timeStamp));
+ }
+}