Feature. new form of groped data in event list. Tiquet: #3079

(cherry picked from commit 9f772e5091)
This commit is contained in:
m-lopez-f 2016-05-23 09:22:57 +02:00
parent f0c36f2c52
commit 0f175eab72
3 changed files with 834 additions and 627 deletions

View File

@ -2951,4 +2951,70 @@ function events_checks_event_tags($event_data, $acltags) {
}
return false;
}
function events_get_events_grouped_by_agent($sql_post, $offset = 0,
$pagination = 1, $meta = false, $history = false, $total = false) {
global $config;
$table = events_get_events_table($meta, $history);
if ($meta) {
$groupby_extra = ', server_id';
}
else {
$groupby_extra = '';
}
switch ($config["dbtype"]) {
case "mysql":
if ($total) {
$sql = "SELECT COUNT(*) FROM (select id_agente,
event_type, count(*) as total from $table WHERE 1=1
$sql_post GROUP BY id_agente, event_type$groupby_extra ORDER BY id_agente ) AS t";
}
else {
$sql = "select id_agente, event_type, count(*) as total, id_grupo from $table
WHERE id_agente > 0 $sql_post GROUP BY id_agente, event_type$groupby_extra ORDER BY id_agente LIMIT $offset,$pagination";
}
break;
case 'postgresql':
if ($total) {
}
else {
$sql = "select id_agente, event_type, count(*), id_grupo as total from $table
WHERE id_agente > 0 $sql_post GROUP BY id_agente, event_type$groupby_extra ORDER BY id_agente LIMIT $offset,$pagination";
}
break;
case 'oracle':
if ($total) {
}
else {
$set = array();
$set['limit'] = $pagination;
$set['offset'] = $offset;
$sql = "select id_agente, event_type, count(*), id_grupo as total from $table
WHERE id_agente > 0 $sql_post GROUP BY id_agente, event_type$groupby_extra ORDER BY id_agente ";
$sql = oracle_recode_query ($sql, $set);
}
break;
}
$result = array();
//Extract the events by filter (or not) from db
$events = db_get_all_rows_sql ($sql);
$result = array();
if ($events) {
foreach ($events as $event) {
$id_agente = $event['id_agente'];
$result[$id_agente][$event['event_type']] = $event['total'];
$result[$id_agente]['id_grupo'] = $event['id_grupo'];
}
}
return $result;
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -560,6 +560,7 @@ $data[1] .= html_print_input_text ('event_view_hr', $event_view_hr, '', 5, 255,
$data[2] = __("Repeated") . $jump;
$repeated_sel[0] = __("All events");
$repeated_sel[1] = __("Group events");
$repeated_sel[2] = __("Group agents");
$data[2] .= html_print_select ($repeated_sel, "group_rep", $group_rep, '', '', 0, true);
$table->data[] = $data;
$table->rowclass[] = '';
@ -680,7 +681,7 @@ if ($group_rep == 0) {
//Extract the events by filter (or not) from db
$result = db_get_all_rows_sql ($sql);
}
else {
elseif ($group_rep == 1) {
$result = events_get_events_grouped(
$sql_post,
$offset,
@ -688,6 +689,14 @@ else {
$meta,
$history);
}
elseif ($group_rep == 2) {
$result = events_get_events_grouped_by_agent(
$sql_post,
$offset,
$pagination,
$meta,
$history);
}
if (!empty($result)) {
if ($group_rep == 0) {
@ -695,7 +704,7 @@ if (!empty($result)) {
FROM $event_table
WHERE 1=1 " . $sql_post;
}
else {
elseif ($group_rep == 1) {
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
@ -713,6 +722,10 @@ if (!empty($result)) {
GROUP BY to_char(evento), id_agentmodule) t";
break;
}
}
elseif ($group_rep == 2) {
}
$limit = (int) db_get_sql ($sql);
@ -745,20 +758,26 @@ if (!empty($result)) {
//Extract the events by filter (or not) from db
$results_graph = db_get_all_rows_sql ($sql);
}
else {
elseif ($group_rep == 1) {
$results_graph = events_get_events_grouped($sql_post,
0,
$limit,
$meta,
$history);
}
$graph = '<div style="width: 350px; margin: 0 auto;">' .
grafico_eventos_agente(350, 185,
$results_graph, $meta, $history, $tags_acls_condition,$limit) .
'</div>';
html_print_div(array('id' => 'events_graph',
'hidden' => true, 'content' => $graph));
elseif ($group_rep == 2) {
}
if (($group_rep == 1) OR ($group_rep == 0)) {
$graph = '<div style="width: 350px; margin: 0 auto;">' .
grafico_eventos_agente(350, 185,
$results_graph, $meta, $history, $tags_acls_condition,$limit) .
'</div>';
html_print_div(array('id' => 'events_graph',
'hidden' => true, 'content' => $graph));
}
}
@ -789,7 +808,7 @@ if ($group_rep == 0) {
FROM $event_table
WHERE 1=1 $sql_post";
}
else {
elseif ($group_rep == 1) {
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
@ -808,9 +827,13 @@ else {
break;
}
}
elseif ($group_rep == 2) {
$sql = "SELECT COUNT(*) FROM (select id_agente as total from $event_table WHERE id_agente > 0
$sql_post GROUP BY id_agente ORDER BY id_agente ) AS t";
}
$total_events = (int) db_get_sql ($sql);
if (empty ($result)) {
$result = array ();
}