From e5305cb049379ddb3fd9c76969300c7fb5c91f5e Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 13 Aug 2017 13:38:35 +0200 Subject: [PATCH] IcingaObjectDatafieldTable: move and base on new ...SimpleQueryBased table --- .../Web/Table}/IcingaObjectDatafieldTable.php | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) rename {application/tables => library/Director/Web/Table}/IcingaObjectDatafieldTable.php (50%) diff --git a/application/tables/IcingaObjectDatafieldTable.php b/library/Director/Web/Table/IcingaObjectDatafieldTable.php similarity index 50% rename from application/tables/IcingaObjectDatafieldTable.php rename to library/Director/Web/Table/IcingaObjectDatafieldTable.php index ffb2c1bc..daf3d37c 100644 --- a/application/tables/IcingaObjectDatafieldTable.php +++ b/library/Director/Web/Table/IcingaObjectDatafieldTable.php @@ -1,25 +1,25 @@ object = $object; $this->objectId = (int) $object->id; - $this->setConnection($object->getConnection()); return $this; } @@ -43,43 +43,41 @@ class IcingaObjectDatafieldTable extends QuickTable ); } - protected function getActionUrl($row) + public function getColumnsToBeRendered() { - if ((int) $row->object_id !== $this->objectId) { - return null; - } - - return Url::fromRequest()->with('field_id', $row->id); - } - - protected function getRowClasses($row) - { - if ((int) $row->object_id !== $this->objectId) { - return array('disabled'); - } - } - - public function getTitles() - { - $view = $this->view(); return array( - 'caption' => $view->translate('Label'), - 'varname' => $view->translate('Field name'), - 'is_required' => $view->translate('Mandatory'), + 'caption' => $this->translate('Label'), + 'varname' => $this->translate('Field name'), + 'is_required' => $this->translate('Mandatory'), ); } - public function count() + public function renderRow($row) { - return $this->getBaseQuery()->count(); + $definedOnThis = (int) $row->object_id === $this->objectId; + if ($definedOnThis) { + $caption = new Link( + $row->caption, + Url::fromRequest()->with('field_id', $row->id) + ); + } else { + $caption = $row->caption; + } + + $row = $this::row([ + $caption, + $row->varname, + $row->is_required + ]); + + if (! $definedOnThis) { + $row->attributes()->add('class', 'disabled'); + } + + return $row; } - public function fetchData() - { - return $this->getBaseQuery()->fetchAll(); - } - - public function getBaseQuery() + public function prepareQuery() { $loader = new IcingaObjectFieldLoader($this->object); $fields = $loader->fetchFieldDetailsForObject($this->object);