summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Table/ObjectsTableEndpoint.php
blob: f73b38bcda609fbaa376d130c0261baafaa86a7c (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
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php

namespace Icinga\Module\Director\Web\Table;

use gipfl\IcingaWeb2\Icon;
use Zend_Db_Select as ZfSelect;

class ObjectsTableEndpoint extends ObjectsTable
{
    protected $searchColumns = [
        'o.object_name',
    ];

    protected $deploymentEndpoint;

    public function getColumnsToBeRendered()
    {
        return array(
            'object_name' => $this->translate('Endpoint'),
            'host'        => $this->translate('Host'),
            'zone'        => $this->translate('Zone'),
            'object_type' => $this->translate('Type'),
        );
    }

    public function getColumns()
    {
        return [
            'uuid'        => 'o.uuid',
            'object_name' => 'o.object_name',
            'object_type' => 'o.object_type',
            'disabled'    => 'o.disabled',
            'host' => "(CASE WHEN o.host IS NULL THEN NULL ELSE"
                . " CONCAT(o.host || ':' || COALESCE(o.port, 5665)) END)",
            'zone' => 'z.object_name',
        ];
    }

    protected function getMainLinkLabel($row)
    {
        if ($row->object_name === $this->deploymentEndpoint) {
            return [
                $row->object_name,
                ' ',
                Icon::create('upload', [
                    'title' => $this->translate(
                        'This is your Config master and will receive our Deployments'
                    )
                ])
            ];
        } else {
            return $row->object_name;
        }
    }

    public function getRowClasses($row)
    {
        if ($row->object_name === $this->deploymentEndpoint) {
            return array_merge(array('deployment-endpoint'), parent::getRowClasses($row));
        } else {
            return null;
        }
    }

    protected function applyObjectTypeFilter(ZfSelect $query, ZfSelect $right = null)
    {
        return $query->where("o.object_type IN ('object', 'external_object')");
    }

    public function prepareQuery()
    {
        if ($this->deploymentEndpoint === null) {
            /** @var \Icinga\Module\Director\Db $c */
            $c = $this->connection();
            if ($c->hasDeploymentEndpoint()) {
                $this->deploymentEndpoint = $c->getDeploymentEndpointName();
            }
        }

        return parent::prepareQuery()->joinLeft(
            ['z' => 'icinga_zone'],
            'o.zone_id = z.id',
            []
        );
    }
}