From df1832aaa932e97332eaf215c69cabf3b666246d Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 20 Jun 2017 21:28:07 +0200 Subject: [PATCH] ChoicesTable: new generic implementation --- library/Director/Web/Table/ChoicesTable.php | 79 +++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 library/Director/Web/Table/ChoicesTable.php diff --git a/library/Director/Web/Table/ChoicesTable.php b/library/Director/Web/Table/ChoicesTable.php new file mode 100644 index 00000000..d9452410 --- /dev/null +++ b/library/Director/Web/Table/ChoicesTable.php @@ -0,0 +1,79 @@ +type = $type; + return $table; + } + + public function renderTo(ControlsAndContent $controller) + { + $url = $controller->url(); + $this->initializeOptionalQuickSearch($controller); + $controller->content()->add([ + $this->getPaginator($url), + $this + ]); + + if ($url->getParam('format') === 'sql') { + $controller->content()->prepend($this->dumpSqlQuery($url)); + } + } + + 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::tr( + $this::td(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'); + } +}