From c23491b2576a52db63d2d00904630f35a5de9113 Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Wed, 8 Feb 2012 15:13:17 +0100 Subject: [PATCH] CC-3285 : show over booked error message checking if percentage is over 100. --- .../application/models/ShowInstance.php | 38 ++++++----- .../models/airtime/CcShowInstances.php | 63 +++++++++++++++++++ .../public/js/airtime/schedule/schedule.js | 11 ++-- 3 files changed, 89 insertions(+), 23 deletions(-) diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index b5dbfb55b..28a3e9315 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -58,21 +58,19 @@ class Application_Model_ShowInstance { /** * Return the start time of the Show (UTC time) * @return string in format "Y-m-d H:i:s" (PHP time notation) - * TODO: make this function return a DateTime object instead. */ - public function getShowInstanceStart() + public function getShowInstanceStart($format="Y-m-d H:i:s") { - return $this->_showInstance->getDbStarts(); + return $this->_showInstance->getDbStarts($format); } /** * Return the end time of the Show (UTC time) * @return string in format "Y-m-d H:i:s" (PHP time notation) - * TODO: make this function return a DateTime object instead. */ - public function getShowInstanceEnd() + public function getShowInstanceEnd($format="Y-m-d H:i:s") { - return $this->_showInstance->getDbEnds(); + return $this->_showInstance->getDbEnds($format); } public function getStartDate() @@ -607,20 +605,26 @@ class Application_Model_ShowInstance { return $time; } + + public function getTimeScheduledSecs() + { + $time_filled = $this->getTimeScheduled(); + return Application_Model_Schedule::WallTimeToMillisecs($time_filled) / 1000; + } + + public function getDurationSecs() + { + $ends = $this->getShowInstanceEnd(null); + $starts = $this->getShowInstanceStart(null); + return $ends->format('U') - $starts->format('U'); + } + public function getPercentScheduled() { - $start_timestamp = $this->getShowInstanceStart(); - $end_timestamp = $this->getShowInstanceEnd(); - $time_filled = $this->getTimeScheduled(); + $durationSeconds = $this->getDurationSecs(); + $timeSeconds = $this->getTimeScheduledSecs(); - $s_epoch = strtotime($start_timestamp); - $e_epoch = strtotime($end_timestamp); - $i_epoch = Application_Model_Schedule::WallTimeToMillisecs($time_filled) / 1000; - - $percent = ceil(($i_epoch / ($e_epoch - $s_epoch)) * 100); - - if ($percent > 100) - $percent = 100; + $percent = ceil(($timeSeconds / $durationSeconds) * 100); return $percent; } diff --git a/airtime_mvc/application/models/airtime/CcShowInstances.php b/airtime_mvc/application/models/airtime/CcShowInstances.php index bdf6164e3..92688ac49 100644 --- a/airtime_mvc/application/models/airtime/CcShowInstances.php +++ b/airtime_mvc/application/models/airtime/CcShowInstances.php @@ -36,4 +36,67 @@ class CcShowInstances extends BaseCcShowInstances { return $result; } + /** + * Get the [optionally formatted] temporal [starts] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw DateTime object will be returned. + * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getDbStarts($format = 'Y-m-d H:i:s') + { + if ($this->starts === null) { + return null; + } + + try { + $dt = new DateTime($this->starts, new DateTimeZone("UTC")); + } catch (Exception $x) { + throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->starts, true), $x); + } + + if ($format === null) { + // Because propel.useDateTimeClass is TRUE, we return a DateTime object. + return $dt; + } elseif (strpos($format, '%') !== false) { + return strftime($format, $dt->format('U')); + } else { + return $dt->format($format); + } + } + + /** + * Get the [optionally formatted] temporal [ends] column value. + * + * + * @param string $format The date/time format string (either date()-style or strftime()-style). + * If format is NULL, then the raw DateTime object will be returned. + * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL + * @throws PropelException - if unable to parse/validate the date/time value. + */ + public function getDbEnds($format = 'Y-m-d H:i:s') + { + if ($this->ends === null) { + return null; + } + + try { + $dt = new DateTime($this->ends, new DateTimeZone("UTC")); + } catch (Exception $x) { + throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->ends, true), $x); + } + + if ($format === null) { + // Because propel.useDateTimeClass is TRUE, we return a DateTime object. + return $dt; + } elseif (strpos($format, '%') !== false) { + return strftime($format, $dt->format('U')); + } else { + return $dt->format($format); + } + } + + } // CcShowInstances diff --git a/airtime_mvc/public/js/airtime/schedule/schedule.js b/airtime_mvc/public/js/airtime/schedule/schedule.js index 6cc8858bf..625b1ecef 100644 --- a/airtime_mvc/public/js/airtime/schedule/schedule.js +++ b/airtime_mvc/public/js/airtime/schedule/schedule.js @@ -11,11 +11,10 @@ function closeDialog(event, ui) { $(this).remove(); } -function checkShowLength() { - var showFilled = $("#show_time_filled").text().split('.')[0]; - var showLength = $("#show_length").text(); +function checkShowLength(json) { + var percent = json.percentFilled; - if (showFilled > showLength){ + if (percent > 100){ $("#show_time_warning") .text("Shows longer than their scheduled time will be cut off by a following show.") .show(); @@ -41,7 +40,7 @@ function setScheduleDialogHtml(json) { $("#show_time_filled").empty().append(json.timeFilled); $("#show_progressbar").progressbar( "value" , json.percentFilled ); - checkShowLength(); + checkShowLength(json); } function setScheduleDialogEvents(dialog) { @@ -298,7 +297,7 @@ function buildScheduleDialog(json){ }); dialog.dialog('open'); - checkShowLength(); + checkShowLength(json); }