Skip to content

Commit 5092e29

Browse files
committed
WIP
1 parent 6013a76 commit 5092e29

16 files changed

+404
-382
lines changed

application/controllers/ReportController.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
use Icinga\Application\Hook;
99
use Icinga\Module\Pdfexport\ProvidedHook\Pdfexport;
1010
use Icinga\Module\Reporting\Database;
11+
use Icinga\Module\Reporting\Model;
1112
use Icinga\Module\Reporting\Report;
1213
use Icinga\Module\Reporting\Web\Controller;
1314
use Icinga\Module\Reporting\Web\Forms\ReportForm;
1415
use Icinga\Module\Reporting\Web\Forms\ScheduleForm;
1516
use Icinga\Module\Reporting\Web\Forms\SendForm;
1617
use Icinga\Module\Reporting\Web\Widget\CompatDropdown;
1718
use ipl\Html\Error;
19+
use ipl\Stdlib\Filter;
1820
use ipl\Web\Url;
1921
use ipl\Web\Widget\ActionBar;
2022
use Icinga\Util\Environment;
@@ -28,7 +30,19 @@ class ReportController extends Controller
2830

2931
public function init()
3032
{
31-
$this->report = Report::fromDb($this->params->getRequired('id'));
33+
/** @var $report Model\Report */
34+
$report = Model\Report::on($this->getDb())
35+
->with([
36+
'timeframe',
37+
'template',
38+
'reportlet',
39+
'reportlet.config',
40+
'schedule'
41+
])
42+
->filter(Filter::equal('id', $this->params->getRequired('id')))
43+
->first();
44+
45+
$this->report = Report::fromModel($report);
3246
}
3347

3448
public function indexAction()

application/controllers/ReportsController.php

+14-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
use GuzzleHttp\Psr7\ServerRequest;
88
use Icinga\Module\Reporting\Database;
9+
use Icinga\Module\Reporting\Model\Report;
910
use Icinga\Module\Reporting\Web\Controller;
1011
use Icinga\Module\Reporting\Web\Forms\ReportForm;
1112
use Icinga\Module\Reporting\Web\ReportsTimeframesAndTemplatesTabs;
1213
use ipl\Html\Html;
13-
use ipl\Sql\Select;
1414
use ipl\Web\Url;
1515
use ipl\Web\Widget\ButtonLink;
1616
use ipl\Web\Widget\Icon;
@@ -35,19 +35,24 @@ public function indexAction()
3535

3636
$tableRows = [];
3737

38-
$select = (new Select())
39-
->from('report r')
40-
->columns(['r.*', 'timeframe' => 't.name'])
41-
->join('timeframe t', 'r.timeframe_id = t.id')
42-
->orderBy('r.mtime', SORT_DESC);
38+
$reports = Report::on($this->getDb())
39+
->withColumns(['report.timeframe.name']);
4340

44-
foreach ($this->getDb()->select($select) as $report) {
41+
$sortControl = $this->createSortControl(
42+
$reports,
43+
[
44+
'name' => t('Name'),
45+
'author' => t('Author')
46+
]
47+
);
48+
49+
foreach ($reports as $report) {
4550
$url = Url::fromPath('reporting/report', ['id' => $report->id])->getAbsoluteUrl('&');
4651

4752
$tableRows[] = Html::tag('tr', ['href' => $url], [
4853
Html::tag('td', null, $report->name),
4954
Html::tag('td', null, $report->author),
50-
Html::tag('td', null, $report->timeframe),
55+
Html::tag('td', null, $report->timeframe->name),
5156
Html::tag('td', null, date('Y-m-d H:i', $report->ctime / 1000)),
5257
Html::tag('td', null, date('Y-m-d H:i', $report->mtime / 1000)),
5358
Html::tag('td', ['class' => 'icon-col'], [
@@ -88,6 +93,7 @@ public function indexAction()
8893
} else {
8994
$this->addContent(Html::tag('p', null, 'No reports created yet.'));
9095
}
96+
$this->addControl($sortControl);
9197
}
9298

9399
public function newAction()

application/controllers/TemplateController.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
use DateTime;
88
use GuzzleHttp\Psr7\ServerRequest;
99
use Icinga\Module\Reporting\Database;
10+
use Icinga\Module\Reporting\Model;
1011
use Icinga\Module\Reporting\Web\Controller;
1112
use Icinga\Module\Reporting\Web\Forms\TemplateForm;
1213
use Icinga\Module\Reporting\Web\Widget\Template;
1314
use ipl\Sql\Select;
15+
use ipl\Stdlib\Filter;
1416

1517
class TemplateController extends Controller
1618
{
@@ -20,7 +22,12 @@ public function indexAction()
2022
{
2123
$this->createTabs()->activate('preview');
2224

23-
$template = Template::fromDb($this->params->getRequired('id'));
25+
/** @var $template Model\Template */
26+
$template = Model\Template::on($this->getDb())
27+
->filter(Filter::equal('id', $this->params->getRequired('id')))
28+
->first();
29+
30+
$template = Template::fromModel($template);
2431

2532
if ($template === null) {
2633
throw new \Exception('Template not found');

application/controllers/TimeframeController.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
use GuzzleHttp\Psr7\ServerRequest;
88
use Icinga\Module\Reporting\Database;
9+
use Icinga\Module\Reporting\Model;
910
use Icinga\Module\Reporting\Timeframe;
1011
use Icinga\Module\Reporting\Web\Controller;
1112
use Icinga\Module\Reporting\Web\Forms\TimeframeForm;
13+
use ipl\Stdlib\Filter;
1214

1315
class TimeframeController extends Controller
1416
{
@@ -19,7 +21,12 @@ class TimeframeController extends Controller
1921

2022
public function init()
2123
{
22-
$this->timeframe = Timeframe::fromDb($this->params->getRequired('id'));
24+
/** @var $timeframe Model\Timeframe */
25+
$timeframe = Model\Timeframe::on($this->getDb())
26+
->filter(Filter::equal('id', $this->params->getRequired('id')))
27+
->first();
28+
29+
$this->timeframe = Timeframe::fromModel($timeframe);
2330
}
2431

2532
public function editAction()

library/Reporting/Model/Config.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Icinga\Module\Reporting\Model;
4+
5+
use ipl\Orm\Model;
6+
use ipl\Orm\Relations;
7+
8+
class Config extends Model
9+
{
10+
public function getTableName()
11+
{
12+
return 'config';
13+
}
14+
15+
public function getKeyName()
16+
{
17+
return 'id';
18+
}
19+
20+
public function getColumns()
21+
{
22+
return [
23+
'reportlet_id',
24+
'name',
25+
'value',
26+
'ctime',
27+
'mtime'
28+
];
29+
}
30+
31+
public function createRelations(Relations $relations)
32+
{
33+
$relations->belongsTo('reportlet', Reportlet::class);
34+
}
35+
}

library/Reporting/Model/Report.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Icinga\Module\Reporting\Model;
4+
5+
use ipl\Orm\Model;
6+
use ipl\Orm\Relations;
7+
8+
class Report extends Model
9+
{
10+
public function getTableName()
11+
{
12+
return 'report';
13+
}
14+
15+
public function getKeyName()
16+
{
17+
return 'id';
18+
}
19+
20+
public function getColumns()
21+
{
22+
return [
23+
'timeframe_id',
24+
'template_id',
25+
'author',
26+
'name',
27+
'ctime',
28+
'mtime'
29+
];
30+
}
31+
public function createRelations(Relations $relations)
32+
{
33+
$relations->belongsTo('timeframe', Timeframe::class);
34+
$relations->belongsTo('template', Template::class)
35+
->setJoinType('LEFT');
36+
37+
$relations->hasOne('schedule', Schedule::class)
38+
->setJoinType('LEFT');
39+
$relations->hasMany('reportlet', Reportlet::class)
40+
->setJoinType('LEFT');
41+
}
42+
}

library/Reporting/Model/Reportlet.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Icinga\Module\Reporting\Model;
4+
5+
use ipl\Orm\Model;
6+
use ipl\Orm\Relations;
7+
8+
class Reportlet extends Model
9+
{
10+
public function getTableName()
11+
{
12+
return 'reportlet';
13+
}
14+
15+
public function getKeyName()
16+
{
17+
return 'id';
18+
}
19+
20+
public function getColumns()
21+
{
22+
return [
23+
'report_id',
24+
'class',
25+
'ctime',
26+
'mtime'
27+
];
28+
}
29+
30+
public function createRelations(Relations $relations)
31+
{
32+
$relations->belongsTo('report', Report::class);
33+
34+
$relations->hasMany('config', Config::class)
35+
->setJoinType('LEFT');
36+
}
37+
}

library/Reporting/Model/Schedule.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Icinga\Module\Reporting\Model;
4+
5+
use ipl\Orm\Model;
6+
use ipl\Orm\Relations;
7+
8+
class Schedule extends Model
9+
{
10+
public function getTableName()
11+
{
12+
return 'schedule';
13+
}
14+
15+
public function getKeyName()
16+
{
17+
return 'id';
18+
}
19+
20+
public function getColumns()
21+
{
22+
return [
23+
'report_id',
24+
'author',
25+
'start',
26+
'frequency',
27+
'action',
28+
'config',
29+
'ctime',
30+
'mtime'
31+
];
32+
}
33+
34+
public function createRelations(Relations $relations)
35+
{
36+
$relations->belongsTo('report', Report::class)
37+
->setJoinType('LEFT');
38+
}
39+
}

library/Reporting/Model/Template.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Icinga\Module\Reporting\Model;
4+
5+
use ipl\Orm\Model;
6+
7+
class Template extends Model
8+
{
9+
public function getTableName()
10+
{
11+
return 'template';
12+
}
13+
14+
public function getKeyName()
15+
{
16+
return 'id';
17+
}
18+
19+
public function getColumns()
20+
{
21+
return [
22+
'author',
23+
'name',
24+
'settings',
25+
'ctime',
26+
'mtime'
27+
];
28+
}
29+
}

library/Reporting/Model/Timeframe.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Icinga\Module\Reporting\Model;
4+
5+
use ipl\Orm\Model;
6+
use ipl\Orm\Relations;
7+
8+
class Timeframe extends Model
9+
{
10+
public function getTableName()
11+
{
12+
return 'timeframe';
13+
}
14+
15+
public function getKeyName()
16+
{
17+
return 'id';
18+
}
19+
20+
public function getColumns()
21+
{
22+
return [
23+
'name',
24+
'title',
25+
'start',
26+
'end',
27+
'ctime',
28+
'mtime'
29+
];
30+
}
31+
32+
public function createRelations(Relations $relations)
33+
{
34+
$relations->hasOne('report', Report::class);
35+
}
36+
}

0 commit comments

Comments
 (0)