summaryrefslogtreecommitdiffstats
path: root/application/controllers/TimeframeController.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--application/controllers/TimeframeController.php41
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);
}