summaryrefslogtreecommitdiffstats
path: root/application/controllers/TestController.php
blob: f666085a3dd759330bbd11876687043adf150913 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2

namespace Icinga\Module\Reporting\Controllers;

use Icinga\Module\Reporting\Database;
use Icinga\Module\Reporting\Timeframe;
use Icinga\Module\Reporting\Web\Controller;
use ipl\Html\Table;
use ipl\Sql\Select;

class TestController extends Controller
{
    use Database;

    public function timeframesAction()
    {
        $select = (new Select())
            ->from('timeframe')
            ->columns('*');

        $table = new Table();

        $table->getAttributes()->add('class', 'common-table');

        $table->getHeader()->add(Table::row(['Name', 'Title', 'Start', 'End'], null, 'th'));

        foreach ($this->getDb()->select($select) as $row) {
            $timeframe = (new Timeframe())
                ->setName($row->name)
                ->setTitle($row->title)
                ->setStart($row->start)
                ->setEnd($row->end);

            $table->getBody()->add(Table::row([
                $timeframe->getName(),
                $timeframe->getTitle(),
                $timeframe->getTimerange()->getStart()->format('Y-m-d H:i:s'),
                $timeframe->getTimerange()->getEnd()->format('Y-m-d H:i:s')
            ]));
        }

        $this->addTitleTab('Timeframes');

        $this->addContent($table);
    }
}