summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Table/BasketTable.php
blob: 25e37e02bc16d5a7ae615688cf940c18eb9ba19b (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
<?php

namespace Icinga\Module\Director\Web\Table;

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

class BasketTable extends ZfQueryBasedTable
{
    protected $searchColumns = [
        'basket_name',
    ];

    public function renderRow($row)
    {
        $tr = $this::row([
            new Link(
                $row->basket_name,
                'director/basket',
                ['name' => $row->basket_name]
            ),
            $row->cnt_snapshots
        ]);

        return $tr;
    }

    public function getColumnsToBeRendered()
    {
        return [
            $this->translate('Basket'),
            $this->translate('Snapshots'),
        ];
    }

    public function prepareQuery()
    {
        return $this->db()->select()->from([
            'b' => 'director_basket'
        ], [
            'b.uuid',
            'b.basket_name',
            'cnt_snapshots' => 'COUNT(bs.basket_uuid)',
        ])->joinLeft(
            ['bs' => 'director_basket_snapshot'],
            'bs.basket_uuid = b.uuid',
            []
        )->group('b.uuid')->order('b.basket_name');
    }
}