summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Table/SyncruleTable.php
blob: 4a8e4e5c021ead51b866ad3658572a6945c59d3d (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

namespace Icinga\Module\Director\Web\Table;

use gipfl\IcingaWeb2\Link;
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;

class SyncruleTable extends ZfQueryBasedTable
{
    protected $searchColumns = [
        'rule_name',
        'description',
    ];

    protected function assemble()
    {
        $this->getAttributes()->add('class', 'syncstate');
        parent::assemble();
    }

    public function renderRow($row)
    {
        $caption = [Link::create(
            $row->rule_name,
            'director/syncrule',
            ['id' => $row->id]
        )];
        if ($row->description !== null) {
            $caption[] = ': ' . $row->description;
        }

        if ($row->sync_state === 'failing' && $row->last_error_message) {
            $caption[] = ' (' . $row->last_error_message . ')';
        }

        $tr = $this::row([$caption, $row->object_type]);
        $tr->getAttributes()->add('class', $row->sync_state);

        return $tr;
    }

    public function getColumnsToBeRendered()
    {
        return [
            $this->translate('Rule name'),
            $this->translate('Object type'),
        ];
    }

    public function prepareQuery()
    {
        return $this->db()->select()->from(
            ['s' => 'sync_rule'],
            [
                'id'                 => 's.id',
                'rule_name'          => 's.rule_name',
                'sync_state'         => 's.sync_state',
                'object_type'        => 's.object_type',
                'update_policy'      => 's.update_policy',
                'purge_existing'     => 's.purge_existing',
                'filter_expression'  => 's.filter_expression',
                'last_error_message' => 's.last_error_message',
                'description'        => 's.description',
            ]
        )->order('rule_name');
    }
}