diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index bd8b99a2..85fff7ec 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -8,7 +8,9 @@ class Director_ListController extends ActionController { $this->setConfigTabs()->activate('activitylog'); $this->view->title = $this->translate('Activity Log'); - $this->view->table = $this->loadTable('activityLog')->setConnection($this->db()); + $this->view->table = $this->applyPaginationLimits( + $this->loadTable('activityLog')->setConnection($this->db()) + ); $this->render('table'); } @@ -21,7 +23,9 @@ class Director_ListController extends ActionController $this->setConfigTabs()->activate('datalist'); $this->view->title = $this->translate('Data lists'); - $this->view->table = $this->loadTable('datalist')->setConnection($this->db()); + $this->view->table = $this->applyPaginationLimits( + $this->loadTable('datalist')->setConnection($this->db()) + ); $this->render('table'); } @@ -34,7 +38,9 @@ class Director_ListController extends ActionController $this->setImportTabs()->activate('importsource'); $this->view->title = $this->translate('Import source'); - $this->view->table = $this->loadTable('importsource')->setConnection($this->db()); + $this->view->table = $this->applyPaginationLimits( + $this->loadTable('importsource')->setConnection($this->db()) + ); $this->render('table'); } @@ -42,7 +48,9 @@ class Director_ListController extends ActionController { $this->setImportTabs()->activate('importrun'); $this->view->title = $this->translate('Import runs'); - $this->view->table = $this->loadTable('importrun')->setConnection($this->db()); + $this->view->table = $this->applyPaginationLimits( + $this->loadTable('importrun')->setConnection($this->db()) + ); $this->render('table'); } @@ -65,7 +73,9 @@ class Director_ListController extends ActionController 'label' => $this->view->title, ))->activate('datalistentry'); - $this->view->table = $this->loadTable('datalistEntry')->setConnection($this->db()); + $this->view->table = $this->applyPaginationLimits( + $this->loadTable('datalistEntry')->setConnection($this->db()) + ); $this->render('table'); } @@ -78,7 +88,9 @@ class Director_ListController extends ActionController $this->setConfigTabs()->activate('datafield'); $this->view->title = $this->translate('Data fields'); - $this->view->table = $this->loadTable('datafield')->setConnection($this->db()); + $this->view->table = $this->applyPaginationLimits( + $this->loadTable('datafield')->setConnection($this->db()) + ); $this->render('table'); } @@ -91,7 +103,9 @@ class Director_ListController extends ActionController $this->setConfigTabs()->activate('generatedconfig'); $this->view->title = $this->translate('Generated Configs'); - $this->view->table = $this->loadTable('generatedConfig')->setConnection($this->db()); + $this->view->table = $this->applyPaginationLimits( + $this->loadTable('generatedConfig')->setConnection($this->db()) + ); $this->render('table'); } } diff --git a/application/tables/ActivityLogTable.php b/application/tables/ActivityLogTable.php index 92c95c1f..299741e1 100644 --- a/application/tables/ActivityLogTable.php +++ b/application/tables/ActivityLogTable.php @@ -41,19 +41,19 @@ class ActivityLogTable extends QuickTable return $this; } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('l' => 'director_activity_log'), - $this->getColumns() + array() )->order('change_time DESC'); foreach ($this->filters as $filter) { $query->where($filter[0], $filter[1]); } - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/DatafieldTable.php b/application/tables/DatafieldTable.php index d043c5be..51aeaa49 100644 --- a/application/tables/DatafieldTable.php +++ b/application/tables/DatafieldTable.php @@ -29,15 +29,15 @@ class DatafieldTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('f' => 'director_datafield'), - $this->getColumns() + array() )->order('varname ASC'); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/DatalistEntryTable.php b/application/tables/DatalistEntryTable.php index 8eb398d5..fd8fc426 100644 --- a/application/tables/DatalistEntryTable.php +++ b/application/tables/DatalistEntryTable.php @@ -37,15 +37,15 @@ class DatalistEntryTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('l' => 'director_datalist_entry'), - $this->getColumns() + array() )->where('l.list_id = ?', $this->getListId())->order('l.entry_name ASC'); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/DatalistTable.php b/application/tables/DatalistTable.php index 7ffbbd24..b887ac16 100644 --- a/application/tables/DatalistTable.php +++ b/application/tables/DatalistTable.php @@ -29,15 +29,15 @@ class DatalistTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('l' => 'director_datalist'), - $this->getColumns() + array() )->order('list_name ASC'); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/GeneratedConfigTable.php b/application/tables/GeneratedConfigTable.php index c5147261..a23793b5 100644 --- a/application/tables/GeneratedConfigTable.php +++ b/application/tables/GeneratedConfigTable.php @@ -38,13 +38,13 @@ class GeneratedConfigTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('l' => 'director_activity_log'), - $this->getColumns() + array() )->joinRight( array('c' => 'director_generated_config'), 'c.last_activity_checksum = l.checksum', @@ -55,6 +55,6 @@ class GeneratedConfigTable extends QuickTable array() )->group('c.checksum')->group('l.id')->order('l.change_time DESC'); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/IcingaCommandArgumentTable.php b/application/tables/IcingaCommandArgumentTable.php index 228abd0f..9adf49b6 100644 --- a/application/tables/IcingaCommandArgumentTable.php +++ b/application/tables/IcingaCommandArgumentTable.php @@ -32,18 +32,18 @@ class IcingaCommandArgumentTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('ca' => 'icinga_command_argument'), - $this->getColumns() + array() )->joinLeft( array('c' => 'icinga_command'), 'ca.command_id = c.id', array() ); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/IcingaCommandTable.php b/application/tables/IcingaCommandTable.php index 9efd0bf9..193a2f6a 100644 --- a/application/tables/IcingaCommandTable.php +++ b/application/tables/IcingaCommandTable.php @@ -31,18 +31,18 @@ class IcingaCommandTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('c' => 'icinga_command'), - $this->getColumns() + array() )->joinLeft( array('z' => 'icinga_zone'), 'c.zone_id = z.id', array() ); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/IcingaEndpointTable.php b/application/tables/IcingaEndpointTable.php index c81b2046..6f0b8615 100644 --- a/application/tables/IcingaEndpointTable.php +++ b/application/tables/IcingaEndpointTable.php @@ -31,18 +31,18 @@ class IcingaEndpointTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('e' => 'icinga_endpoint'), - $this->getColumns() + array() )->joinLeft( array('z' => 'icinga_zone'), 'e.zone_id = z.id', array() ); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/IcingaHostGroupTable.php b/application/tables/IcingaHostGroupTable.php index c12b223a..62c2ed03 100644 --- a/application/tables/IcingaHostGroupTable.php +++ b/application/tables/IcingaHostGroupTable.php @@ -29,14 +29,14 @@ class IcingaHostGroupTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('hg' => 'icinga_hostgroup'), - $this->getColumns() + array() ); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/IcingaHostTable.php b/application/tables/IcingaHostTable.php index ccf962e9..f5771719 100644 --- a/application/tables/IcingaHostTable.php +++ b/application/tables/IcingaHostTable.php @@ -2,10 +2,12 @@ namespace Icinga\Module\Director\Tables; +use Icinga\Data\Limitable; use Icinga\Module\Director\Web\Table\QuickTable; class IcingaHostTable extends QuickTable { + public function getColumns() { return array( @@ -31,18 +33,18 @@ class IcingaHostTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('h' => 'icinga_host'), - $this->getColumns() + array() )->joinLeft( array('z' => 'icinga_zone'), 'h.zone_id = z.id', array() ); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/IcingaHostVarTable.php b/application/tables/IcingaHostVarTable.php index 0771cb77..a252f0b6 100644 --- a/application/tables/IcingaHostVarTable.php +++ b/application/tables/IcingaHostVarTable.php @@ -35,18 +35,16 @@ class IcingaHostVarTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); - $query = $db->select()->from( + return $db->select()->from( array('hv' => 'icinga_host_var'), - $this->getColumns() + array() )->join( array('h' => 'icinga_host'), 'hv.host_id = h.id', array() ); - - return $db->fetchAll($query); } } diff --git a/application/tables/IcingaServiceGroupTable.php b/application/tables/IcingaServiceGroupTable.php index 945ea369..c651e6b5 100644 --- a/application/tables/IcingaServiceGroupTable.php +++ b/application/tables/IcingaServiceGroupTable.php @@ -29,14 +29,14 @@ class IcingaServiceGroupTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('sg' => 'icinga_servicegroup'), - $this->getColumns() + array() ); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/IcingaServiceTable.php b/application/tables/IcingaServiceTable.php index 6d0ed3b5..0fb6bf15 100644 --- a/application/tables/IcingaServiceTable.php +++ b/application/tables/IcingaServiceTable.php @@ -29,18 +29,18 @@ class IcingaServiceTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('s' => 'icinga_service'), - $this->getColumns() + array() )->joinLeft( array('z' => 'icinga_zone'), 's.zone_id = z.id', array() ); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/IcingaServiceVarTable.php b/application/tables/IcingaServiceVarTable.php index c15d1331..6d7c88b7 100644 --- a/application/tables/IcingaServiceVarTable.php +++ b/application/tables/IcingaServiceVarTable.php @@ -35,18 +35,18 @@ class IcingaServiceVarTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('sv' => 'icinga_service_var'), - $this->getColumns() + array() )->join( array('h' => 'icinga_service'), 'sv.service_id = h.id', array() ); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/IcingaTimePeriodTable.php b/application/tables/IcingaTimePeriodTable.php index 6f6f0d5e..ff95cd2e 100644 --- a/application/tables/IcingaTimePeriodTable.php +++ b/application/tables/IcingaTimePeriodTable.php @@ -31,18 +31,18 @@ class IcingaTimePeriodTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('t' => 'icinga_timeperiod'), - $this->getColumns() + array() )->joinLeft( array('z' => 'icinga_zone'), 't.zone_id = z.id', array() ); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/IcingaUserGroupTable.php b/application/tables/IcingaUserGroupTable.php index 441acbb2..c23e1a09 100644 --- a/application/tables/IcingaUserGroupTable.php +++ b/application/tables/IcingaUserGroupTable.php @@ -31,18 +31,18 @@ class IcingaUserGroupTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('ug' => 'icinga_usergroup'), - $this->getColumns() + array() )->joinLeft( array('z' => 'icinga_zone'), 'ug.zone_id = z.id', array() ); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/IcingaUserTable.php b/application/tables/IcingaUserTable.php index a12acb0a..6af95042 100644 --- a/application/tables/IcingaUserTable.php +++ b/application/tables/IcingaUserTable.php @@ -35,18 +35,18 @@ class IcingaUserTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('u' => 'icinga_user'), - $this->getColumns() + array() )->joinLeft( array('z' => 'icinga_zone'), 'u.zone_id = z.id', array() ); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/IcingaZoneTable.php b/application/tables/IcingaZoneTable.php index b0c8bc44..e506d6ec 100644 --- a/application/tables/IcingaZoneTable.php +++ b/application/tables/IcingaZoneTable.php @@ -35,18 +35,18 @@ class IcingaZoneTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('z' => 'icinga_zone'), - $this->getColumns() + array() )->joinLeft( array('e' => 'icinga_endpoint'), 'z.id = e.zone_id', array() )->group('z.id'); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/ImportrunTable.php b/application/tables/ImportrunTable.php index d676fd45..d18ff626 100644 --- a/application/tables/ImportrunTable.php +++ b/application/tables/ImportrunTable.php @@ -33,13 +33,13 @@ class ImportrunTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('s' => 'import_source'), - $this->getColumns() + array() )->join( array('r' => 'import_run'), 'r.source_id = s.id', @@ -54,6 +54,6 @@ class ImportrunTable extends QuickTable array() )->group('r.id')->order('r.start_time DESC'); - return $db->fetchAll($query); + return $query; } } diff --git a/application/tables/ImportsourceTable.php b/application/tables/ImportsourceTable.php index a034be9c..94da74c3 100644 --- a/application/tables/ImportsourceTable.php +++ b/application/tables/ImportsourceTable.php @@ -38,15 +38,15 @@ class ImportsourceTable extends QuickTable ); } - public function fetchData() + public function getBaseQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( array('s' => 'import_source'), - $this->getColumns() + array() )->order('source_name ASC'); - return $db->fetchAll($query); + return $query; } } diff --git a/application/views/scripts/list/table.phtml b/application/views/scripts/list/table.phtml index a0ca6479..bc9f2068 100644 --- a/application/views/scripts/list/table.phtml +++ b/application/views/scripts/list/table.phtml @@ -3,7 +3,8 @@

escape($this->title) ?>

addLink ?> - +
+table->getPaginator() ?>
diff --git a/application/views/scripts/object/history.phtml b/application/views/scripts/object/history.phtml index ccaa702f..09ceb0b1 100644 --- a/application/views/scripts/object/history.phtml +++ b/application/views/scripts/object/history.phtml @@ -1,6 +1,8 @@
tabs ?>

escape($this->title) ?>

+
+table->getPaginator() ?>
diff --git a/application/views/scripts/objects/table.phtml b/application/views/scripts/objects/table.phtml index a0ca6479..bc9f2068 100644 --- a/application/views/scripts/objects/table.phtml +++ b/application/views/scripts/objects/table.phtml @@ -3,7 +3,8 @@

escape($this->title) ?>

addLink ?> - +
+table->getPaginator() ?>
diff --git a/library/Director/Web/Controller/ActionController.php b/library/Director/Web/Controller/ActionController.php index 3f325094..6e055cd5 100644 --- a/library/Director/Web/Controller/ActionController.php +++ b/library/Director/Web/Controller/ActionController.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Director\Web\Controller; use Icinga\Application\Icinga; +use Icinga\Data\Paginatable; use Icinga\Module\Director\Db; use Icinga\Module\Director\Web\Form\FormLoader; use Icinga\Module\Director\Web\Table\TableLoader; @@ -24,6 +25,16 @@ abstract class ActionController extends Controller } } + protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) + { + $limit = $this->params->get('limit', $limit); + $page = $this->params->get('page', $offset); + + $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); + + return $paginatable; + } + public function loadForm($name) { return FormLoader::load($name, $this->Module()); diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php index 96f0899e..aa4040cb 100644 --- a/library/Director/Web/Controller/ObjectController.php +++ b/library/Director/Web/Controller/ObjectController.php @@ -95,10 +95,10 @@ abstract class ObjectController extends ActionController $this->getTabs()->activate('history'); $object = $this->object(); $this->view->title = $this->translate('Activity Log'); - $this->view->table = $this->loadTable('activityLog') - ->setConnection($this->db()) + $this->view->table = $this->applyPaginationLimits( + $this->loadTable('activityLog')->setConnection($this->db()) ->filterObject('icinga_' . $type, $object->object_name) - ; + ); $this->render('object/history', null, true); } diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php index e17e9545..f4382d82 100644 --- a/library/Director/Web/Controller/ObjectsController.php +++ b/library/Director/Web/Controller/ObjectsController.php @@ -81,8 +81,10 @@ abstract class ObjectsController extends ActionController 'director/' . $ltype . '/add' ); $this->view->title = $this->translate('Icinga ' . ucfirst($ltype)); - $this->view->table = $this->loadTable('icinga' . ucfirst($type)) - ->setConnection($this->db()); + $this->view->table = $this->applyPaginationLimits( + $this->loadTable('icinga' . ucfirst($type))->setConnection($this->db()) + ); + $this->render('objects/table', null, true); }