Added date filter - #4642

This commit is contained in:
Tatiana Llorente 2019-09-18 18:19:29 +02:00
parent eb271a93eb
commit 8acdde9f3a
2 changed files with 66 additions and 9 deletions

View File

@ -5618,7 +5618,8 @@ function get_tickets_integriaims($tickets_filters)
$incident_creator = $tickets_filters['incident_creator'];
$incident_priority = $tickets_filters['incident_priority'];
$incident_resolution = $tickets_filters['incident_resolution'];
$incident_date = $tickets_filters['incident_date'];
$created_from = $tickets_filters['created_from'];
$created_to = $tickets_filters['created_to'];
// API call.
$result_api_call_list = integria_api_call(
@ -5655,5 +5656,46 @@ function get_tickets_integriaims($tickets_filters)
$array_get_incidents = $filter_resolution;
}
// Modify $array_get_incidents if filter for date is selected.
if ($created_from !== '' && $created_to !== '') {
$date = [];
$date_utimestamp = [];
foreach ($array_get_incidents as $key => $value) {
// Change format date / to -.
$date[$key] = date('Y-m-d', strtotime($array_get_incidents[$key][9]));
// Covert date to utimestamp.
$date_utimestamp[$key] = strtotime($date[$key]);
}
// Change format date / to -.
$created_from_date = date('Y-m-d', strtotime($created_from));
$created_to_date = date('Y-m-d', strtotime($created_to));
// Covert date to utimestamp.
$created_from_timestamp = strtotime($created_from_date);
$created_to_timestamp = strtotime($created_to_date);
// Dates within the selected period.
$selected_period = array_filter(
$date_utimestamp,
function ($value) use ($created_from_timestamp, $created_to_timestamp) {
return ($value >= $created_from_timestamp && $value <= $created_to_timestamp);
}
);
// Return incidents with the correct dates.
$filter_date = [];
foreach ($array_get_incidents as $key => $value) {
foreach ($selected_period as $index => $value) {
if ($array_get_incidents[$key][0] == $index) {
$filter_date[$key] = $array_get_incidents[$key];
continue;
}
}
}
$array_get_incidents = $filter_date;
}
return $array_get_incidents;
}

View File

@ -47,7 +47,8 @@ $incident_owner = (string) get_parameter('incident_owner', '');
$incident_creator = (string) get_parameter('incident_creator', '');
$incident_priority = (int) get_parameter('incident_priority', -1);
$incident_resolution = (string) get_parameter('incident_resolution', '');
$incident_date = (string) get_parameter('incident_date', '');
$created_from = (string) get_parameter('created_from', '');
$created_to = (string) get_parameter('created_to', '');
$offset = (int) get_parameter('offset');
@ -74,9 +75,9 @@ if ($delete_incident) {
// Full url with all filters.
$url = ui_get_full_url(
'index.php?sec=incident&sec2=operation/incidents/list_integriaims_incidents&incident_text='.$incident_text.'&incident_status='.$incident_status.'&incident_group='.$incident_group.'&incident_owner='.$incident_owner.'&incident_creator='.$incident_creator.'&incident_priority='.$incident_priority.'&incident_resolution='.$incident_resolution.'&incident_date='.$incident_date.'&offset='.$offset
'index.php?sec=incident&sec2=operation/incidents/list_integriaims_incidents&incident_text='.$incident_text.'&incident_status='.$incident_status.'&incident_group='.$incident_group.'&incident_owner='.$incident_owner.'&incident_creator='.$incident_creator.'&incident_priority='.$incident_priority.'&incident_resolution='.$incident_resolution.'&created_from='.$created_from.'&created_to='.$created_to.'&offset='.$offset
);
hd($url);
// ---- FILTERS ----
// API calls to fill the filters.
@ -165,7 +166,7 @@ $table->data[2][1] = html_print_select(
$table->data[2][2] = __('Date');
$table->data[2][3] = html_print_input_text_extended(
'created_from',
'',
$created_from,
'created_from',
'',
12,
@ -177,7 +178,7 @@ $table->data[2][3] = html_print_input_text_extended(
);
$table->data[2][3] .= html_print_input_text_extended(
'created_to',
'',
$created_to,
'created_to',
'',
12,
@ -189,8 +190,8 @@ $table->data[2][3] .= html_print_input_text_extended(
);
// TODO: image of Integria IMS.
$table->data[2][4] = 'Imagen:';
$table->data[2][5] = 'IMAGEN';
$table->data[2][4] = '';
$table->data[2][5] = '';
// Send filters to get_tickets_integriaims().
@ -202,7 +203,8 @@ $tickets_filters = [
'incident_creator' => $incident_creator,
'incident_priority' => $incident_priority,
'incident_resolution' => $incident_resolution,
'incident_date' => $incident_date,
'created_from' => $created_from,
'created_to' => $created_to,
];
// Data to export to csv file.
@ -319,3 +321,16 @@ if (check_acl($config['id_user'], 0, 'IR')) {
echo '</div>';
echo '</form>';
}
// Datapicker library for show calendar.
ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript/i18n/');
?>
<script language="javascript" type="text/javascript">
$(document).ready( function() {
$("#created_from, #created_to").datepicker({
dateFormat: "<?php echo DATE_FORMAT_JS; ?>"
});
});
</script>