2013-01-11 15:32:28 +01:00
|
|
|
<?php
|
|
|
|
// Pandora FMS - http://pandorafms.com
|
|
|
|
// ==================================================
|
2020-11-27 13:52:35 +01:00
|
|
|
// Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
2013-01-11 15:32:28 +01:00
|
|
|
// Please see http://pandorafms.org for full contribution list
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation; version 2
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
/**
|
2019-01-30 16:18:44 +01:00
|
|
|
* @package Include
|
2013-01-11 15:32:28 +01:00
|
|
|
* @subpackage Component groups
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format components groups in tree way.
|
|
|
|
*
|
2019-01-30 16:18:44 +01:00
|
|
|
* @param array $groups The list of groups to create the treefield list.
|
2013-01-11 15:32:28 +01:00
|
|
|
* @param integer $parent The id_group of parent actual scan branch.
|
2019-01-30 16:18:44 +01:00
|
|
|
* @param integer $deep The level of profundity in the branch.
|
2013-01-11 15:32:28 +01:00
|
|
|
*
|
|
|
|
* @return array The treefield list of components groups.
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function component_groups_get_groups_tree_recursive($groups, $parent=0, $deep=0)
|
|
|
|
{
|
|
|
|
$return = [];
|
|
|
|
|
|
|
|
foreach ($groups as $key => $group) {
|
|
|
|
if ($group['parent'] == $parent) {
|
|
|
|
$group['deep'] = $deep;
|
|
|
|
|
|
|
|
$branch = component_groups_get_groups_tree_recursive($groups, $key, ($deep + 1));
|
|
|
|
if (empty($branch)) {
|
|
|
|
$group['hash_branch'] = false;
|
|
|
|
} else {
|
|
|
|
$group['hash_branch'] = true;
|
|
|
|
}
|
2013-01-11 15:32:28 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$return = ($return + [$key => $group] + $branch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
2013-01-11 15:32:28 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2013-01-14 15:16:06 +01:00
|
|
|
/**
|
|
|
|
* Return a array of id_group of childrens (to branches down)
|
|
|
|
*
|
|
|
|
* @param integer $parent The id_group parent to search the childrens.
|
2019-01-30 16:18:44 +01:00
|
|
|
* @param array $groups The groups, its for optimize the querys to DB.
|
2013-01-14 15:16:06 +01:00
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function component_groups_get_childrens($parent, $groups=null)
|
|
|
|
{
|
|
|
|
if (empty($groups)) {
|
|
|
|
$groups = db_get_all_rows_in_table('tnetwork_component_group');
|
|
|
|
}
|
2013-01-14 15:16:06 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$return = [];
|
2013-01-14 15:16:06 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
foreach ($groups as $key => $group) {
|
|
|
|
if ($group['id_sg'] == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-14 15:16:06 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($group['parent'] == $parent) {
|
|
|
|
$return = ($return + [$group['id_sg'] => $group] + component_groups_get_childrens($group['id_sg'], $groups));
|
|
|
|
}
|
|
|
|
}
|
2013-01-14 15:16:06 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
return $return;
|
|
|
|
}
|