IcingaHostForm: Move getAppliedGroups to IcingaObject

This commit is contained in:
Markus Frosch 2018-04-26 11:22:18 +02:00
parent cceb588d24
commit 26e58834f6
2 changed files with 29 additions and 18 deletions

View File

@ -283,24 +283,7 @@ class IcingaHostForm extends DirectorObjectForm
return [];
}
$db = $this->getDb()->getDbAdapter();
$query = $db->select()->from(
['hghr' => 'icinga_hostgroup_host_resolved'],
['hg.object_name']
)->join(
['hg' => 'icinga_hostgroup'],
'hg.id = hghr.hostgroup_id',
[]
)->joinLeft(
['hgh' => 'icinga_hostgroup_host'],
'hgh.hostgroup_id = hghr.hostgroup_id',
[]
)->where(
'hghr.host_id = ?',
$this->object()->get('id')
)->where('hgh.host_id IS NULL')->order('hg.object_name');
return $db->fetchCol($query);
return $this->object()->getAppliedGroups();
}
protected function hasHostGroupRestriction()

View File

@ -853,6 +853,34 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this->groups->hasBeenModified();
}
public function getAppliedGroups()
{
$this->assertGroupsSupport();
if (! $this instanceof IcingaHost) {
throw new ProgrammingError('getAppliedGroups is only available for hosts currently!');
}
$type = strtolower($this->type);
$query = $this->db->select()->from(
['gr' => "icinga_${type}group_${type}_resolved"],
['g.object_name']
)->join(
['g' => "icinga_${type}group"],
"g.id = gr.${type}group_id",
[]
)->joinLeft(
['go' => "icinga_${type}group_${type}"],
"go.${type}group_id = gr.${type}group_id",
[]
)->where(
"gr.${type}_id = ?",
$this->id
)->where("go.${type}_id IS NULL")->order('g.object_name');
return $this->db->fetchCol($query);
}
/**
* @return IcingaTimePeriodRanges
*/