diff --git a/application/tables/IcingaHostTable.php b/application/tables/IcingaHostTable.php index 46665b9e..0ce114c5 100644 --- a/application/tables/IcingaHostTable.php +++ b/application/tables/IcingaHostTable.php @@ -7,7 +7,6 @@ use Icinga\Module\Director\Web\Table\QuickTable; class IcingaHostTable extends QuickTable { - public function getColumns() { return array( @@ -15,6 +14,7 @@ class IcingaHostTable extends QuickTable 'host' => 'h.object_name', 'address' => 'h.address', 'zone' => 'z.object_name', + 'parents' => "GROUP_CONCAT(ih.object_name ORDER BY hi.weight SEPARATOR ', ')" ); } @@ -30,10 +30,11 @@ class IcingaHostTable extends QuickTable 'host' => $view->translate('Hostname'), 'address' => $view->translate('Address'), 'zone' => $view->translate('Zone'), + 'parents' => $view->translate('Imports'), ); } - public function getBaseQuery() + protected function getUnfilteredQuery() { $db = $this->connection()->getConnection(); $query = $db->select()->from( @@ -43,8 +44,35 @@ class IcingaHostTable extends QuickTable array('z' => 'icinga_zone'), 'h.zone_id = z.id', array() - )->order('h.object_name'); + )->joinLeft( + array('hi' => 'icinga_host_inheritance'), + 'hi.host_id = h.id', + array() + )->joinLeft( + array('ih' => 'icinga_host'), + 'hi.parent_host_id = ih.id', + array() + )->group('h.id') + ->order('h.object_name'); return $query; } + + public function count() + { + $db = $this->connection()->getConnection(); + $sub = clone($this->getBaseQuery()); + $sub->columns($this->getColumns()); + $query = $db->select()->from( + array('sub' => $sub), + 'COUNT(*)' + ); + + return $db->fetchOne($query); + } + + public function getBaseQuery() + { + return $this->getUnfilteredQuery()->where('h.object_type = ?', 'object'); + } }