2011-09-21 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_api.php: added code to get count of event when the api
	is called for the "get_events".



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4977 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-09-21 20:43:24 +00:00
parent 2c98cf8fe0
commit 773c1f6127
2 changed files with 51 additions and 12 deletions

View File

@ -1,3 +1,8 @@
2011-09-21 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_api.php: added code to get count of event when the api
is called for the "get_events".
2011-09-21 Sergio Martin <sergio.martin@artica.es> 2011-09-21 Sergio Martin <sergio.martin@artica.es>
* operation/events/events_list.php * operation/events/events_list.php

View File

@ -121,11 +121,13 @@ function returnData($returnType, $data, $separator = ';') {
} }
} }
else { else {
foreach($data['data'] as $dataContent) { if (!empty($data['data'])) {
$clean = array_map( foreach($data['data'] as $dataContent) {
function($item) {return io_safe_output($item);}, $clean = array_map(
$dataContent); function($item) {return io_safe_output($item);},
echo implode($separator, $clean) . "\n"; $dataContent);
echo implode($separator, $clean) . "\n";
}
} }
} }
break; break;
@ -936,6 +938,23 @@ function otherParameter2Filter($other, $array = false) {
} }
} }
if (isset($other['data'][10]) && ($other['data'][10] != null)) {
if ($array) {
$filter['total'] = true;
}
else {
}
}
else {
if ($array) {
$filter['total'] = false;
}
else {
}
}
if ($array) { if ($array) {
return $filter; return $filter;
} }
@ -1503,6 +1522,7 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d
$utimestamp_bottom = 0; $utimestamp_bottom = 0;
$filter = otherParameter2Filter($other, true); $filter = otherParameter2Filter($other, true);
//html_debug_print($filter, true);
if (isset($filter['criticity'])) if (isset($filter['criticity']))
$severity = $filter['criticity']; $severity = $filter['criticity'];
@ -1599,14 +1619,24 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d
if ($group_rep == 0) { if ($group_rep == 0) {
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
$sql = "SELECT *, if ($filter['total']) {
(SELECT t1.nombre FROM tagente AS t1 WHERE t1.id_agente = tevento.id_agente) AS agent_name, $sql = "SELECT COUNT(*)
(SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name, FROM tevento
(SELECT t2.icon FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_icon WHERE 1=1 ".$sql_post;
FROM tevento }
WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$offset.",".$pagination; else {
$sql = "SELECT *,
(SELECT t1.nombre FROM tagente AS t1 WHERE t1.id_agente = tevento.id_agente) AS agent_name,
(SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name,
(SELECT t2.icon FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_icon
FROM tevento" .
//FOR THE TEST THE API IN THE ANDROID
// "WHERE 1=1 ".$sql_post." ORDER BY id_evento ASC LIMIT ".$offset.",".$pagination;
"WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$offset.",".$pagination;
}
break; break;
case "postgresql": case "postgresql":
//TODO TOTAL
$sql = "SELECT *, $sql = "SELECT *,
(SELECT t1.nombre FROM tagente AS t1 WHERE t1.id_agente = tevento.id_agente) AS agent_name, (SELECT t1.nombre FROM tagente AS t1 WHERE t1.id_agente = tevento.id_agente) AS agent_name,
(SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name, (SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name,
@ -1615,6 +1645,7 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d
WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$pagination." OFFSET ".$offset; WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$pagination." OFFSET ".$offset;
break; break;
case "oracle": case "oracle":
//TODO TOTAL
$set = array(); $set = array();
$set['limit'] = $pagination; $set['limit'] = $pagination;
$set['offset'] = $offset; $set['offset'] = $offset;
@ -1684,9 +1715,12 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d
$result = db_get_all_rows_sql ($sql); $result = db_get_all_rows_sql ($sql);
if ($result !== false) { if (($result !== false) && (!$filter['total'])) {
//Add the description and image //Add the description and image
foreach ($result as $key => $row) { foreach ($result as $key => $row) {
//FOR THE TEST THE API IN THE ANDROID
//$row['evento'] = $row['id_evento'];
$row['description_event'] = events_print_type_description($row["event_type"], true); $row['description_event'] = events_print_type_description($row["event_type"], true);
$row['img_description'] = events_print_type_img ($row["event_type"], true, true); $row['img_description'] = events_print_type_img ($row["event_type"], true, true);
$row['criticity_name'] = get_priority_name ($row["criticity"]); $row['criticity_name'] = get_priority_name ($row["criticity"]);