summaryrefslogtreecommitdiffstats
path: root/library/Reporting/Database.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:28:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:28:59 +0000
commit978a1651bac3faf5e91ddba327bf39aeb6a4cb63 (patch)
treef0d1fee61877df200ccfb1c0af58a39cd551fb46 /library/Reporting/Database.php
parentInitial commit. (diff)
downloadicingaweb2-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/Database.php')
-rw-r--r--library/Reporting/Database.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/library/Reporting/Database.php b/library/Reporting/Database.php
new file mode 100644
index 0000000..3dabe17
--- /dev/null
+++ b/library/Reporting/Database.php
@@ -0,0 +1,58 @@
+<?php
+// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2
+
+namespace Icinga\Module\Reporting;
+
+use Icinga\Application\Config;
+use Icinga\Data\ResourceFactory;
+use ipl\Sql;
+
+trait Database
+{
+ protected function getDb($resource = null)
+ {
+ $config = new Sql\Config(ResourceFactory::getResourceConfig(
+ $resource ?: Config::module('reporting')->get('backend', 'resource', 'reporting')
+ ));
+
+ $config->options = [\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ];
+ if ($config->db === 'mysql') {
+ $config->options[\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET SESSION SQL_MODE='STRICT_TRANS_TABLES"
+ . ",NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
+ }
+
+ $conn = new RetryConnection($config);
+
+ return $conn;
+ }
+
+ protected function listTimeframes()
+ {
+ $select = (new Sql\Select())
+ ->from('timeframe')
+ ->columns(['id', 'name']);
+
+ $timeframes = [];
+
+ foreach ($this->getDb()->select($select) as $row) {
+ $timeframes[$row->id] = $row->name;
+ }
+
+ return $timeframes;
+ }
+
+ protected function listTemplates()
+ {
+ $select = (new Sql\Select())
+ ->from('template')
+ ->columns(['id', 'name']);
+
+ $templates = [];
+
+ foreach ($this->getDb()->select($select) as $row) {
+ $templates[$row->id] = $row->name;
+ }
+
+ return $templates;
+ }
+}