From b813ba1035f9068fa779885fa5147487389b8cf8 Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Thu, 1 Mar 2012 17:25:37 +0100 Subject: [PATCH] CC-3174 : showbuilder making a time filled formatter to take the code out of show builder. --- .../application/models/ShowBuilder.php | 34 ++------------ .../models/formatters/TimeFilledFormatter.php | 46 +++++++++++++++++++ 2 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 airtime_mvc/application/models/formatters/TimeFilledFormatter.php diff --git a/airtime_mvc/application/models/ShowBuilder.php b/airtime_mvc/application/models/ShowBuilder.php index 0443c63cd..cbc75b2b9 100644 --- a/airtime_mvc/application/models/ShowBuilder.php +++ b/airtime_mvc/application/models/ShowBuilder.php @@ -1,6 +1,7 @@ epoch_now = time(); } - private function formatTimeFilled($p_sec) { - - $formatted = ""; - $sign = ($p_sec < 0) ? "-" : "+"; - - $time = Application_Model_Playlist::secondsToPlaylistTime(abs($p_sec)); - Logging::log("time is: ".$time); - $info = explode(":", $time); - - $formatted .= $sign; - - if (intval($info[0]) > 0) { - $info[0] = ltrim($info[0], "0"); - $formatted .= " {$info[0]}h"; - } - - if (intval($info[1]) > 0) { - $info[1] = ltrim($info[1], "0"); - $formatted .= " {$info[1]}m"; - } - - if (intval($info[2]) > 0) { - $sec = round($info[2], 0); - $formatted .= " {$sec}s"; - } - - return $formatted; - } - //check to see if this row should be editable. private function isAllowed($p_item, &$row) { @@ -206,7 +178,9 @@ class Application_Model_ShowBuilder { $runtime = bcsub($contentDT->format("U.u"), $showEndDT->format("U.u"), 6); $row["runtime"] = $runtime; - $row["fRuntime"] = $this->formatTimeFilled($runtime); + + $timeFilled = new TimeFilledFormatter($runtime); + $row["fRuntime"] = $timeFilled->format(); return $row; } diff --git a/airtime_mvc/application/models/formatters/TimeFilledFormatter.php b/airtime_mvc/application/models/formatters/TimeFilledFormatter.php new file mode 100644 index 000000000..6a894d194 --- /dev/null +++ b/airtime_mvc/application/models/formatters/TimeFilledFormatter.php @@ -0,0 +1,46 @@ +_seconds = $seconds; + } + + public function format() + { + $formatted = ""; + $sign = ($this->_seconds < 0) ? "-" : "+"; + + $time = Application_Model_Playlist::secondsToPlaylistTime(abs($this->_seconds)); + Logging::log("time is: ".$time); + $info = explode(":", $time); + + $formatted .= $sign; + + if (intval($info[0]) > 0) { + $info[0] = ltrim($info[0], "0"); + $formatted .= " {$info[0]}h"; + } + + if (intval($info[1]) > 0) { + $info[1] = ltrim($info[1], "0"); + $formatted .= " {$info[1]}m"; + } + + if (intval($info[2]) > 0) { + $sec = round($info[2], 0); + $formatted .= " {$sec}s"; + } + + return $formatted; + } +} \ No newline at end of file