diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index 2cca81ac2..0d2ead443 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -513,6 +513,7 @@ class PlaylistController extends Zend_Controller_Action } catch (BlockNotFoundException $e) { $this->playlistNotFound('block', true); } catch (Exception $e) { + Logging::info($e); $this->playlistUnknownError($e); } } diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 55a28c79a..8d716b461 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -212,6 +212,14 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm }//for + $repeatTracks = new Zend_Form_Element_Checkbox('sp_repeat_tracks'); + $repeatTracks->setDecorators(array('viewHelper')) + ->setLabel('Allow Repeat Tracks:'); + if (isset($storedCrit["repeat_tracks"])) { + $repeatTracks->setChecked($storedCrit["repeat_tracks"]["value"] == 1?true:false); + } + $this->addElement($repeatTracks); + $limit = new Zend_Form_Element_Select('sp_limit_options'); $limit->setAttrib('class', 'sp_input_select') ->setDecorators(array('viewHelper')) @@ -220,7 +228,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $limit->setValue($storedCrit["limit"]["modifier"]); } $this->addElement($limit); - + $limitValue = new Zend_Form_Element_Text('sp_limit_value'); $limitValue->setAttrib('class', 'sp_input_text_limit') ->setLabel('Limit to') diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 80fae297d..364c11ef0 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -1093,6 +1093,14 @@ SQL; ->setDbValue($p_criteriaData['etc']['sp_limit_value']) ->setDbBlockId($this->id) ->save(); + + // insert repeate track option + $qry = new CcBlockcriteria(); + $qry->setDbCriteria("repeat_tracks") + ->setDbModifier("N/A") + ->setDbValue($p_criteriaData['etc']['sp_repeat_tracks']) + ->setDbBlockId($this->id) + ->save(); } /** @@ -1105,7 +1113,7 @@ SQL; $this->saveSmartBlockCriteria($p_criteria); $insertList = $this->getListOfFilesUnderLimit(); $this->deleteAllFilesFromBlock(); - $this->addAudioClips(array_keys($insertList)); + $this->addAudioClips(array_values($insertList)); // update length in playlist contents. $this->updateBlockLengthInAllPlaylist(); @@ -1134,6 +1142,7 @@ SQL; $info = $this->getListofFilesMeetCriteria(); $files = $info['files']; $limit = $info['limit']; + $repeat = $info['repeat_tracks']; $insertList = array(); $totalTime = 0; @@ -1142,19 +1151,45 @@ SQL; // this moves the pointer to the first element in the collection $files->getFirst(); $iterator = $files->getIterator(); - while ($iterator->valid() && $totalTime < $limit['time']) { + + $isBlockFull = false; + + while ($iterator->valid()) { $id = $iterator->current()->getDbId(); $length = Application_Common_DateHelper::calculateLengthInSeconds($iterator->current()->getDbLength()); - $insertList[$id] = $length; + $insertList[] = $id; $totalTime += $length; $totalItems++; - - if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500) { - break; + + if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) { + $isBlockFull = true; + break; } $iterator->next(); } + + // if block is not full and reapeat_track is check, fill up more + while (!$isBlockFull && $repeat == 1) { + if (!$iterator->valid()) { + $iterator->closeCursor(); + $info = $this->getListofFilesMeetCriteria(); + $files = $info['files']; + $files->getFirst(); + $iterator = $files->getIterator(); + } + $id = $iterator->current()->getDbId(); + $length = Application_Common_DateHelper::calculateLengthInSeconds($iterator->current()->getDbLength()); + $insertList[] = $id; + $totalTime += $length; + $totalItems++; + + if ((!is_null($limit['items']) && $limit['items'] == count($insertList)) || $totalItems > 500 || $totalTime > $limit['time']) { + break; + } + + $iterator->next(); + } return $insertList; } @@ -1202,6 +1237,8 @@ SQL; if ($criteria == "limit") { $storedCrit["limit"] = array("value"=>$value, "modifier"=>$modifier); + } else if($criteria == "repeat_tracks") { + $storedCrit["repeat_tracks"] = array("value"=>$value); } else { $storedCrit["crit"][$criteria][] = array("criteria"=>$criteria, "value"=>$value, "modifier"=>$modifier, "extra"=>$extra, "display_name"=>$criteriaOptions[$criteria]); } @@ -1317,6 +1354,7 @@ SQL; } // construct limit restriction $limits = array(); + if (isset($storedCrit['limit'])) { if ($storedCrit['limit']['modifier'] == "items") { $limits['time'] = 1440 * 60; @@ -1328,10 +1366,16 @@ SQL; $limits['items'] = null; } } + + $repeatTracks = 0; + if (isset($storedCrit['repeat_tracks'])) { + $repeatTracks = $storedCrit['repeat_tracks']['value']; + } + try { $out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find(); - return array("files"=>$out, "limit"=>$limits, "count"=>$out->count()); + return array("files"=>$out, "limit"=>$limits, "repeat_tracks"=> $repeatTracks, "count"=>$out->count()); } catch (Exception $e) { Logging::info($e); } @@ -1377,7 +1421,7 @@ SQL; $output['etc'][$ele['name']] = $ele['value']; } } - + return $output; } // smart block functions end diff --git a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml index 0f27248ca..c75791fe1 100644 --- a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml +++ b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml @@ -59,6 +59,20 @@
+
+ element->getElement('sp_repeat_tracks')->getLabel() ?> + + element->getElement('sp_repeat_tracks')?> + element->getElement("sp_repeat_tracks")->hasErrors()) : ?> + element->getElement("sp_repeat_tracks")->getMessages() as $error): ?> + + + + + +
+
+
element->getElement('sp_limit_value')->getLabel() ?> element->getElement('sp_limit_value')?> diff --git a/airtime_mvc/public/css/styles.css b/airtime_mvc/public/css/styles.css index b14b77251..c47192450 100644 --- a/airtime_mvc/public/css/styles.css +++ b/airtime_mvc/public/css/styles.css @@ -105,7 +105,7 @@ select { } .airtime_auth_help_icon, .custom_auth_help_icon, .stream_username_help_icon, -.playlist_type_help_icon, .master_username_help_icon { +.playlist_type_help_icon, .master_username_help_icon, .repeat_tracks_help_icon{ cursor: help; position: relative; display:inline-block; zoom:1; diff --git a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js index 0dc3bc0a9..fc736b84a 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js @@ -384,6 +384,28 @@ function setupUI() { at: "right center" }, }); + + $(".repeat_tracks_help_icon").qtip({ + content: { + text: "If your criteria is too strict, Airtime may not be able to fill up the desired smart block length." + + " Hence, if you check this option, tracks will be used more than once." + }, + hide: { + delay: 500, + fixed: true + }, + style: { + border: { + width: 0, + radius: 4 + }, + classes: "ui-tooltip-dark ui-tooltip-rounded" + }, + position: { + my: "left bottom", + at: "right center" + }, + }); } function enableAndShowExtraField(valEle, index) {