summaryrefslogtreecommitdiffstats
path: root/library/Reporting/Timeframe.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Reporting/Timeframe.php')
-rw-r--r--library/Reporting/Timeframe.php97
1 files changed, 11 insertions, 86 deletions
diff --git a/library/Reporting/Timeframe.php b/library/Reporting/Timeframe.php
index f295779..4e8cb9e 100644
--- a/library/Reporting/Timeframe.php
+++ b/library/Reporting/Timeframe.php
@@ -1,14 +1,13 @@
<?php
+
// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2
namespace Icinga\Module\Reporting;
-use ipl\Sql\Select;
+use Icinga\Module\Reporting\Model;
class Timeframe
{
- use Database;
-
/** @var int */
protected $id;
@@ -25,35 +24,21 @@ class Timeframe
protected $end;
/**
- * @param int $id
+ * Create timeframe from the given model
*
- * @return static
+ * @param Model\Timeframe $timeframeModel
*
- * @throws \Exception
+ * @return static
*/
- public static function fromDb($id)
+ public static function fromModel(Model\Timeframe $timeframeModel): self
{
$timeframe = new static();
- $db = $timeframe->getDb();
-
- $select = (new Select())
- ->from('timeframe')
- ->columns('*')
- ->where(['id = ?' => $id]);
-
- $row = $db->select($select)->fetch();
-
- if ($row === false) {
- throw new \Exception('Timeframe not found');
- }
-
- $timeframe
- ->setId($row->id)
- ->setName($row->name)
- ->setTitle($row->title)
- ->setStart($row->start)
- ->setEnd($row->end);
+ $timeframe->id = $timeframeModel->id;
+ $timeframe->name = $timeframeModel->name;
+ $timeframe->title = $timeframeModel->title;
+ $timeframe->start = $timeframeModel->start;
+ $timeframe->end = $timeframeModel->end;
return $timeframe;
}
@@ -67,18 +52,6 @@ class Timeframe
}
/**
- * @param int $id
- *
- * @return $this
- */
- public function setId($id)
- {
- $this->id = $id;
-
- return $this;
- }
-
- /**
* @return string
*/
public function getName()
@@ -87,18 +60,6 @@ class Timeframe
}
/**
- * @param string $name
- *
- * @return $this
- */
- public function setName($name)
- {
- $this->name = $name;
-
- return $this;
- }
-
- /**
* @return string
*/
public function getTitle()
@@ -107,18 +68,6 @@ class Timeframe
}
/**
- * @param string $title
- *
- * @return $this
- */
- public function setTitle($title)
- {
- $this->title = $title;
-
- return $this;
- }
-
- /**
* @return string
*/
public function getStart()
@@ -127,18 +76,6 @@ class Timeframe
}
/**
- * @param string $start
- *
- * @return $this
- */
- public function setStart($start)
- {
- $this->start = $start;
-
- return $this;
- }
-
- /**
* @return string
*/
public function getEnd()
@@ -146,18 +83,6 @@ class Timeframe
return $this->end;
}
- /**
- * @param string $end
- *
- * @return $this
- */
- public function setEnd($end)
- {
- $this->end = $end;
-
- return $this;
- }
-
public function getTimerange()
{
$start = new \DateTime($this->getStart());