[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaHostAppliedForServiceTable: new table

git at icinga.org git at icinga.org
Tue Aug 23 16:31:37 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: fbd1adba39c8cce687010def2e66e54d040b70eb
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=fbd1adba39c8cce687010def2e66e54d040b70eb

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue Aug 23 14:04:48 2016 +0000

IcingaHostAppliedForServiceTable: new table

---

 .../tables/IcingaHostAppliedForServiceTable.php    |   95 ++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/application/tables/IcingaHostAppliedForServiceTable.php b/application/tables/IcingaHostAppliedForServiceTable.php
new file mode 100644
index 0000000..2b15bdf
--- /dev/null
+++ b/application/tables/IcingaHostAppliedForServiceTable.php
@@ -0,0 +1,95 @@
+<?php
+
+namespace Icinga\Module\Director\Tables;
+
+use Icinga\Data\DataArray\ArrayDatasource;
+use Icinga\Module\Director\CustomVariable\CustomVariableDictionary;
+use Icinga\Module\Director\Objects\IcingaHost;
+use Icinga\Module\Director\Web\Table\QuickTable;
+
+class IcingaHostAppliedForServiceTable extends QuickTable
+{
+    protected $title;
+
+    protected $host;
+
+    protected $searchColumns = array(
+        'service',
+    );
+
+    public function setDictionary(CustomVariableDictionary $dict)
+    {
+        $data = array();
+
+        foreach ($dict->getValue() as $key => $var) {
+            $data[] = (object) array(
+                'service' => $key,
+            );
+        }
+
+        $this->setConnection(new ArrayDatasource($data));
+        return $this;
+    }
+
+    public function count()
+    {
+        $query = clone($this->getBaseQuery());
+        $this->applyFiltersToQuery($query);
+        return $query->count();
+    }
+
+    public function fetchData()
+    {
+        $query = $this->getBaseQuery()->columns($this->getColumns());
+
+        if ($this->hasLimit() || $this->hasOffset()) {
+            $query->limit($this->getLimit(), $this->getOffset());
+        }
+
+        $this->applyFiltersToQuery($query);
+
+        return $query->fetchAll();
+    }
+
+    public function getColumns()
+    {
+        return array(
+            'service' => 'service'
+        );
+    }
+
+    public function setTitle($title)
+    {
+        $this->title = $title;
+        return $this;
+    }
+
+    public function setHost(IcingaHost $host)
+    {
+        $this->host = $host;
+        return $this;
+    }
+
+    protected function getActionUrl($row)
+    {
+        $params = array(
+            'name'    => $this->host->object_name,
+            'service' => $row->service,
+        );
+
+        return $this->url('director/host/appliedservice', $params);
+    }
+
+    public function getTitles()
+    {
+        $view = $this->view();
+        return array(
+            'service' => $this->title ?: $view->translate('Servicename'),
+        );
+    }
+
+    public function getBaseQuery()
+    {
+        return $this->connection->select();
+    }
+}



More information about the icinga-checkins mailing list