mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +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 {
|
} else {
|
||||||
$all = array();
|
$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');
|
$search = $this->getRequest()->getPost('value');
|
||||||
$begins = array();
|
$begins = array();
|
||||||
$matches = array();
|
$matches = array();
|
||||||
$begin = Filter::expression('value', '=', $search . '*');
|
$begin = Filter::expression('value', '=', $search . '*');
|
||||||
$middle = Filter::expression('value', '=', '*' . $search . '*');
|
$middle = Filter::expression('value', '=', '*' . $search . '*')->setCaseSensitive(false);
|
||||||
$prefixes = array();
|
$prefixes = array();
|
||||||
foreach ($all as $str) {
|
foreach ($all as $str) {
|
||||||
if (false !== ($pos = strrpos($str, '.'))) {
|
if (false !== ($pos = strrpos($str, '.'))) {
|
||||||
@ -45,6 +46,8 @@ class SuggestController extends ActionController
|
|||||||
} elseif ($middle->matches($row)) {
|
} elseif ($middle->matches($row)) {
|
||||||
$matches[] = $this->highlight($str, $search);
|
$matches[] = $this->highlight($str, $search);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$matches[] = $str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +85,41 @@ class SuggestController extends ActionController
|
|||||||
protected function suggestHostnames()
|
protected function suggestHostnames()
|
||||||
{
|
{
|
||||||
$db = $this->db()->getDbAdapter();
|
$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);
|
return $db->fetchCol($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +172,10 @@ class SuggestController extends ActionController
|
|||||||
{
|
{
|
||||||
$search = $this->view->escape($search);
|
$search = $this->view->escape($search);
|
||||||
$val = $this->view->escape($val);
|
$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