mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 17:24:18 +02:00
SuggestController: a few more suggestions
This commit is contained in:
parent
73a2060b42
commit
3759a4e48d
@ -26,12 +26,13 @@ class SuggestController extends ActionController
|
||||
} else {
|
||||
$all = array();
|
||||
}
|
||||
|
||||
// TODO: also get cursor position and eventually add an asterisk in the middle
|
||||
// tODO: filter also when fetching, eventually limit somehow
|
||||
$search = $this->getRequest()->getPost('value');
|
||||
$begins = array();
|
||||
$matches = array();
|
||||
$begin = Filter::expression('value', '=', $search . '*');
|
||||
$middle = Filter::expression('value', '=', '*' . $search . '*');
|
||||
$middle = Filter::expression('value', '=', '*' . $search . '*')->setCaseSensitive(false);
|
||||
$prefixes = array();
|
||||
foreach ($all as $str) {
|
||||
if (false !== ($pos = strrpos($str, '.'))) {
|
||||
@ -45,6 +46,8 @@ class SuggestController extends ActionController
|
||||
} elseif ($middle->matches($row)) {
|
||||
$matches[] = $this->highlight($str, $search);
|
||||
}
|
||||
} else {
|
||||
$matches[] = $str;
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,7 +85,41 @@ class SuggestController extends ActionController
|
||||
protected function suggestHostnames()
|
||||
{
|
||||
$db = $this->db()->getDbAdapter();
|
||||
$query = $db->select()->from('icinga_host', 'object_name')->order('object_name');
|
||||
$query = $db->select()
|
||||
->from('icinga_host', 'object_name')
|
||||
->order('object_name')
|
||||
->where("object_type = 'object'");
|
||||
return $db->fetchCol($query);
|
||||
}
|
||||
|
||||
protected function suggestHosttemplates()
|
||||
{
|
||||
$db = $this->db()->getDbAdapter();
|
||||
$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()
|
||||
{
|
||||
$db = $this->db()->getDbAdapter();
|
||||
$query = $db->select()
|
||||
->from('icinga_service', 'object_name')
|
||||
->order('object_name')
|
||||
->where("object_type = 'template'");
|
||||
return $db->fetchCol($query);
|
||||
}
|
||||
|
||||
protected function suggestCommandtemplates()
|
||||
{
|
||||
$db = $this->db()->getDbAdapter();
|
||||
$query = $db->select()
|
||||
->from('icinga_command', 'object_name')
|
||||
->order('object_name')
|
||||
->where("object_type = 'template'");
|
||||
return $db->fetchCol($query);
|
||||
}
|
||||
|
||||
@ -135,6 +172,10 @@ class SuggestController extends ActionController
|
||||
{
|
||||
$search = $this->view->escape($search);
|
||||
$val = $this->view->escape($val);
|
||||
return str_replace($search, '<strong>' . $search . '</strong>', $val);
|
||||
return preg_replace(
|
||||
'/(' . preg_quote($search, '/') . ')/i',
|
||||
'<strong>\1</strong>',
|
||||
$val
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user