Improved the functionalities and prepared to be extended with another classes
This commit is contained in:
parent
ffd7eb1a23
commit
3a03a9192f
|
@ -14,15 +14,15 @@
|
||||||
// GNU General Public License for more details.
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
class Tree {
|
class Tree {
|
||||||
private $type = null;
|
protected $type = null;
|
||||||
private $tree = array();
|
protected $tree = array();
|
||||||
private $filter = array();
|
protected $filter = array();
|
||||||
private $root = null;
|
protected $root = null;
|
||||||
private $childrenMethod = "on_demand";
|
protected $childrenMethod = "on_demand";
|
||||||
private $countModuleStatusMethod = "on_demand";
|
protected $countModuleStatusMethod = "on_demand";
|
||||||
private $countAgentStatusMethod = "on_demand";
|
protected $countAgentStatusMethod = "on_demand";
|
||||||
|
|
||||||
private $userGroups;
|
protected $userGroups;
|
||||||
|
|
||||||
public function __construct($type, $root = null,
|
public function __construct($type, $root = null,
|
||||||
$childrenMethod = "on_demand",
|
$childrenMethod = "on_demand",
|
||||||
|
@ -61,10 +61,16 @@ class Tree {
|
||||||
case 'tag':
|
case 'tag':
|
||||||
$this->getDataTag();
|
$this->getDataTag();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
$this->getDataExtended();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataOS() {
|
protected function getDataExtended () {
|
||||||
|
// Override this method to add new types
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDataOS() {
|
||||||
|
|
||||||
// Get the parent
|
// Get the parent
|
||||||
if (empty($this->root))
|
if (empty($this->root))
|
||||||
|
@ -75,7 +81,7 @@ class Tree {
|
||||||
// ACL Group
|
// ACL Group
|
||||||
$group_acl = "";
|
$group_acl = "";
|
||||||
if (!empty($this->userGroups)) {
|
if (!empty($this->userGroups)) {
|
||||||
$user_groups_str = implode(",", $this->userGroups);
|
$user_groups_str = implode(",", array_keys($this->userGroups));
|
||||||
$group_acl = " AND ta.id_grupo IN ($user_groups_str) ";
|
$group_acl = " AND ta.id_grupo IN ($user_groups_str) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,10 +104,12 @@ class Tree {
|
||||||
ta.id_agente, ta.nombre AS agent_name
|
ta.id_agente, ta.nombre AS agent_name
|
||||||
FROM tagente ta, tagente_modulo tam
|
FROM tagente ta, tagente_modulo tam
|
||||||
WHERE ta.id_agente = tam.id_agente
|
WHERE ta.id_agente = tam.id_agente
|
||||||
|
AND ta.disabled = 0
|
||||||
|
AND tam.disabled = 0
|
||||||
$group_acl
|
$group_acl
|
||||||
ORDER BY ta.id_os ASC, ta.id_agente ASC";
|
ORDER BY ta.id_os ASC, ta.id_agente ASC";
|
||||||
$data = db_process_sql($sql);
|
$data = db_process_sql($sql);
|
||||||
}
|
}html_debug_print($group_acl, true);
|
||||||
|
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
$data = array();
|
$data = array();
|
||||||
|
@ -130,7 +138,7 @@ class Tree {
|
||||||
if ($actual_os_root['id'] === (int)$value['id_os']) {
|
if ($actual_os_root['id'] === (int)$value['id_os']) {
|
||||||
// Agent
|
// Agent
|
||||||
if (empty($actual_agent) || $actual_agent['id'] !== (int)$value['id_agente']) {
|
if (empty($actual_agent) || $actual_agent['id'] !== (int)$value['id_agente']) {
|
||||||
// Add the last agent to the agent module
|
// Add the last agent to the os item
|
||||||
if (!empty($actual_agent))
|
if (!empty($actual_agent))
|
||||||
$actual_os_root['children'][] = $actual_agent;
|
$actual_os_root['children'][] = $actual_agent;
|
||||||
|
|
||||||
|
@ -157,9 +165,9 @@ class Tree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// The first iteration don't enter here
|
// The first iteration doesn't enter here
|
||||||
if ($actual_os_root['id'] !== null) {
|
if ($actual_os_root['id'] !== null) {
|
||||||
// Add the agent to the module group
|
// Add the agent to the os item
|
||||||
$actual_os_root['children'][] = $actual_agent;
|
$actual_os_root['children'][] = $actual_agent;
|
||||||
// Add the os the branch
|
// Add the os the branch
|
||||||
$nodes[] = $actual_os_root;
|
$nodes[] = $actual_os_root;
|
||||||
|
@ -227,7 +235,7 @@ class Tree {
|
||||||
}
|
}
|
||||||
// ACL groups
|
// ACL groups
|
||||||
if (!empty($this->userGroups))
|
if (!empty($this->userGroups))
|
||||||
$filter['id_grupo'] = $this->userGroups;
|
$filter['id_grupo'] = array_keys($this->userGroups);
|
||||||
|
|
||||||
// First filter by name and father
|
// First filter by name and father
|
||||||
$groups = db_get_all_rows_filter('tgrupo', $filter, array('id_grupo', 'nombre'));
|
$groups = db_get_all_rows_filter('tgrupo', $filter, array('id_grupo', 'nombre'));
|
||||||
|
@ -338,7 +346,7 @@ class Tree {
|
||||||
return $groups;
|
return $groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataGroup() {
|
private function getDataGroup() {
|
||||||
// Get the parent
|
// Get the parent
|
||||||
if (empty($this->root))
|
if (empty($this->root))
|
||||||
$parent = 0;
|
$parent = 0;
|
||||||
|
@ -395,7 +403,7 @@ class Tree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getModules ($parent = 0, $filter = array()) {
|
private function getModules ($parent = 0, $filter = array()) {
|
||||||
$modules = array();
|
$modules = array();
|
||||||
|
|
||||||
$modules_aux = agents_get_modules($parent,
|
$modules_aux = agents_get_modules($parent,
|
||||||
|
@ -410,7 +418,7 @@ class Tree {
|
||||||
return $modules;
|
return $modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataModules() {
|
private function getDataModules() {
|
||||||
// Get the parent
|
// Get the parent
|
||||||
if (empty($this->root))
|
if (empty($this->root))
|
||||||
$parent = 0;
|
$parent = 0;
|
||||||
|
@ -420,7 +428,7 @@ class Tree {
|
||||||
// ACL Group
|
// ACL Group
|
||||||
$group_acl = "";
|
$group_acl = "";
|
||||||
if (!empty($this->userGroups)) {
|
if (!empty($this->userGroups)) {
|
||||||
$user_groups_str = implode(",", $this->userGroups);
|
$user_groups_str = implode(",", array_keys($this->userGroups));
|
||||||
$group_acl = " AND ta.id_grupo IN ($user_groups_str) ";
|
$group_acl = " AND ta.id_grupo IN ($user_groups_str) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,6 +436,8 @@ class Tree {
|
||||||
ta.id_agente, ta.nombre AS agent_name
|
ta.id_agente, ta.nombre AS agent_name
|
||||||
FROM tagente ta, tagente_modulo tam
|
FROM tagente ta, tagente_modulo tam
|
||||||
WHERE ta.id_agente = tam.id_agente
|
WHERE ta.id_agente = tam.id_agente
|
||||||
|
AND ta.disabled = 0
|
||||||
|
AND tam.disabled = 0
|
||||||
$group_acl
|
$group_acl
|
||||||
ORDER BY tam.nombre";
|
ORDER BY tam.nombre";
|
||||||
$data = db_process_sql($sql);
|
$data = db_process_sql($sql);
|
||||||
|
@ -578,7 +588,7 @@ class Tree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAgents ($parent = 0, $parentType = '') {
|
private function getAgents ($parent = 0, $parentType = '') {
|
||||||
switch ($parentType) {
|
switch ($parentType) {
|
||||||
case 'group':
|
case 'group':
|
||||||
// ACL Groups
|
// ACL Groups
|
||||||
|
@ -606,11 +616,7 @@ class Tree {
|
||||||
return $agents;
|
return $agents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataAgents($type, $id) {
|
private function getDataModuleGroup() {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDataModuleGroup() {
|
|
||||||
// Get the parent
|
// Get the parent
|
||||||
if (empty($this->root))
|
if (empty($this->root))
|
||||||
$parent = 0;
|
$parent = 0;
|
||||||
|
@ -620,7 +626,7 @@ class Tree {
|
||||||
// ACL Group
|
// ACL Group
|
||||||
$group_acl = "";
|
$group_acl = "";
|
||||||
if (!empty($this->userGroups)) {
|
if (!empty($this->userGroups)) {
|
||||||
$user_groups_str = implode(",", $this->userGroups);
|
$user_groups_str = implode(",", array_keys($this->userGroups));
|
||||||
$group_acl = " AND ta.id_grupo IN ($user_groups_str) ";
|
$group_acl = " AND ta.id_grupo IN ($user_groups_str) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -632,6 +638,8 @@ class Tree {
|
||||||
ta.id_agente, ta.nombre AS agent_name
|
ta.id_agente, ta.nombre AS agent_name
|
||||||
FROM tagente ta, tagente_modulo tam
|
FROM tagente ta, tagente_modulo tam
|
||||||
WHERE ta.id_agente = tam.id_agente
|
WHERE ta.id_agente = tam.id_agente
|
||||||
|
AND ta.disabled = 0
|
||||||
|
AND tam.disabled = 0
|
||||||
$group_acl
|
$group_acl
|
||||||
ORDER BY tam.id_module_group ASC, ta.id_agente ASC";
|
ORDER BY tam.id_module_group ASC, ta.id_agente ASC";
|
||||||
$data = db_process_sql($sql);
|
$data = db_process_sql($sql);
|
||||||
|
@ -690,7 +698,7 @@ class Tree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// The first iteration don't enter here
|
// The first iteration doesn't enter here
|
||||||
if ($actual_module_group_root['id'] !== null) {
|
if ($actual_module_group_root['id'] !== null) {
|
||||||
// Add the agent to the module group
|
// Add the agent to the module group
|
||||||
$actual_module_group_root['children'][] = $actual_agent;
|
$actual_module_group_root['children'][] = $actual_agent;
|
||||||
|
@ -749,7 +757,7 @@ class Tree {
|
||||||
$this->tree = $nodes;
|
$this->tree = $nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataTag() {
|
private function getDataTag() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getJSON() {
|
public function getJSON() {
|
||||||
|
|
Loading…
Reference in New Issue