diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:28:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:28:59 +0000 |
commit | 978a1651bac3faf5e91ddba327bf39aeb6a4cb63 (patch) | |
tree | f0d1fee61877df200ccfb1c0af58a39cd551fb46 /library/Reporting/Timeframe.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-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/Timeframe.php')
-rw-r--r-- | library/Reporting/Timeframe.php | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/library/Reporting/Timeframe.php b/library/Reporting/Timeframe.php new file mode 100644 index 0000000..f295779 --- /dev/null +++ b/library/Reporting/Timeframe.php @@ -0,0 +1,168 @@ +<?php +// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 + +namespace Icinga\Module\Reporting; + +use ipl\Sql\Select; + +class Timeframe +{ + use Database; + + /** @var int */ + protected $id; + + /** @var string */ + protected $name; + + /** @var string */ + protected $title; + + /** @var string */ + protected $start; + + /** @var string */ + protected $end; + + /** + * @param int $id + * + * @return static + * + * @throws \Exception + */ + public static function fromDb($id) + { + $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); + + return $timeframe; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + * + * @return $this + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * + * @return $this + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * + * @return $this + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * @return string + */ + public function getStart() + { + return $this->start; + } + + /** + * @param string $start + * + * @return $this + */ + public function setStart($start) + { + $this->start = $start; + + return $this; + } + + /** + * @return string + */ + public function getEnd() + { + 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()); + $end = new \DateTime($this->getEnd()); + + return new Timerange($start, $end); + } +} |