Encapsulated some code to format a date into an human readable string into a function

This commit is contained in:
Alejandro Gallardo Escobar 2015-07-03 12:32:03 +02:00
parent 37b55517e1
commit 306bfe2a54
1 changed files with 75 additions and 54 deletions

View File

@ -558,60 +558,7 @@ function reporting_SLA($report, $content, $type = 'dinamic',
$data['name'] = $planned_downtime['name'];
$data['description'] = $planned_downtime['description'];
$data['execution'] = ucfirst($planned_downtime['type_execution']);
$data['dates'] = "";
switch ($planned_downtime['type_execution']) {
case 'once':
$data['dates'] = date ("Y-m-d H:i", $planned_downtime['date_from']) .
" " . __('to') . " ".
date ("Y-m-d H:i", $planned_downtime['date_to']);
break;
case 'periodically':
switch ($planned_downtime['type_periodicity']) {
case 'weekly':
$data['dates'] = __('Weekly:');
$data['dates'] .= " ";
if ($planned_downtime['monday']) {
$data['dates'] .= __('Mon');
$data['dates'] .= " ";
}
if ($planned_downtime['tuesday']) {
$data['dates'] .= __('Tue');
$data['dates'] .= " ";
}
if ($planned_downtime['wednesday']) {
$data['dates'] .= __('Wed');
$data['dates'] .= " ";
}
if ($planned_downtime['thursday']) {
$data['dates'] .= __('Thu');
$data['dates'] .= " ";
}
if ($planned_downtime['friday']) {
$data['dates'] .= __('Fri');
$data['dates'] .= " ";
}
if ($planned_downtime['saturday']) {
$data['dates'] .= __('Sat');
$data['dates'] .= " ";
}
if ($planned_downtime['sunday']) {
$data['dates'] .= __('Sun');
$data['dates'] .= " ";
}
$data['dates'] .= " (" . $planned_downtime['periodically_time_from'];
$data['dates'] .= "-" . $planned_downtime['periodically_time_to'] . ")";
break;
case 'monthly':
$data['dates'] = __('Monthly:') . " ";
$data['dates'] .= __('From day') . " " . $planned_downtime['periodically_day_from'];
$data['dates'] .= " " . strtolower(__('To day')) . " ";
$data['dates'] .= $planned_downtime['periodically_day_to'];
$data['dates'] .= " (" . $planned_downtime['periodically_time_from'];
$data['dates'] .= "-" . $planned_downtime['periodically_time_to'] . ")";
break;
}
break;
}
$data['dates'] = reporting_format_planned_downtime_dates($planned_downtime);
$data['malformed'] = 0;
if (!$malformed_planned_downtimes_empty
@ -8180,4 +8127,78 @@ function reporting_template_graphs_get_user ($id_user = 0, $only_names = false,
return $templates;
}
/**
* Get a human readable representation of the planned downtime date.
*
* @param array $planned_downtime Planned downtime row.
*
* @return string Representation of the date.
*/
function reporting_format_planned_downtime_dates ($planned_downtime) {
$dates = '';
if (!isset($planned_downtime) || !isset($planned_downtime['type_execution']))
return '';
switch ($planned_downtime['type_execution']) {
case 'once':
$dates = date ("Y-m-d H:i", $planned_downtime['date_from']) .
" " . __('to') . " ".
date ("Y-m-d H:i", $planned_downtime['date_to']);
break;
case 'periodically':
if (!isset($planned_downtime['type_periodicity']))
return '';
switch ($planned_downtime['type_periodicity']) {
case 'weekly':
$dates = __('Weekly:');
$dates .= " ";
if ($planned_downtime['monday']) {
$dates .= __('Mon');
$dates .= " ";
}
if ($planned_downtime['tuesday']) {
$dates .= __('Tue');
$dates .= " ";
}
if ($planned_downtime['wednesday']) {
$dates .= __('Wed');
$dates .= " ";
}
if ($planned_downtime['thursday']) {
$dates .= __('Thu');
$dates .= " ";
}
if ($planned_downtime['friday']) {
$dates .= __('Fri');
$dates .= " ";
}
if ($planned_downtime['saturday']) {
$dates .= __('Sat');
$dates .= " ";
}
if ($planned_downtime['sunday']) {
$dates .= __('Sun');
$dates .= " ";
}
$dates .= " (" . $planned_downtime['periodically_time_from'];
$dates .= "-" . $planned_downtime['periodically_time_to'] . ")";
break;
case 'monthly':
$dates = __('Monthly:') . " ";
$dates .= __('From day') . " " . $planned_downtime['periodically_day_from'];
$dates .= " " . strtolower(__('To day')) . " ";
$dates .= $planned_downtime['periodically_day_to'];
$dates .= " (" . $planned_downtime['periodically_time_from'];
$dates .= "-" . $planned_downtime['periodically_time_to'] . ")";
break;
}
break;
}
return $dates;
}
?>