Merge branch 'ent-9420-eventos-agrupados-no-muestran-estado-del-ultimo-elemento' into 'develop'

fixed group by order event_get_all pandora_enterprise#9420

See merge request artica/pandorafms!5106
This commit is contained in:
Diego Muñoz-Reja 2022-09-26 15:16:15 +00:00
commit 10d97c8cfa
1 changed files with 109 additions and 36 deletions

View File

@ -1494,6 +1494,15 @@ function events_get_all(
MAX(id_evento) as max_id_evento', MAX(id_evento) as max_id_evento',
($idx !== false) ? 'GROUP_CONCAT(DISTINCT user_comment SEPARATOR "<br>") AS comments,' : '' ($idx !== false) ? 'GROUP_CONCAT(DISTINCT user_comment SEPARATOR "<br>") AS comments,' : ''
); );
$group_selects_trans = sprintf(
',tmax_event.event_rep,
%s
tmax_event.timestamp_last,
tmax_event.timestamp_first,
tmax_event.max_id_evento',
($idx !== false) ? 'tmax_event.comments,' : ''
);
} }
} else { } else {
$idx = array_search('te.user_comment', $fields); $idx = array_search('te.user_comment', $fields);
@ -1502,43 +1511,107 @@ function events_get_all(
} }
} }
$sql = sprintf( if ((int) $filter['group_rep'] === 1 && $count === false) {
'SELECT %s $sql = sprintf(
'SELECT %s
%s
FROM %s
INNER JOIN (
SELECT te.id_evento %s
FROM %s
%s
%s
%s JOIN %s ta
ON ta.%s = te.id_agente
%s
%s
%s JOIN tgrupo tg
ON %s
WHERE 1=1
%s
%s
%s
%s
%s
) tmax_event
ON te.id_evento = tmax_event.max_id_evento
%s %s
FROM %s %s
%s %s JOIN %s ta
%s ON ta.%s = te.id_agente
%s JOIN %s ta %s
ON ta.%s = te.id_agente %s
%s %s JOIN tgrupo tg
%s ON %s',
%s JOIN tgrupo tg join(',', $fields),
ON %s $group_selects_trans,
WHERE 1=1 $tevento,
%s $group_selects,
%s $tevento,
%s $event_lj,
%s $agentmodule_join,
%s $tagente_join,
', $tagente_table,
join(',', $fields), $tagente_field,
$group_selects, $conditionMetaconsole,
$tevento, join(' ', $agent_join_filters),
$event_lj, $tgrupo_join,
$agentmodule_join, join(' ', $tgrupo_join_filters),
$tagente_join, join(' ', $sql_filters),
$tagente_table, $group_by,
$tagente_field, $order_by,
$conditionMetaconsole, $pagination,
join(' ', $agent_join_filters), $having,
$tgrupo_join, $event_lj,
join(' ', $tgrupo_join_filters), $agentmodule_join,
join(' ', $sql_filters), $tagente_join,
$group_by, $tagente_table,
$order_by, $tagente_field,
$pagination, $conditionMetaconsole,
$having join(' ', $agent_join_filters),
); $tgrupo_join,
join(' ', $tgrupo_join_filters),
join(' ', $sql_filters)
);
} else {
$sql = sprintf(
'SELECT %s
%s
FROM %s
%s
%s
%s JOIN %s ta
ON ta.%s = te.id_agente
%s
%s
%s JOIN tgrupo tg
ON %s
WHERE 1=1
%s
%s
%s
%s
%s
',
join(',', $fields),
$group_selects,
$tevento,
$event_lj,
$agentmodule_join,
$tagente_join,
$tagente_table,
$tagente_field,
$conditionMetaconsole,
join(' ', $agent_join_filters),
$tgrupo_join,
join(' ', $tgrupo_join_filters),
join(' ', $sql_filters),
$group_by,
$order_by,
$pagination,
$having
);
}
if ($return_sql === true) { if ($return_sql === true) {
return $sql; return $sql;