summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Table/DatalistEntryTable.php
blob: 70167c75414ce7cfd61196781a5f9cb3ee5b924b (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
68
69
70
71
72
73
<?php

namespace Icinga\Module\Director\Web\Table;

use Icinga\Module\Director\Objects\DirectorDatalist;
use gipfl\IcingaWeb2\Link;
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;

class DatalistEntryTable extends ZfQueryBasedTable
{
    protected $datalist;

    protected $searchColumns = [
        'entry_name',
        'entry_value'
    ];

    public function setList(DirectorDatalist $list)
    {
        $this->datalist = $list;

        return $this;
    }

    public function getList()
    {
        return $this->datalist;
    }

    public function getColumns()
    {
        return  [
            'list_name'   => 'l.list_name',
            'list_id'     => 'le.list_id',
            'entry_name'  => 'le.entry_name',
            'entry_value' => 'le.entry_value',
        ];
    }

    public function renderRow($row)
    {
        return $this::tr([
            $this::td(Link::create($row->entry_name, 'director/data/listentry/edit', [
                'list'       => $row->list_name,
                'entry_name' => $row->entry_name,
            ])),
            $this::td($row->entry_value)
        ]);
    }

    public function getColumnsToBeRendered()
    {
        return [
            'entry_name'    => $this->translate('Key'),
            'entry_value'   => $this->translate('Label'),
        ];
    }

    public function prepareQuery()
    {
        return $this->db()->select()->from(
            ['le' => 'director_datalist_entry'],
            $this->getColumns()
        )->join(
            ['l' => 'director_datalist'],
            'l.id = le.list_id',
            []
        )->where(
            'le.list_id = ?',
            $this->getList()->id
        )->order('le.entry_name ASC');
    }
}