summaryrefslogtreecommitdiffstats
path: root/library/Reporting/Reportlet.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Reporting/Reportlet.php')
-rw-r--r--library/Reporting/Reportlet.php62
1 files changed, 21 insertions, 41 deletions
diff --git a/library/Reporting/Reportlet.php b/library/Reporting/Reportlet.php
index 2876a00..1c74f38 100644
--- a/library/Reporting/Reportlet.php
+++ b/library/Reporting/Reportlet.php
@@ -1,13 +1,11 @@
<?php
+
// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2
namespace Icinga\Module\Reporting;
class Reportlet
{
- /** @var int */
- protected $id;
-
/** @var string */
protected $class;
@@ -15,23 +13,29 @@ class Reportlet
protected $config;
/**
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
-
- /**
- * @param int $id
+ * Create reportlet from the given model
*
- * @return $this
+ * @param Model\Reportlet $reportletModel
+ *
+ * @return static
*/
- public function setId($id)
+ public static function fromModel(Model\Reportlet $reportletModel): self
{
- $this->id = $id;
+ $reportlet = new static();
+ $reportlet->class = $reportletModel->class;
+
+ $reportletConfig = [
+ 'name' => $reportletModel->report_name,
+ 'id' => $reportletModel->report_id
+ ];
+
+ foreach ($reportletModel->config as $config) {
+ $reportletConfig[$config->name] = $config->value;
+ }
- return $this;
+ $reportlet->config = $reportletConfig;
+
+ return $reportlet;
}
/**
@@ -43,18 +47,6 @@ class Reportlet
}
/**
- * @param string $class
- *
- * @return $this
- */
- public function setClass($class)
- {
- $this->class = $class;
-
- return $this;
- }
-
- /**
* @return array
*/
public function getConfig()
@@ -63,24 +55,12 @@ class Reportlet
}
/**
- * @param array $config
- *
- * @return $this
- */
- public function setConfig($config)
- {
- $this->config = $config;
-
- return $this;
- }
-
- /**
* @return \Icinga\Module\Reporting\Hook\ReportHook
*/
public function getImplementation()
{
$class = $this->getClass();
- return new $class;
+ return new $class();
}
}