Added the module group tree

This commit is contained in:
Alejandro Gallardo Escobar 2015-01-02 09:45:53 +01:00
parent c1c8115409
commit 2b00ac49f9
1 changed files with 22 additions and 17 deletions

View File

@ -207,9 +207,9 @@ class Tree {
private function processModule (&$module) { private function processModule (&$module) {
$module['type'] = 'module'; $module['type'] = 'module';
$module['id'] = $module['id_agente_modulo']; $module['id'] = (int) $module['id_agente_modulo'];
$module['name'] = $module['nombre']; $module['name'] = $module['nombre'];
$module['id_module_type'] = $module['id_tipo_modulo']; $module['id_module_type'] = (int) $module['id_tipo_modulo'];
// $module['icon'] = modules_get_type_icon($module['id_tipo_modulo']); // $module['icon'] = modules_get_type_icon($module['id_tipo_modulo']);
$module['value'] = modules_get_last_value($module['id']); $module['value'] = modules_get_last_value($module['id']);
@ -353,7 +353,7 @@ class Tree {
private function processAgent (&$agent, $modulesFilter = array(), $searchChildren = true) { private function processAgent (&$agent, $modulesFilter = array(), $searchChildren = true) {
$agent['type'] = 'agent'; $agent['type'] = 'agent';
$agent['id'] = $agent['id_agente']; $agent['id'] = (int) $agent['id_agente'];
$agent['name'] = $agent['nombre']; $agent['name'] = $agent['nombre'];
// Counters // Counters
@ -512,17 +512,6 @@ class Tree {
$this->processModule($module); $this->processModule($module);
// $agent = array();
// $agent['id_agente'] = $value['id_agente'];
// $agent['nombre'] = $value['agent_name'];
// $this->processAgent(&$agent, array(), false);
// $agent['children'] = array($module);
// Module group // Module group
if ($actual_module_group_root['id'] === $module['id_module_group']) { if ($actual_module_group_root['id'] === $module['id_module_group']) {
// Agent // Agent
@ -533,7 +522,7 @@ class Tree {
// Create the new agent // Create the new agent
$actual_agent = array(); $actual_agent = array();
$actual_agent['id_agente'] = $value['id_agente']; $actual_agent['id_agente'] = (int) $value['id_agente'];
$actual_agent['nombre'] = $value['agent_name']; $actual_agent['nombre'] = $value['agent_name'];
$actual_agent['children'] = array(); $actual_agent['children'] = array();
@ -553,15 +542,28 @@ class Tree {
} }
} }
else { else {
// The first iteration don't enter here
if ($actual_module_group_root['id'] !== null) { if ($actual_module_group_root['id'] !== null) {
// Add the agent to the module group
$actual_module_group_root['children'][] = $actual_agent; $actual_module_group_root['children'][] = $actual_agent;
// Add the module group to the branch
$nodes[] = $actual_module_group_root; $nodes[] = $actual_module_group_root;
} }
// Create the new agent
$actual_agent = array();
$actual_agent['id_agente'] = (int) $value['id_agente'];
$actual_agent['nombre'] = $value['agent_name'];
$actual_agent['children'] = array();
$this->processAgent(&$actual_agent, array(), false);
// Add the module to the agent
$actual_agent['children'][] = $module;
// Create new module group // Create new module group
$actual_module_group_root = array(); $actual_module_group_root = array();
$actual_module_group_root['id'] = $module['id_module_group']; $actual_module_group_root['id'] = (int) $module['id_module_group'];
$actual_module_group_root['children'] = array($agent);
if (isset($module_groups[$module['id_module_group']])) { if (isset($module_groups[$module['id_module_group']])) {
$actual_module_group_root['name'] = $module_groups[$module['id_module_group']]; $actual_module_group_root['name'] = $module_groups[$module['id_module_group']];
@ -587,8 +589,11 @@ class Tree {
$actual_module_group_root['counters'][$agent['status']]++; $actual_module_group_root['counters'][$agent['status']]++;
} }
} }
// If there is an agent and a module group open and not saved
if ($actual_module_group_root['id'] !== null) { if ($actual_module_group_root['id'] !== null) {
// Add the last agent to the module group
$actual_module_group_root['children'][] = $actual_agent; $actual_module_group_root['children'][] = $actual_agent;
// Add the last module group to the branch
$nodes[] = $actual_module_group_root; $nodes[] = $actual_module_group_root;
} }