diff --git a/airtime_mvc/application/common/DateHelper.php b/airtime_mvc/application/common/DateHelper.php index 0c3b880c5..7a8861283 100644 --- a/airtime_mvc/application/common/DateHelper.php +++ b/airtime_mvc/application/common/DateHelper.php @@ -152,6 +152,11 @@ class Application_Common_DateHelper { return strtotime($time2) - strtotime($time1); } + + public static function TimeAdd($time1, $time2) + { + return strtotime($time2) + strtotime($time1); + } public static function ConvertMSToHHMMSSmm($time) { diff --git a/airtime_mvc/application/controllers/AudiopreviewController.php b/airtime_mvc/application/controllers/AudiopreviewController.php index 43e3bbf94..478b7ef19 100644 --- a/airtime_mvc/application/controllers/AudiopreviewController.php +++ b/airtime_mvc/application/controllers/AudiopreviewController.php @@ -81,6 +81,53 @@ class AudiopreviewController extends Zend_Controller_Action $this->_helper->viewRenderer->setRender('audio-preview'); } + public function blockPreviewAction() + { + global $CC_CONFIG; + + $blockIndex = $this->_getParam('blockIndex'); + $blockId = $this->_getParam('blockId'); + + $request = $this->getRequest(); + $baseUrl = $request->getBaseUrl(); + + $baseDir = dirname($_SERVER['SCRIPT_FILENAME']); + + $this->view->headScript()->appendFile($baseUrl.'/js/airtime/audiopreview/preview_jplayer.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headScript()->appendFile($baseUrl.'/js/jplayer/jplayer.playlist.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + $this->view->headLink()->appendStylesheet($baseUrl.'/js/jplayer/skin/jplayer.airtime.audio.preview.css?'.$CC_CONFIG['airtime_version']); + $this->_helper->layout->setLayout('audioPlayer'); + + $logo = Application_Model_Preference::GetStationLogo(); + if ($logo) { + $this->view->logo = "data:image/png;base64,$logo"; + } else { + $this->view->logo = "$baseUrl/css/images/airtime_logo_jp.png"; + } + $this->view->blockIndex= $blockIndex; + $this->view->blockId = $blockId; + + $this->_helper->viewRenderer->setRender('audio-preview'); + } + public function getBlockAction() + { + // disable the view and the layout + $this->view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + $blockId = $this->_getParam('blockId'); + + if (!isset($blockId)) { + return; + } + + $bl = new Application_Model_Block($blockId); + $result = array(); + foreach ($bl->getContents(true) as $ele) { + $result[] = $this->createElementMap($ele); + } + $this->_helper->json($result); + } /** *Function will load and return the contents of the requested playlist. */ diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 9e0119f20..78fd1abe5 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -76,6 +76,9 @@ class LibraryController extends Zend_Controller_Action $obj = new Application_Model_Playlist($id); } else { $obj = new Application_Model_Block($id); + if (!$obj->isStatic()){ + unset($menu["play"]); + } if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) { if ($this->obj_sess->type === "playlist") { $menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy"); @@ -312,21 +315,22 @@ class LibraryController extends Zend_Controller_Action $this->view->md = $md; $this->view->contents = $file->getContents(); } else if ($type == "block") { - $file = new Application_Model_Block($id); + $block = new Application_Model_Block($id); $this->view->type = $type; - $md = $file->getAllPLMetaData(); + $md = $block->getAllPLMetaData(); $formatter = new LengthFormatter($md["dcterms:extent"]); $md["dcterms:extent"] = $formatter->format(); $this->view->md = $md; - if ($file->isStatic()) { + if ($block->isStatic()) { $this->view->blType = 'Static'; - $this->view->contents = $file->getContents(); + $this->view->contents = $block->getContents(); } else { $this->view->blType = 'Dynamic'; - $this->view->contents = $file->getCriteria(); + $this->view->contents = $block->getCriteria(); } + $this->view->block = $block; } else if ($type == "stream") { $file = new Application_Model_Webstream($id); diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index 43103edf9..044ebde34 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -71,7 +71,6 @@ class PlaylistController extends Zend_Controller_Action $this->view->length = $formatter->format(); $this->view->obj = $obj; - Logging::log($obj->getContents()); $this->view->html = $this->view->render('playlist/update.phtml'); $this->view->name = $obj->getName(); $this->view->description = $obj->getDescription(); diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 3e4a91e4c..1752bd441 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -250,30 +250,50 @@ EOT; } else { $length = $this->getDynamicBlockLength(); } - $length = $length == null ? "N/A" : $length; return $length; } + public function getFormattedLength() + { + $prepend = ""; + if ($this->isStatic()){ + $length = $this->block->getDbLength(); + } else { + $length = $this->getDynamicBlockLength(); + if (!$this->hasItemLimit()) { + $prepend = "~"; + } + } + $formatter = new LengthFormatter($length); + $length = $prepend.$formatter->format(); + return $length; + } + public function getDynamicBlockLength() { - $result = CcBlockcriteriaQuery::create()->filterByDbBlockId($this->id) - ->filterByDbCriteria('limit')->findOne(); - $modifier = $result->getDbModifier(); - $value = $result->getDbValue(); + list($value, $modifier) = $this->getLimitValueAndModifier(); if ($modifier == "items") { $length = $value." ".$modifier; } else { + $value = str_pad($value, 2, "0", STR_PAD_LEFT); if ($modifier == "minutes") { - $timestamp = "00:".$value.":00"; + $length = "00:".$value.":00"; } else if ($modifier == "hours") { - $timestamp = $value."00:00"; + $length = $value."00:00"; } - $formatter = new LengthFormatter($timestamp); - $length = "~".$formatter->format(); } return $length; } + public function getLimitValueAndModifier() + { + $result = CcBlockcriteriaQuery::create()->filterByDbBlockId($this->id) + ->filterByDbCriteria('limit')->findOne(); + $modifier = $result->getDbModifier(); + $value = $result->getDbValue(); + return array($value, $modifier); + } + // public function getStaticLength(){ $sql = "SELECT SUM(cliplength) as length FROM cc_blockcontents WHERE block_id={$this->id}"; @@ -886,6 +906,7 @@ EOT; public function setLength($value){ $this->block->setDbLength($value); $this->block->save($this->con); + $this->updateBlockLengthInAllPlaylist(); } @@ -1056,18 +1077,31 @@ EOT; // if the block is dynamic, put null to the length // as it cannot be calculated if ($blockType == 'dynamic') { - $this->setLength(null); - $output['blockLength'] = $this->getDynamicBlockLength(); + if ($this->hasItemLimit()) { + $this->setLength(null); + } else { + $this->setLength($this->getDynamicBlockLength()); + } } else { $length = $this->getStaticLength(); $this->setLength($length); - $formatter = new LengthFormatter($length); - $output['blockLength'] = $formatter->format(); } + $output['blockLength'] = $this->getFormattedLength(); } + $this->updateBlockLengthInAllPlaylist(); return $output; } + public function hasItemLimit() + { + list($value, $modifier) = $this->getLimitValueAndModifier(); + if ($modifier == 'items') { + return true; + } else { + return false; + } + } + public function storeCriteriaIntoDb($p_criteriaData){ // delete criteria under $p_blockId CcBlockcriteriaQuery::create()->findByDbBlockId($this->id)->delete(); @@ -1128,18 +1162,28 @@ EOT; $this->deleteAllFilesFromBlock(); $this->addAudioClips(array_keys($insertList)); // update length in playlist contents. - $blocks = CcPlaylistcontentsQuery::create()->filterByDbBlockId($this->id)->find(); - $blocks->getFirst(); - $iterator = $blocks->getIterator(); - while ($iterator->valid()) { - $iterator->current()->setDbClipLength($this->getLength()); - $iterator->current()->save(); - $iterator->next(); - } + $this->updateBlockLengthInAllPlaylist(); return array("result"=>0); } } + public function updateBlockLengthInAllPlaylist() + { + $blocks = CcPlaylistcontentsQuery::create()->filterByDbBlockId($this->id)->find(); + $blocks->getFirst(); + $iterator = $blocks->getIterator(); + while ($iterator->valid()) { + $length = $this->getLength(); + if (!preg_match("/^[0-9]{2}:[0-9]{2}:[0-9]{2}/", $length)) { + $iterator->current()->setDbClipLength(null); + } else { + $iterator->current()->setDbClipLength($length); + } + $iterator->current()->save(); + $iterator->next(); + } + } + public function getListOfFilesUnderLimit() { $info = $this->getListofFilesMeetCriteria(); diff --git a/airtime_mvc/application/models/Datatables.php b/airtime_mvc/application/models/Datatables.php index f54631cb7..a807757ad 100644 --- a/airtime_mvc/application/models/Datatables.php +++ b/airtime_mvc/application/models/Datatables.php @@ -94,8 +94,8 @@ class Application_Model_Datatables $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(); + $bl = new Application_Model_Block($r['id']); + $r['length'] = $bl->getFormattedLength(); } } } catch (Exception $e) { diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index f560c4f37..bc8f353a8 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -198,7 +198,7 @@ EOT; //format the length for UI. if ($row['type'] == 2){ $bl = new Application_Model_Block($row['item_id']); - $formatter = new LengthFormatter($bl->getLength()); + $formatter = new LengthFormatter($bl->getFormattedLength()); } else { $formatter = new LengthFormatter($row['length']); } @@ -257,24 +257,39 @@ EOT; return $fade; } - public function hasDynamicBlockOrWebStream(){ - $sql = "SELECT count(*) as count FROM cc_playlistcontents as pc - JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic' - WHERE playlist_id={$this->id} AND (pc.type=2 OR pc.type=1)"; - $r = $this->con->query($sql); - $result = $r->fetchAll(PDO::FETCH_NUM); - if (intval($result[0][0]) > 0) { + // returns true/false and ids of dynamic blocks + public function hasDynamicBlock(){ + $ids = $this->getIdsOfDynamicBlocks(); + if (count($ids) > 0) { return true; } else { return false; } } + + public function getIdsOfDynamicBlocks() { + $sql = "SELECT bl.id FROM cc_playlistcontents as pc + JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic' + WHERE playlist_id={$this->id} AND pc.type=2"; + $r = $this->con->query($sql); + $result = $r->fetchAll(PDO::FETCH_ASSOC); + return $result; + } //aggregate column on playlistcontents cliplength column. public function getLength() { - if ($this->hasDynamicBlockOrWebStream()){ - return "N/A"; + if ($this->hasDynamicBlock()){ + $ids = $this->getIdsOfDynamicBlocks(); + $length = $this->pl->getDbLength(); + foreach ($ids as $id){ + $bl = new Application_Model_Block($id['id']); + if ($bl->hasItemLimit()) { + return "N/A"; + } + } + $formatter = new LengthFormatter($length); + return "~".$formatter->format(); } else { return $this->pl->getDbLength(); } diff --git a/airtime_mvc/application/views/scripts/audiopreview/audio-preview.phtml b/airtime_mvc/application/views/scripts/audiopreview/audio-preview.phtml index d5d1b2dc4..d440d96ca 100644 --- a/airtime_mvc/application/views/scripts/audiopreview/audio-preview.phtml +++ b/airtime_mvc/application/views/scripts/audiopreview/audio-preview.phtml @@ -3,6 +3,9 @@ playlistID)): ?> playlistID" ?> playlistIndex" ?> +blockId)): ?> + blockId" ?> + blockIndex" ?> audioFileID)): ?> audioFileID" ?> audioFileTitle" ?> diff --git a/airtime_mvc/application/views/scripts/library/get-file-metadata.ajax.phtml b/airtime_mvc/application/views/scripts/library/get-file-metadata.ajax.phtml index 3579b1d7c..c192e9ddb 100644 --- a/airtime_mvc/application/views/scripts/library/get-file-metadata.ajax.phtml +++ b/airtime_mvc/application/views/scripts/library/get-file-metadata.ajax.phtml @@ -26,23 +26,7 @@