Fixed tags problems with secondary groups in tree view

This commit is contained in:
fermin831 2018-10-02 13:35:48 +02:00
parent dc92a00b48
commit 2d057f9ae9
2 changed files with 18 additions and 19 deletions

View File

@ -205,26 +205,19 @@ class Tree {
return "AND ta.$field_filter > 0" . $show_init_condition; return "AND ta.$field_filter > 0" . $show_init_condition;
} }
// FIXME: Separate and condition from inner join
protected function getTagJoin () { protected function getTagJoin () {
// $parent is the agent id return 'INNER JOIN ttag_module ttm
$group_id = (int) db_get_value('id_grupo', 'tagente', 'id_agente', $this->id); ON tam.id_agente_modulo = ttm.id_agente_modulo';
$tag_join = ''; }
if (empty($group_id)) {
// ACL error, this will restrict the module search
$tag_join = 'INNER JOIN ttag_module tta
ON 1=0';
}
else if (!empty($this->acltags) && isset($this->acltags[$group_id])) {
$tags_str = $this->acltags[$group_id];
if (!empty($tags_str)) { protected function getTagCondition () {
$tag_join = sprintf('INNER JOIN ttag_module ttm $tags = tags_get_user_applied_agent_tags($this->id, "AR");
ON tam.id_agente_modulo = ttm.id_agente_modulo // All tags permision, returns no condition
AND ttm.id_tag IN (%s)', $tags_str); if ($tags === true) return "";
} // No permision, do not show anything
} if ($tags === false) return " AND 1=0";
return $tag_join; $tags_sql = implode(',', $tags);
return "AND ttm.id_tag IN ($tags_sql)";;
} }
protected function getModuleStatusFilterFromTestado ($state = false, $without_ands = false) { protected function getModuleStatusFilterFromTestado ($state = false, $without_ands = false) {
@ -900,7 +893,8 @@ class Tree {
$module_search_filter = $this->getModuleSearchFilter(); $module_search_filter = $this->getModuleSearchFilter();
$module_status_filter = $this->getModuleStatusFilterFromTestado(); $module_status_filter = $this->getModuleStatusFilterFromTestado();
$agent_filter = "AND ta.id_agente = " . $this->id; $agent_filter = "AND ta.id_agente = " . $this->id;
$tag_join = $this->getTagJoin(); $tag_condition = $this->getTagCondition();
$tag_join = empty($tag_condition) ? '' : $this->getTagJoin();
$condition = $this->L2condition; $condition = $this->L2condition;
$inner = $this->L2inner; $inner = $this->L2inner;
@ -929,6 +923,7 @@ class Tree {
$agent_status_filter $agent_status_filter
$module_status_filter $module_status_filter
$module_search_filter $module_search_filter
$tag_condition
ORDER BY tam.nombre ASC, tam.id_agente_modulo ASC"; ORDER BY tam.nombre ASC, tam.id_agente_modulo ASC";
return $sql; return $sql;
} }

View File

@ -52,6 +52,10 @@ class TreeTag extends Tree {
protected function getTagJoin () { protected function getTagJoin () {
return ''; return '';
} }
protected function getTagCondition () {
return '';
}
} }
?> ?>