SuggestController: reduce duplicate code
This commit is contained in:
parent
0c2cb9e484
commit
d6a3d0e229
|
@ -79,6 +79,8 @@ class SuggestController extends ActionController
|
||||||
* TODO: Should not remain here
|
* TODO: Should not remain here
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws \Icinga\Exception\ConfigurationError
|
||||||
|
* @throws \Icinga\Security\SecurityException
|
||||||
*/
|
*/
|
||||||
protected function suggestLocations()
|
protected function suggestLocations()
|
||||||
{
|
{
|
||||||
|
@ -152,39 +154,22 @@ class SuggestController extends ActionController
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function suggestHosttemplates()
|
protected function suggestHosttemplates()
|
||||||
{
|
{
|
||||||
$this->assertPermission('director/hosts');
|
$this->assertPermission('director/hosts');
|
||||||
$db = $this->db()->getDbAdapter();
|
return $this->fetchTemplateNames('icinga_host', 'template_choice_id IS NULL');
|
||||||
$query = $db->select()
|
|
||||||
->from('icinga_host', 'object_name')
|
|
||||||
->order('object_name')
|
|
||||||
->where("object_type = 'template'")
|
|
||||||
->where('template_choice_id IS NULL');
|
|
||||||
return $db->fetchCol($query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function suggestServicetemplates()
|
protected function suggestServicetemplates()
|
||||||
{
|
{
|
||||||
$this->assertPermission('director/services');
|
$this->assertPermission('director/services');
|
||||||
$db = $this->db()->getDbAdapter();
|
return $this->fetchTemplateNames('icinga_service', 'template_choice_id IS NULL');
|
||||||
$query = $db->select()
|
|
||||||
->from('icinga_service', 'object_name')
|
|
||||||
->order('object_name')
|
|
||||||
->where("object_type = 'template'");
|
|
||||||
return $db->fetchCol($query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function suggestNotificationtemplates()
|
protected function suggestNotificationtemplates()
|
||||||
{
|
{
|
||||||
$this->assertPermission('director/notifications');
|
$this->assertPermission('director/notifications');
|
||||||
$db = $this->db()->getDbAdapter();
|
return $this->fetchTemplateNames('icinga_notification');
|
||||||
$query = $db->select()
|
|
||||||
->from('icinga_notification', 'object_name')
|
|
||||||
->order('object_name')
|
|
||||||
->where("object_type = 'template'");
|
|
||||||
return $db->fetchCol($query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function suggestCommandtemplates()
|
protected function suggestCommandtemplates()
|
||||||
|
@ -200,12 +185,7 @@ class SuggestController extends ActionController
|
||||||
protected function suggestUsertemplates()
|
protected function suggestUsertemplates()
|
||||||
{
|
{
|
||||||
$this->assertPermission('director/users');
|
$this->assertPermission('director/users');
|
||||||
$db = $this->db()->getDbAdapter();
|
return $this->fetchTemplateNames('icinga_user');
|
||||||
$query = $db->select()
|
|
||||||
->from('icinga_user', 'object_name')
|
|
||||||
->order('object_name')
|
|
||||||
->where("object_type = 'template'");
|
|
||||||
return $db->fetchCol($query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function suggestCheckcommandnames()
|
protected function suggestCheckcommandnames()
|
||||||
|
@ -219,6 +199,21 @@ class SuggestController extends ActionController
|
||||||
return $db->fetchCol($query);
|
return $db->fetchCol($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function fetchTemplateNames($table, $where)
|
||||||
|
{
|
||||||
|
$db = $this->db()->getDbAdapter();
|
||||||
|
$query = $db->select()
|
||||||
|
->from($table, 'object_name')
|
||||||
|
->where('object_type = ?', 'template')
|
||||||
|
->order('object_name');
|
||||||
|
|
||||||
|
if ($where !== null) {
|
||||||
|
$query->where('template_choice_id IS NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $db->fetchCol($query);
|
||||||
|
}
|
||||||
|
|
||||||
protected function suggestHostgroupnames()
|
protected function suggestHostgroupnames()
|
||||||
{
|
{
|
||||||
$db = $this->db()->getDbAdapter();
|
$db = $this->db()->getDbAdapter();
|
||||||
|
@ -322,12 +317,7 @@ class SuggestController extends ActionController
|
||||||
protected function suggestDependencytemplates()
|
protected function suggestDependencytemplates()
|
||||||
{
|
{
|
||||||
$this->assertPermission('director/hosts');
|
$this->assertPermission('director/hosts');
|
||||||
$db = $this->db()->getDbAdapter();
|
return $this->fetchTemplateNames('icinga_dependency');
|
||||||
$query = $db->select()
|
|
||||||
->from('icinga_dependency', 'object_name')
|
|
||||||
->order('object_name')
|
|
||||||
->where("object_type = 'template'");
|
|
||||||
return $db->fetchCol($query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function highlight($val, $search)
|
protected function highlight($val, $search)
|
||||||
|
|
Loading…
Reference in New Issue