summaryrefslogtreecommitdiffstats
path: root/library/Reporting/Hook
diff options
context:
space:
mode:
Diffstat (limited to 'library/Reporting/Hook')
-rw-r--r--library/Reporting/Hook/ActionHook.php37
-rw-r--r--library/Reporting/Hook/ReportHook.php116
2 files changed, 153 insertions, 0 deletions
diff --git a/library/Reporting/Hook/ActionHook.php b/library/Reporting/Hook/ActionHook.php
new file mode 100644
index 0000000..ef550ee
--- /dev/null
+++ b/library/Reporting/Hook/ActionHook.php
@@ -0,0 +1,37 @@
+<?php
+// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2
+
+namespace Icinga\Module\Reporting\Hook;
+
+use Icinga\Application\Hook;
+use Icinga\Module\Reporting\Report;
+use ipl\Html\Form;
+
+abstract class ActionHook
+{
+ /**
+ * @return string
+ */
+ abstract public function getName();
+
+ /**
+ * @param Report $report
+ * @param array $config
+ */
+ abstract public function execute(Report $report, array $config);
+
+ /**
+ * @param Form $form
+ */
+ public function initConfigForm(Form $form, Report $report)
+ {
+ }
+
+ /**
+ * @return ActionHook[]
+ */
+ final public static function getActions()
+ {
+ return Hook::all('reporting/Action');
+ }
+}
diff --git a/library/Reporting/Hook/ReportHook.php b/library/Reporting/Hook/ReportHook.php
new file mode 100644
index 0000000..13cc01e
--- /dev/null
+++ b/library/Reporting/Hook/ReportHook.php
@@ -0,0 +1,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');
+ }
+}