summaryrefslogtreecommitdiffstats
path: root/application/controllers/ReportsController.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:46:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:46:47 +0000
commit4ada86876033fa171e2896d7e3d3c5645d8062db (patch)
treef0d1fee61877df200ccfb1c0af58a39cd551fb46 /application/controllers/ReportsController.php
parentInitial commit. (diff)
downloadicingaweb2-module-reporting-upstream.tar.xz
icingaweb2-module-reporting-upstream.zip
Adding upstream version 0.10.0.upstream/0.10.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/controllers/ReportsController.php')
-rw-r--r--application/controllers/ReportsController.php104
1 files changed, 104 insertions, 0 deletions
diff --git a/application/controllers/ReportsController.php b/application/controllers/ReportsController.php
new file mode 100644
index 0000000..7971897
--- /dev/null
+++ b/application/controllers/ReportsController.php
@@ -0,0 +1,104 @@
+<?php
+// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2
+
+namespace Icinga\Module\Reporting\Controllers;
+
+use GuzzleHttp\Psr7\ServerRequest;
+use Icinga\Module\Reporting\Database;
+use Icinga\Module\Reporting\Web\Controller;
+use Icinga\Module\Reporting\Web\Forms\ReportForm;
+use Icinga\Module\Reporting\Web\ReportsTimeframesAndTemplatesTabs;
+use ipl\Html\Html;
+use ipl\Sql\Select;
+use ipl\Web\Url;
+use ipl\Web\Widget\ButtonLink;
+use ipl\Web\Widget\Icon;
+use ipl\Web\Widget\Link;
+
+class ReportsController extends Controller
+{
+ use Database;
+ use ReportsTimeframesAndTemplatesTabs;
+
+ public function indexAction()
+ {
+ $this->createTabs()->activate('reports');
+
+ if ($this->hasPermission('reporting/reports')) {
+ $this->addControl(new ButtonLink(
+ $this->translate('New Report'),
+ Url::fromPath('reporting/reports/new'),
+ 'plus'
+ ));
+ }
+
+ $tableRows = [];
+
+ $select = (new Select())
+ ->from('report r')
+ ->columns(['r.*', 'timeframe' => 't.name'])
+ ->join('timeframe t', 'r.timeframe_id = t.id')
+ ->orderBy('r.mtime', SORT_DESC);
+
+ foreach ($this->getDb()->select($select) as $report) {
+ $url = Url::fromPath('reporting/report', ['id' => $report->id])->getAbsoluteUrl('&');
+
+ $tableRows[] = Html::tag('tr', ['href' => $url], [
+ Html::tag('td', null, $report->name),
+ Html::tag('td', null, $report->author),
+ Html::tag('td', null, $report->timeframe),
+ Html::tag('td', null, date('Y-m-d H:i', $report->ctime / 1000)),
+ Html::tag('td', null, date('Y-m-d H:i', $report->mtime / 1000)),
+ Html::tag('td', ['class' => 'icon-col'], [
+ new Link(
+ new Icon('edit'),
+ Url::fromPath('reporting/report/edit', ['id' => $report->id])
+ )
+ ])
+ ]);
+ }
+
+ if (! empty($tableRows)) {
+ $table = Html::tag(
+ 'table',
+ ['class' => 'common-table table-row-selectable', 'data-base-target' => '_next'],
+ [
+ Html::tag(
+ 'thead',
+ null,
+ Html::tag(
+ 'tr',
+ null,
+ [
+ Html::tag('th', null, 'Name'),
+ Html::tag('th', null, 'Author'),
+ Html::tag('th', null, 'Timeframe'),
+ Html::tag('th', null, 'Date Created'),
+ Html::tag('th', null, 'Date Modified'),
+ Html::tag('th')
+ ]
+ )
+ ),
+ Html::tag('tbody', null, $tableRows)
+ ]
+ );
+
+ $this->addContent($table);
+ } else {
+ $this->addContent(Html::tag('p', null, 'No reports created yet.'));
+ }
+ }
+
+ public function newAction()
+ {
+ $this->assertPermission('reporting/reports');
+ $this->addTitleTab($this->translate('New Report'));
+
+ $form = new ReportForm();
+ $form->handleRequest(ServerRequest::fromGlobals());
+
+ $this->redirectForm($form, 'reporting/reports');
+
+ $this->addContent($form);
+ }
+}