From 65b28fc2f6d191cd9dbc04dd0e30a968fbba78a1 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 20 Apr 2016 14:06:22 +0200 Subject: [PATCH] SyncRunTable: add new table, link and show it --- .../controllers/SyncruleController.php | 18 +++++ application/tables/SyncRunTable.php | 78 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 application/tables/SyncRunTable.php diff --git a/application/controllers/SyncruleController.php b/application/controllers/SyncruleController.php index 9e47c314..a8994c04 100644 --- a/application/controllers/SyncruleController.php +++ b/application/controllers/SyncruleController.php @@ -109,6 +109,20 @@ class SyncruleController extends ActionController $this->setViewScript('list/table'); } + public function historyAction() + { + $this->view->stayHere = true; + + $id = $this->params->get('id'); + $this->prepareRuleTabs($id)->activate('history'); + $this->view->title = $this->translate('Sync history'); + $this->view->table = $this->loadTable('syncRun') + ->enforceFilter(Filter::where('rule_id', $id)) + ->setConnection($this->db()); + + $this->setViewScript('list/table'); + } + protected function prepareRuleTabs($ruleId = null) { if ($ruleId) { @@ -120,6 +134,10 @@ class SyncruleController extends ActionController 'label' => $this->translate('Properties'), 'url' => 'director/syncrule/property', 'urlParams' => array('rule_id' => $ruleId) + ))->add('history', array( + 'label' => $this->translate('History'), + 'url' => 'director/syncrule/history', + 'urlParams' => array('id' => $ruleId) )); } else { return $this->getTabs()->add('add', array( diff --git a/application/tables/SyncRunTable.php b/application/tables/SyncRunTable.php new file mode 100644 index 00000000..1ba51910 --- /dev/null +++ b/application/tables/SyncRunTable.php @@ -0,0 +1,78 @@ + 'sr.id', + 'rule_id' => 'sr.rule_id', + 'rule_name' => 'sr.rule_name', + 'start_time' => 'sr.start_time', + 'duration_ms' => 'sr.duration_ms', + 'objects_deleted' => 'sr.objects_deleted', + 'objects_created' => 'sr.objects_created', + 'objects_modified' => 'sr.objects_modified', + 'last_former_activity' => 'sr.last_former_activity', + 'last_related_activity' => 'sr.last_related_activity', + ); + } + + protected function getActionUrl($row) + { + return $this->url( + 'director/syncrule/history', + array( + 'id' => $row->rule_id, + 'run_id' => $row->id, + ) + ); + } + + public function getTitles() + { + $singleRule = false; + + foreach ($this->enforcedFilters as $filter) { + if (in_array('rule_id', $filter->listFilteredColumns())) { + $singleRule = true; + break; + } + } + + $view = $this->view(); + + if ($singleRule) { + return array( + 'start_time' => $view->translate('Start time'), + 'objects_created' => $view->translate('Created'), + 'objects_modified' => $view->translate('Modified'), + 'objects_deleted' => $view->translate('Deleted'), + ); + } else { + return array( + 'rule_name' => $view->translate('Rule name'), + 'start_time' => $view->translate('Start time'), + ); + } + } + + public function getBaseQuery() + { + $db = $this->connection()->getConnection(); + + $query = $db->select()->from( + array('sr' => 'sync_run'), + array() + )->order('rule_name'); + + return $query; + } +}