From 31a6ab0cf25ee805c1ebd0c2baac636cfc318a61 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 30 May 2018 00:45:08 +0200 Subject: [PATCH] IcingaHostServiceTable, others: cleanup, fix... ...blacklist-styling --- .../Table/IcingaHostAppliedServicesTable.php | 3 -- .../Web/Table/IcingaHostServiceTable.php | 35 +++++++++++++++++-- .../Table/IcingaServiceSetServiceTable.php | 7 +--- library/vendor/ipl/Html/Link.php | 6 ---- .../ipl/Web/Table/ZfQueryBasedTable.php | 6 ++-- library/vendor/ipl/Web/Url.php | 6 ++-- 6 files changed, 40 insertions(+), 23 deletions(-) diff --git a/library/Director/Web/Table/IcingaHostAppliedServicesTable.php b/library/Director/Web/Table/IcingaHostAppliedServicesTable.php index 170f817d..7c86e55f 100644 --- a/library/Director/Web/Table/IcingaHostAppliedServicesTable.php +++ b/library/Director/Web/Table/IcingaHostAppliedServicesTable.php @@ -76,7 +76,6 @@ class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable /** * @return \Icinga\Data\SimpleQuery - * @throws \Icinga\Exception\IcingaException */ public function prepareQuery() { @@ -100,7 +99,6 @@ class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable /*** * @return array - * @throws \Icinga\Exception\IcingaException */ protected function getAllApplyRules() { @@ -116,7 +114,6 @@ class IcingaHostAppliedServicesTable extends SimpleQueryBasedTable /** * @return array - * @throws \Icinga\Exception\IcingaException */ protected function fetchAllApplyRules() { diff --git a/library/Director/Web/Table/IcingaHostServiceTable.php b/library/Director/Web/Table/IcingaHostServiceTable.php index 24d2b44b..dba54159 100644 --- a/library/Director/Web/Table/IcingaHostServiceTable.php +++ b/library/Director/Web/Table/IcingaHostServiceTable.php @@ -13,6 +13,7 @@ class IcingaHostServiceTable extends ZfQueryBasedTable /** @var IcingaHost */ protected $host; + /** @var IcingaHost */ protected $inheritedBy; protected $searchColumns = [ @@ -51,9 +52,15 @@ class IcingaHostServiceTable extends ZfQueryBasedTable public function renderRow($row) { + if ($row->blacklisted === 'y') { + $attributes = ['class' => 'strike-links']; + } else { + $attributes = null; + } + return $this::row([ $this->getServiceLink($row) - ]); + ], $attributes); } protected function getServiceLink($row) @@ -95,9 +102,15 @@ class IcingaHostServiceTable extends ZfQueryBasedTable ]; } + /** + * @return \Zend_Db_Select + * @throws \Zend_Db_Select_Exception + */ public function prepareQuery() { - return $this->db()->select()->from( + $db = $this->db(); + + $query = $db->select()->from( ['s' => 'icinga_service'], [ 'id' => 's.id', @@ -114,5 +127,23 @@ class IcingaHostServiceTable extends ZfQueryBasedTable 's.host_id = ?', $this->host->get('id') )->order('s.object_name'); + + if ($this->inheritedBy) { + $query->joinLeft( + ['hsb' => 'icinga_host_service_blacklist'], + $db->quoteInto( + 's.id = hsb.service_id AND hsb.host_id = ?', + $this->inheritedBy->get('id') + ), + [] + ); + $query->columns([ + 'blacklisted' => "CASE WHEN hsb.service_id IS NULL THEN 'n' ELSE 'y' END" + ]); + } else { + $query->columns(['blacklisted' => "('n')"]); + } + + return $query; } } diff --git a/library/Director/Web/Table/IcingaServiceSetServiceTable.php b/library/Director/Web/Table/IcingaServiceSetServiceTable.php index ccdf6448..5933f586 100644 --- a/library/Director/Web/Table/IcingaServiceSetServiceTable.php +++ b/library/Director/Web/Table/IcingaServiceSetServiceTable.php @@ -81,8 +81,6 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable /** * @param $row * @return Link - * @throws \Icinga\Exception\IcingaException - * @throws \Icinga\Exception\ProgrammingError */ protected function getServiceLink($row) { @@ -136,8 +134,6 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable /** * @param HtmlElement $parent - * @throws \Icinga\Exception\IcingaException - * @throws \Icinga\Exception\ProgrammingError */ protected function addHostHeaderTo(HtmlElement $parent) { @@ -180,7 +176,6 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable /** * @return \Zend_Db_Select - * @throws \Icinga\Exception\IcingaException * @throws \Zend_Db_Select_Exception */ public function prepareQuery() @@ -218,7 +213,7 @@ class IcingaServiceSetServiceTable extends ZfQueryBasedTable 'blacklisted' => "CASE WHEN hsb.service_id IS NULL THEN 'n' ELSE 'y' END", ]); } else { - $query->columns(['blacklisted' => "'n'"]); + $query->columns(['blacklisted' => "('n')"]); } return $query; diff --git a/library/vendor/ipl/Html/Link.php b/library/vendor/ipl/Html/Link.php index f2e8151d..0b24c322 100644 --- a/library/vendor/ipl/Html/Link.php +++ b/library/vendor/ipl/Html/Link.php @@ -18,8 +18,6 @@ class Link extends BaseHtmlElement * @param $url * @param null $urlParams * @param array|null $attributes - * @throws \Icinga\Exception\IcingaException - * @throws \Icinga\Exception\ProgrammingError */ public function __construct($content, $url, $urlParams = null, array $attributes = null) { @@ -36,8 +34,6 @@ class Link extends BaseHtmlElement * @param mixed $attributes * * @return static - * @throws \Icinga\Exception\IcingaException - * @throws \Icinga\Exception\ProgrammingError */ public static function create($content, $url, $urlParams = null, array $attributes = null) { @@ -48,7 +44,6 @@ class Link extends BaseHtmlElement /** * @param $url * @param $urlParams - * @throws \Icinga\Exception\ProgrammingError */ public function setUrl($url, $urlParams) { @@ -71,7 +66,6 @@ class Link extends BaseHtmlElement /** * @return Attribute - * @throws \Icinga\Exception\ProgrammingError */ public function getHrefAttribute() { diff --git a/library/vendor/ipl/Web/Table/ZfQueryBasedTable.php b/library/vendor/ipl/Web/Table/ZfQueryBasedTable.php index f0b8008c..d4b179fc 100644 --- a/library/vendor/ipl/Web/Table/ZfQueryBasedTable.php +++ b/library/vendor/ipl/Web/Table/ZfQueryBasedTable.php @@ -4,7 +4,6 @@ namespace dipl\Web\Table; use Icinga\Data\Db\DbConnection; use Icinga\Data\Filter\Filter; -use Icinga\Exception\ProgrammingError; use dipl\Db\Zf1\FilterRenderer; use dipl\Db\Zf1\SelectPaginationAdapter; use dipl\Html\DeferredText; @@ -12,6 +11,7 @@ use dipl\Html\Html; use dipl\Html\Link; use dipl\Web\Widget\ControlsAndContent; use dipl\Web\Url; +use LogicException; use Zend_Db_Adapter_Abstract as DbAdapter; abstract class ZfQueryBasedTable extends QueryBasedTable @@ -32,10 +32,10 @@ abstract class ZfQueryBasedTable extends QueryBasedTable $this->connection = $db; $this->db = $db->getDbAdapter(); } else { - throw new ProgrammingError( + throw new LogicException(sprintf( 'Unable to deal with %s db class', get_class($db) - ); + )); } } diff --git a/library/vendor/ipl/Web/Url.php b/library/vendor/ipl/Web/Url.php index c311d2ab..eb5a83fd 100644 --- a/library/vendor/ipl/Web/Url.php +++ b/library/vendor/ipl/Web/Url.php @@ -3,9 +3,9 @@ namespace dipl\Web; use Icinga\Application\Icinga; -use Icinga\Exception\ProgrammingError; use Icinga\Web\Url as WebUrl; use Icinga\Web\UrlParams; +use InvalidArgumentException; /** * Class Url @@ -26,10 +26,10 @@ class Url extends WebUrl } if (! is_string($url)) { - throw new ProgrammingError( + throw new InvalidArgumentException(sprintf( 'url "%s" is not a string', $url - ); + )); } $self = new static;