IcingaServiceSet: simplify code

This commit is contained in:
Thomas Gelf 2016-10-20 07:23:49 +00:00
parent 5de24c6ec4
commit f09560a89e
1 changed files with 13 additions and 21 deletions

View File

@ -50,29 +50,21 @@ class IcingaServiceSet extends IcingaObject
*/
public function getServiceObjects()
{
if (! $this->hasBeenLoadedFromDb()) {
if ($this->host_id) {
$imports = $this->imports;
if (empty($imports)) {
return array();
}
$conn = $this->getConnection();
$db = $conn->getDbAdapter();
$base = IcingaServiceSet::load(array(
'object_name' => array_shift($imports),
'object_type' => 'template'
), $this->getConnection());
} else {
$base = $this;
}
$query = $db->select()->from(
array('s' => 'icinga_service'),
'*'
)->join(
array('sset' => 'icinga_service_set_service'),
'sset.service_id = s.id',
array()
)->where(
$db->quoteInto(
'sset.service_set_id = ?',
(int) $this->id
)
)->order('s.object_name');
// TODO: This cannot be prefetched
return IcingaService::loadAll($conn, $query, 'object_name');
return $base->getMultiRelation('service')->getObjects();
}
public function renderToConfig(IcingaConfig $config)