Clean filtered references for parent modules

This commit is contained in:
José González 2022-03-07 10:45:11 +01:00
parent d9f7ea4038
commit 89d5b490bf
2 changed files with 12 additions and 20 deletions

View File

@ -390,37 +390,29 @@ class TreeGroup extends Tree
$groups[$group['id']] = $group; $groups[$group['id']] = $group;
} }
// Build the module hierarchy // Build the module hierarchy.
foreach ($groups as $id => $group) { foreach ($groups as $id => $group) {
if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) { if (isset($groups[$id]['parent']) === true && ($groups[$id]['parent'] != 0)) {
$parent = $groups[$id]['parent']; $parent = $groups[$id]['parent'];
// Parent exists // Parent exists.
if (!isset($groups[$parent]['children'])) { if (isset($groups[$parent]['children']) === true) {
$groups[$parent]['children'] = []; $groups[$parent]['children'] = [];
} }
// Store a reference to the group into the parent // Store a reference to the group into the parent.
$groups[$parent]['children'][] = &$groups[$id]; $groups[$parent]['children'][] = &$groups[$id];
// This group was introduced into a parent // This group was introduced into a parent.
$groups[$id]['have_parent'] = true; $groups[$id]['have_parent'] = true;
} }
} }
// Sort the children groups // Sort the children groups.
foreach ($groups as $id => $group) { foreach ($groups as $id => $group) {
if (isset($groups[$id]['children'])) { if (isset($groups[$id]['children']) === true) {
usort($groups[$id]['children'], ['Tree', 'cmpSortNames']); usort($groups[$id]['children'], ['Tree', 'cmpSortNames']);
} }
} }
// Filter groups and eliminates the reference to children groups out of her parent
$groups = array_filter(
$groups,
function ($group) {
return !($group['have_parent'] ?? false);
}
);
return array_values($groups); return array_values($groups);
} }

View File

@ -323,7 +323,7 @@ html_print_image(
echo "<div id='tree-controller-recipient'>"; echo "<div id='tree-controller-recipient'>";
echo '</div>'; echo '</div>';
if (is_metaconsole()) { if (is_metaconsole() === true) {
echo '</div>'; echo '</div>';
} }
@ -331,7 +331,7 @@ enterprise_hook('close_meta_frame');
?> ?>
<?php if (!is_metaconsole()) { ?> <?php if (is_metaconsole() === false) { ?>
<script type="text/javascript" src="include/javascript/fixed-bottom-box.js"></script> <script type="text/javascript" src="include/javascript/fixed-bottom-box.js"></script>
<?php } else { ?> <?php } else { ?>
<script type="text/javascript" src="../../include/javascript/fixed-bottom-box.js"></script> <script type="text/javascript" src="../../include/javascript/fixed-bottom-box.js"></script>
@ -341,12 +341,12 @@ enterprise_hook('close_meta_frame');
var treeController = TreeController.getController(); var treeController = TreeController.getController();
processTreeSearch(); processTreeSearch();
$("form#tree_search").submit(function(e) { $("form#tree_search").submit(function(e) {
e.preventDefault(); e.preventDefault();
processTreeSearch(); processTreeSearch();
}); });
function processTreeSearch () { function processTreeSearch () {
// Clear the tree // Clear the tree
if (typeof treeController.recipient != 'undefined' && treeController.recipient.length > 0) if (typeof treeController.recipient != 'undefined' && treeController.recipient.length > 0)