summaryrefslogtreecommitdiffstats
path: root/library/Reporting/Hook/ReportHook.php
blob: 13cc01e5fe4ac3130289a02fd1235280dcab6801 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2

namespace Icinga\Module\Reporting\Hook;

use Icinga\Application\ClassLoader;
use Icinga\Application\Hook;
use Icinga\Module\Reporting\ReportData;
use Icinga\Module\Reporting\Timerange;
use ipl\Html\Form;
use ipl\Html\ValidHtml;

abstract class ReportHook
{
    /**
     * Get the name of the report
     *
     * @return  string
     */
    abstract public function getName();

    /**
     * @param   Timerange   $timerange
     * @param   array       $config
     *
     * @return  ReportData|null
     */
    public function getData(Timerange $timerange, array $config = null)
    {
        return null;
    }

    /**
     * Get the HTML of the report
     *
     * @param   Timerange   $timerange
     * @param   array       $config
     *
     * @return  ValidHtml|null
     */
    public function getHtml(Timerange $timerange, array $config = null)
    {
        return null;
    }

    /**
     * Initialize the report's configuration form
     *
     * @param   Form    $form
     */
    public function initConfigForm(Form $form)
    {
    }

    /**
     * Get the description of the report
     *
     * @return  string
     */
    public function getDescription()
    {
        return null;
    }

    /**
     * Get whether the report provides reporting data
     *
     * @return  bool
     */
    public function providesData()
    {
        try {
            $method = new \ReflectionMethod($this, 'getData');
        } catch (\ReflectionException $e) {
            return false;
        }

        return $method->getDeclaringClass()->getName() !== self::class;
    }

    /**
     * Get whether the report provides HTML
     *
     * @return  bool
     */
    public function providesHtml()
    {
        try {
            $method = new \ReflectionMethod($this, 'getHtml');
        } catch (\ReflectionException $e) {
            return false;
        }

        return $method->getDeclaringClass()->getName() !== self::class;
    }

    /**
     * Get the module name of the report
     *
     * @return  string
     */
    final public function getModuleName()
    {
        return ClassLoader::extractModuleName(get_class($this));
    }

    /**
     * Get all provided reports
     *
     * @return  ReportHook[]
     */
    final public static function getReports()
    {
        return Hook::all('reporting/Report');
    }
}