Merge branch 'ent-1768-4966-Se-ven-grupos-vacios-en-el-tree-view-cuando-tienen-parent' into 'develop'

[Console Tree view] Removed empty childs

See merge request artica/pandorafms!1320
This commit is contained in:
vgilc 2018-02-28 10:34:52 +01:00
commit b9f09f0f4f
1 changed files with 26 additions and 6 deletions

View File

@ -1212,12 +1212,7 @@ class Tree {
Tree::processCounters($groups);
// Filter groups and eliminates the reference to empty groups
if ($remove_empty) {
// Filter empty groups
$groups = array_filter($groups, function ($group) {
return (isset($group['counters']) &&
isset($group['counters']['total']) &&
!empty($group['counters']['total']));
});
$groups = Tree::deleteEmptyGroups($groups);
}
usort($groups, array("Tree", "cmpSortNames"));
return $groups;
@ -1892,6 +1887,31 @@ class Tree {
}
}
/**
* @brief Recursive function to remove the empty groups
*
* @param groups All groups structure
*
* @return new_groups A new groups structure without empty groups
*/
protected static function deleteEmptyGroups ($groups) {
$new_groups = array();
foreach ($groups as $group) {
// If a group is empty, do not add to new_groups.
if (!isset($group['counters']['total']) || $group['counters']['total'] == 0) {
continue;
}
// Tray to remove the children groups
if (!empty($group['children'])) {
$children = Tree::deleteEmptyGroups ($group['children']);
if (empty($children)) unset($group['children']);
else $group['children'] = $children;
}
$new_groups[] = $group;
}
return $new_groups;
}
private static function extractGroupsWithIDs ($groups, $ids_hash) {
$result_groups = array();
foreach ($groups as $group) {