diff options
Diffstat (limited to 'library/Director/Db/AppliedServiceSetLoader.php')
-rw-r--r-- | library/Director/Db/AppliedServiceSetLoader.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/library/Director/Db/AppliedServiceSetLoader.php b/library/Director/Db/AppliedServiceSetLoader.php new file mode 100644 index 0000000..b1e9408 --- /dev/null +++ b/library/Director/Db/AppliedServiceSetLoader.php @@ -0,0 +1,58 @@ +<?php + +namespace Icinga\Module\Director\Db; + +use Icinga\Data\Filter\Filter; +use Icinga\Module\Director\Objects\HostApplyMatches; +use Icinga\Module\Director\Objects\IcingaHost; +use Icinga\Module\Director\Objects\IcingaServiceSet; + +class AppliedServiceSetLoader +{ + protected $host; + + public function __construct(IcingaHost $host) + { + $this->host = $host; + } + + /** + * @return IcingaServiceSet[] + */ + public static function fetchForHost(IcingaHost $host) + { + $loader = new static($host); + return $loader->fetchAppliedServiceSets(); + } + + /** + * @return IcingaServiceSet[] + */ + protected function fetchAppliedServiceSets() + { + $sets = array(); + $matcher = HostApplyMatches::prepare($this->host); + foreach ($this->fetchAllServiceSets() as $set) { + $filter = Filter::fromQueryString($set->get('assign_filter')); + if ($matcher->matchesFilter($filter)) { + $sets[] = $set; + } + } + + return $sets; + } + + /** + * @return IcingaServiceSet[] + */ + protected function fetchAllServiceSets() + { + $db = $this->host->getDb(); + $query = $db + ->select() + ->from('icinga_service_set') + ->where('assign_filter IS NOT NULL'); + + return IcingaServiceSet::loadAll($this->host->getConnection(), $query); + } +} |