summaryrefslogtreecommitdiffstats
path: root/library/Cube/Web/ActionLink.php
blob: c9ad87b0bd68065e698ec4603818c158bf13bde3 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php

// Icinga Web 2 Cube Module | (c) 2016 Icinga GmbH | GPLv2

namespace Icinga\Module\Cube\Web;

use Icinga\Web\Url;
use Icinga\Web\View;

/**
 * ActionLink
 *
 * ActionLinksHook implementations return instances of this class
 *
 * @package Icinga\Module\Cube\Web
 */
class ActionLink
{
    /** @var Url */
    protected $url;

    /** @var string */
    protected $title;

    /** @var string */
    protected $description;

    /** @var string */
    protected $icon;

    /**
     * ActionLink constructor.
     * @param Url $url
     * @param string $title
     * @param string $description
     * @param string $icon
     */
    public function __construct(Url $url, $title, $description, $icon)
    {
        $this->url         = $url;
        $this->title       = $title;
        $this->description = $description;
        $this->icon        = $icon;
    }

    /**
     * @return Url
     */
    public function getUrl()
    {
        return $this->url;
    }

    /**
     * @return string
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * @return string
     */
    public function getIcon()
    {
        return $this->icon;
    }

    /**
     * Render our icon
     *
     * @param View $view
     * @return string
     */
    protected function renderIcon(View $view)
    {
        return $view->icon($this->getIcon());
    }

    /**
     * @param View $view
     * @return string
     */
    public function render(View $view)
    {
        return sprintf(
            '<a href="%s">%s<span class="title">%s</span><p>%s</p></a>',
            $this->getUrl(),
            $this->renderIcon($view),
            $view->escape($this->getTitle()),
            $view->escape($this->getDescription())
        );
    }
}