Merge branch 'buscar-un-grupo-en-el-tree-view-carrefour' into 'develop'
Mostrar los descendientes de los grupos filtrados en el tree view See merge request artica/pandorafms!1159
This commit is contained in:
commit
18fa3d29a9
|
@ -57,31 +57,6 @@ class Tree {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setFilter($filter) {
|
public function setFilter($filter) {
|
||||||
// Filter the user groups
|
|
||||||
if (!empty($filter['groupID'])) {
|
|
||||||
$group_id = $filter['groupID'];
|
|
||||||
$this->userGroups = isset($this->userGroupsACL[$group_id])
|
|
||||||
? array($group_id => $this->userGroupsACL[$group_id])
|
|
||||||
: array();
|
|
||||||
}
|
|
||||||
else if (!empty($filter['searchGroup'])) {
|
|
||||||
$groups = db_get_all_rows_filter('tgrupo', array('nombre' => '%' . $filter['searchGroup'] . '%'));
|
|
||||||
|
|
||||||
// Save the groups which intersect
|
|
||||||
$userGroupsACL = $this->userGroupsACL;
|
|
||||||
$this->userGroups = array_reduce($groups, function ($userGroups, $group) use ($userGroupsACL) {
|
|
||||||
$group_id = $group['id_grupo'];
|
|
||||||
if (isset($userGroupsACL[$group_id])) {
|
|
||||||
$userGroups[$group_id] = $userGroupsACL[$group_id];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $userGroups;
|
|
||||||
}, array());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$this->userGroups = $this->userGroupsACL;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->filter = $filter;
|
$this->filter = $filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1877,6 +1852,25 @@ class Tree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function extractGroupsWithIDs ($groups, $ids_hash) {
|
||||||
|
$result_groups = array();
|
||||||
|
foreach ($groups as $group) {
|
||||||
|
if (isset($ids_hash[$group['id']])) {
|
||||||
|
$result_groups[] = $group;
|
||||||
|
}
|
||||||
|
else if (!empty($group['children'])) {
|
||||||
|
$result = self::extractGroupsWithIDs($group['children'], $ids_hash);
|
||||||
|
|
||||||
|
// Item found on children
|
||||||
|
if (!empty($result)) {
|
||||||
|
$result_groups = array_merge($result_groups, $result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result_groups;
|
||||||
|
}
|
||||||
|
|
||||||
private static function extractItemWithID ($items, $item_id, $item_type = "group", $strictACL = false) {
|
private static function extractItemWithID ($items, $item_id, $item_type = "group", $strictACL = false) {
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
if ($item["type"] != $item_type)
|
if ($item["type"] != $item_type)
|
||||||
|
@ -2166,14 +2160,33 @@ class Tree {
|
||||||
|
|
||||||
$processed_items = $this->getProcessedGroups($items, true);
|
$processed_items = $this->getProcessedGroups($items, true);
|
||||||
|
|
||||||
|
if (!empty($processed_items)) {
|
||||||
|
// Filter by group name. This should be done after rerieving the items cause we need the possible items descendants
|
||||||
|
if (!empty($this->filter['searchGroup'])) {
|
||||||
|
// Save the groups which intersect with the user groups
|
||||||
|
$groups = db_get_all_rows_filter('tgrupo', array('nombre' => '%' . $this->filter['searchGroup'] . '%'));
|
||||||
|
if ($groups == false) $groups = array();
|
||||||
|
$userGroupsACL = $this->userGroupsACL;
|
||||||
|
$ids_hash = array_reduce($groups, function ($userGroups, $group) use ($userGroupsACL) {
|
||||||
|
$group_id = $group['id_grupo'];
|
||||||
|
if (isset($userGroupsACL[$group_id])) {
|
||||||
|
$userGroups[$group_id] = $userGroupsACL[$group_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $userGroups;
|
||||||
|
}, array());
|
||||||
|
|
||||||
|
$result = self::extractGroupsWithIDs($processed_items, $ids_hash);
|
||||||
|
|
||||||
|
$processed_items = ($result === false) ? array() : $result;
|
||||||
|
}
|
||||||
|
|
||||||
// groupID filter. To access the view from tactical views f.e.
|
// groupID filter. To access the view from tactical views f.e.
|
||||||
if (!empty($processed_items) && !empty($this->filter['groupID'])) {
|
if (!empty($this->filter['groupID'])) {
|
||||||
$result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group", $this->strictACL);
|
$result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group", $this->strictACL);
|
||||||
|
|
||||||
if ($result === false)
|
$processed_items = ($result === false) ? array() : array($result);
|
||||||
$processed_items = array();
|
}
|
||||||
else
|
|
||||||
$processed_items = array($result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Agents
|
// Agents
|
||||||
|
|
|
@ -135,11 +135,13 @@ $agent_status_arr[AGENT_STATUS_CRITICAL] = __('Critical');
|
||||||
$agent_status_arr[AGENT_STATUS_UNKNOWN] = __('Unknown');
|
$agent_status_arr[AGENT_STATUS_UNKNOWN] = __('Unknown');
|
||||||
$agent_status_arr[AGENT_STATUS_NOT_INIT] = __('Not init');
|
$agent_status_arr[AGENT_STATUS_NOT_INIT] = __('Not init');
|
||||||
|
|
||||||
|
if ($tab == 'group' || is_metaconsole()) {
|
||||||
$row = array();
|
$row = array();
|
||||||
$row[] = __('Search group');
|
$row[] = __('Search group');
|
||||||
$row[] = html_print_input_text("search_group", $search_group, '', is_metaconsole() ? 70 : 40, 30, true);
|
$row[] = html_print_input_text("search_group", $search_group, '', is_metaconsole() ? 70 : 40, 30, true);
|
||||||
|
|
||||||
$table->data[] = $row;
|
$table->data[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
$row = array();
|
$row = array();
|
||||||
$row[] = __('Search agent');
|
$row[] = __('Search agent');
|
||||||
|
|
Loading…
Reference in New Issue