From 306bfe2a542d831844e1b8dc9a867cd1530cfa4b Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Fri, 3 Jul 2015 12:32:03 +0200 Subject: [PATCH] Encapsulated some code to format a date into an human readable string into a function --- .../include/functions_reporting.php | 129 ++++++++++-------- 1 file changed, 75 insertions(+), 54 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index e94939a11f..3cae99783e 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -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; +} + ?> \ No newline at end of file