summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Table/ChoicesTable.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Director/Web/Table/ChoicesTable.php')
-rw-r--r--library/Director/Web/Table/ChoicesTable.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/library/Director/Web/Table/ChoicesTable.php b/library/Director/Web/Table/ChoicesTable.php
new file mode 100644
index 0000000..4ba2460
--- /dev/null
+++ b/library/Director/Web/Table/ChoicesTable.php
@@ -0,0 +1,65 @@
+<?php
+
+namespace Icinga\Module\Director\Web\Table;
+
+use Icinga\Module\Director\Db;
+use gipfl\IcingaWeb2\Link;
+use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
+use gipfl\IcingaWeb2\Url;
+
+class ChoicesTable extends ZfQueryBasedTable
+{
+ protected $searchColumns = ['o.object_name'];
+
+ protected $type;
+
+ /**
+ * @param $type
+ * @param Db $db
+ * @return static
+ */
+ public static function create($type, Db $db)
+ {
+ $class = __NAMESPACE__ . '\\ChoicesTable' . ucfirst($type);
+ if (! class_exists($class)) {
+ $class = __CLASS__;
+ }
+
+ /** @var static $table */
+ $table = new $class($db);
+ $table->type = $type;
+ return $table;
+ }
+
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ public function getColumnsToBeRendered()
+ {
+ return [$this->translate('Name')];
+ }
+
+ public function renderRow($row)
+ {
+ $type = $this->getType();
+ $url = Url::fromPath("director/templatechoice/${type}", [
+ 'name' => $row->object_name
+ ]);
+
+ return $this::row([
+ Link::create($row->object_name, $url)
+ ]);
+ }
+
+ protected function prepareQuery()
+ {
+ $type = $this->getType();
+ $table = "icinga_${type}_template_choice";
+ return $this->db()
+ ->select()
+ ->from(['o' => $table], 'object_name')
+ ->order('o.object_name');
+ }
+}