From d5ccb1edb5483bbb53ca20141075db569bfabbf5 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 16 Aug 2017 14:55:34 +0200 Subject: [PATCH] Importrun, imported rows: move and refactor... ...table and refactor the controller --- .../controllers/ImportrunController.php | 28 ++++-------- .../Director/Web/Table}/ImportedrowsTable.php | 43 +++++++------------ 2 files changed, 23 insertions(+), 48 deletions(-) rename {application/tables => library/Director/Web/Table}/ImportedrowsTable.php (52%) diff --git a/application/controllers/ImportrunController.php b/application/controllers/ImportrunController.php index 9476d320..d0e34e55 100644 --- a/application/controllers/ImportrunController.php +++ b/application/controllers/ImportrunController.php @@ -4,33 +4,21 @@ namespace Icinga\Module\Director\Controllers; use Icinga\Module\Director\Objects\ImportRun; use Icinga\Module\Director\Web\Controller\ActionController; +use Icinga\Module\Director\Web\Table\ImportedrowsTable; class ImportrunController extends ActionController { public function indexAction() { - $db = $this->db(); - $id = $this->getRequest()->getUrl()->getParams()->shift('id'); - $importRun = ImportRun::load($id, $db); - $url = clone($this->getRequest()->getUrl()); - $chosenColumns = $this->getRequest()->getUrl()->shift('chosenColumns'); + $importRun = ImportRun::load($this->params->getRequired('id'), $this->db()); + $this->addTitle($this->translate('Import run')); + $this->addSingleTab($this->translate('Import run')); - $this->view->title = $this->translate('Import run'); - $this->getTabs()->add('importrun', array( - 'label' => $this->view->title, - 'url' => $url - ))->activate('importrun'); - - $table = $this - ->loadTable('importedrows') - ->setConnection($db) - ->setImportRun($importRun); - - if ($chosenColumns) { - $table->setColumns(preg_split('/,/', $chosenColumns, -1, PREG_SPLIT_NO_EMPTY)); + $table = ImportedrowsTable::load($importRun); + if ($chosen = $this->params->get('chosenColumns')) { + $table->setColumns(preg_split('/,/', $chosen, -1, PREG_SPLIT_NO_EMPTY)); } - $this->view->table = $this->applyPaginationLimits($table); - $this->view->filterEditor = $table->getFilterEditor($this->getRequest()); + $table->renderTo($this); } } diff --git a/application/tables/ImportedrowsTable.php b/library/Director/Web/Table/ImportedrowsTable.php similarity index 52% rename from application/tables/ImportedrowsTable.php rename to library/Director/Web/Table/ImportedrowsTable.php index 64d72ff4..3c1fdf73 100644 --- a/application/tables/ImportedrowsTable.php +++ b/library/Director/Web/Table/ImportedrowsTable.php @@ -1,18 +1,25 @@ setImportRun($run); + return $table; + } + public function setImportRun(ImportRun $run) { $this->importRun = $run; @@ -42,35 +49,15 @@ class ImportedrowsTable extends QuickTable return array_combine($cols, $cols); } - public function getTitles() + public function getColumnsToBeRendered() { - $cols = $this->getColumns(); - // TODO: replace key column with object name!? - // $view = $this->view(); - // 'object_name' => $view->translate('Object name') - return array_combine($cols, $cols); + return $this->getColumns(); } - public function fetchData() - { - $query = $this->getBaseQuery()->columns($this->getColumns()); - - if ($this->hasLimit() || $this->hasOffset()) { - $query->limit($this->getLimit(), $this->getOffset()); - } - - return $query->fetchAll(); - } - - public function count() - { - return $this->getBaseQuery()->count(); - } - - public function getBaseQuery() + public function prepareQuery() { $ds = new ArrayDatasource( - $this->importRun->fetchRows($this->columns, $this->filter) + $this->importRun->fetchRows($this->columns) ); return $ds->select()->order('object_name');