From 6e71a6bb92ed1e765ee154713726fded3a6a3699 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 2 Aug 2012 11:17:10 -0400 Subject: [PATCH] CC-84: Smart Playlists - dynamic block length display --- airtime_mvc/application/models/Block.php | 28 +++++++++++++++++-- airtime_mvc/application/models/Datatables.php | 3 ++ airtime_mvc/application/models/Playlist.php | 8 ++++-- .../models/formatters/LengthFormatter.php | 4 +-- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 1d9163957..3e4a91e4c 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -245,11 +245,35 @@ EOT; // function return "N/A" if dynamic public function getLength() { - $length = $this->block->getDbLength(); + if ($this->isStatic()){ + $length = $this->block->getDbLength(); + } else { + $length = $this->getDynamicBlockLength(); + } $length = $length == null ? "N/A" : $length; return $length; } + public function getDynamicBlockLength() + { + $result = CcBlockcriteriaQuery::create()->filterByDbBlockId($this->id) + ->filterByDbCriteria('limit')->findOne(); + $modifier = $result->getDbModifier(); + $value = $result->getDbValue(); + if ($modifier == "items") { + $length = $value." ".$modifier; + } else { + if ($modifier == "minutes") { + $timestamp = "00:".$value.":00"; + } else if ($modifier == "hours") { + $timestamp = $value."00:00"; + } + $formatter = new LengthFormatter($timestamp); + $length = "~".$formatter->format(); + } + return $length; + } + // public function getStaticLength(){ $sql = "SELECT SUM(cliplength) as length FROM cc_blockcontents WHERE block_id={$this->id}"; @@ -1033,7 +1057,7 @@ EOT; // as it cannot be calculated if ($blockType == 'dynamic') { $this->setLength(null); - $output['blockLength'] = "N/A"; + $output['blockLength'] = $this->getDynamicBlockLength(); } else { $length = $this->getStaticLength(); $this->setLength($length); diff --git a/airtime_mvc/application/models/Datatables.php b/airtime_mvc/application/models/Datatables.php index 545b08cbb..f54631cb7 100644 --- a/airtime_mvc/application/models/Datatables.php +++ b/airtime_mvc/application/models/Datatables.php @@ -93,6 +93,9 @@ class Application_Model_Datatables if ($r['ftype'] == 'playlist') { $pl = new Application_Model_Playlist($r['id']); $r['length'] = $pl->getLength(); + } else if ($r['ftype'] == "block") { + $bl = new Application_Model_Block($r['id']); + $r['length'] = $bl->getLength(); } } } catch (Exception $e) { diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index faf3d838d..f560c4f37 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -196,7 +196,12 @@ EOT; $offset_cliplength = Application_Common_DateHelper::secondsToPlaylistTime($offset); //format the length for UI. - $formatter = new LengthFormatter($row['length']); + if ($row['type'] == 2){ + $bl = new Application_Model_Block($row['item_id']); + $formatter = new LengthFormatter($bl->getLength()); + } else { + $formatter = new LengthFormatter($row['length']); + } $row['length'] = $formatter->format(); $formatter = new LengthFormatter($offset_cliplength); @@ -268,7 +273,6 @@ EOT; //aggregate column on playlistcontents cliplength column. public function getLength() { - Logging::log($this->hasDynamicBlockOrWebStream()); if ($this->hasDynamicBlockOrWebStream()){ return "N/A"; } else { diff --git a/airtime_mvc/application/models/formatters/LengthFormatter.php b/airtime_mvc/application/models/formatters/LengthFormatter.php index d41ffc563..5278b1a82 100644 --- a/airtime_mvc/application/models/formatters/LengthFormatter.php +++ b/airtime_mvc/application/models/formatters/LengthFormatter.php @@ -16,8 +16,8 @@ class LengthFormatter { } public function format() { - if ($this->_length == "N/A" || $this->_length == "") { - return "N/A"; + if (!preg_match("/^[0-9]{2}:[0-9]{2}:[0-9]{2}/", $this->_length)) { + return $this->_length; } $pieces = explode(":", $this->_length);