summaryrefslogtreecommitdiffstats
path: root/modules/monitoring/application/views/helpers/Link.php
blob: c5443a4d3193e9591d1fcdb3a5915512e1b4a5fb (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
<?php
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */

/**
 * Helper for generating frequently used jump links
 *
 * Most of the monitoring overviews link to detail information, e.g. the full information of the involved monitored
 * object. Instead of reintroducing link generation and translation in those views, this helper contains most
 * frequently used jump links.
 */
class Zend_View_Helper_Link extends Zend_View_Helper_Abstract
{
    /**
     * Helper entry point
     *
     * @return $this
     */
    public function link()
    {
        return $this;
    }

    /**
     * Create a host link
     *
     * @param   string  $host       Hostname
     * @param   string  $linkText   Link text, e.g. the host's display name
     *
     * @return  string
     */
    public function host($host, $linkText)
    {
        return $this->view->qlink(
            $linkText,
            'monitoring/host/show',
            array('host' => $host),
            array('title' => sprintf($this->view->translate('Show detailed information for host %s'), $linkText))
        );
    }

    /**
     * Create a service link
     *
     * @param   string  $service            Service name
     * @param   string  $serviceLinkText    Text for the service link, e.g. the service's display name
     * @param   string  $host               Hostname
     * @param   string  $hostLinkText       Text for the host link, e.g. the host's display name
     * @param   string  $class              An optional class to use for this link
     *
     * @return  string
     */
    public function service($service, $serviceLinkText, $host, $hostLinkText, $class = null)
    {
        return sprintf(
            '%s&#58; %s',
            $this->host($host, $hostLinkText),
            $this->view->qlink(
                $serviceLinkText,
                'monitoring/service/show',
                array('host' => $host, 'service' => $service),
                array(
                    'title' => sprintf(
                        $this->view->translate('Show detailed information for service %s on host %s'),
                        $serviceLinkText,
                        $hostLinkText
                    ),
                    'class' => $class
                )
            )
        );
    }
}