diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:29:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:29:16 +0000 |
commit | 8a985929ed84cdb458a13c66b25f84e41133b24f (patch) | |
tree | 102a3d6e3cb731c6d23263095d0098f99572626d /application/controllers/TimeframeController.php | |
parent | Adding upstream version 0.10.0. (diff) | |
download | icingaweb2-module-reporting-8a985929ed84cdb458a13c66b25f84e41133b24f.tar.xz icingaweb2-module-reporting-8a985929ed84cdb458a13c66b25f84e41133b24f.zip |
Adding upstream version 1.0.1.upstream/1.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/controllers/TimeframeController.php')
-rw-r--r-- | application/controllers/TimeframeController.php | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/application/controllers/TimeframeController.php b/application/controllers/TimeframeController.php index ca67b0b..01395c2 100644 --- a/application/controllers/TimeframeController.php +++ b/application/controllers/TimeframeController.php @@ -1,24 +1,37 @@ <?php + // Icinga Reporting | (c) 2019 Icinga GmbH | GPLv2 namespace Icinga\Module\Reporting\Controllers; -use GuzzleHttp\Psr7\ServerRequest; +use Exception; use Icinga\Module\Reporting\Database; +use Icinga\Module\Reporting\Model; use Icinga\Module\Reporting\Timeframe; use Icinga\Module\Reporting\Web\Controller; use Icinga\Module\Reporting\Web\Forms\TimeframeForm; +use Icinga\Web\Notification; +use ipl\Html\Form; +use ipl\Web\Url; +use ipl\Stdlib\Filter; class TimeframeController extends Controller { - use Database; - /** @var Timeframe */ protected $timeframe; public function init() { - $this->timeframe = Timeframe::fromDb($this->params->getRequired('id')); + /** @var Model\Timeframe $timeframe */ + $timeframe = Model\Timeframe::on(Database::get()) + ->filter(Filter::equal('id', $this->params->getRequired('id'))) + ->first(); + + if ($timeframe === null) { + throw new Exception('Timeframe not found'); + } + + $this->timeframe = Timeframe::fromModel($timeframe); } public function editAction() @@ -32,15 +45,19 @@ class TimeframeController extends Controller 'end' => $this->timeframe->getEnd() ]; + $form = TimeframeForm::fromId($this->timeframe->getId()) + ->setAction((string) Url::fromRequest()) + ->populate($values) + ->on(TimeframeForm::ON_SUCCESS, function (Form $form) { + $pressedButton = $form->getPressedSubmitElement(); + if ($pressedButton && $pressedButton->getName() === 'remove') { + Notification::success($this->translate('Removed timeframe successfully')); + } else { + Notification::success($this->translate('Update timeframe successfully')); + } - $form = (new TimeframeForm()) - ->setId($this->timeframe->getId()); - - $form->populate($values); - - $form->handleRequest(ServerRequest::fromGlobals()); - - $this->redirectForm($form, 'reporting/timeframes'); + $this->switchToSingleColumnLayout(); + })->handleRequest($this->getServerRequest()); $this->addContent($form); } |