Merge pull request #707 from Robbt/intro-playlist

Add Intro and Outro playlist to Autoloading Playlists
This commit is contained in:
frecuencialibre 2019-02-14 10:49:15 -06:00 committed by GitHub
commit 4d0fea34fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 91 additions and 19 deletions

View File

@ -23,32 +23,44 @@ class AutoPlaylistManager {
*
*/
public static function buildAutoPlaylist() {
Logging::info("Checking to run Auto Playlist");
//Logging::info("Checking to run Auto Playlist");
$autoPlaylists = static::_upcomingAutoPlaylistShows();
foreach ($autoPlaylists as $autoplaylist) {
// creates a ShowInstance object to build the playlist in from the ShowInstancesQuery Object
$si = new Application_Model_ShowInstance($autoplaylist->getDbId());
$playlistid = $si->GetAutoPlaylistId();
Logging::info("Scheduling $playlistid");
// call the addPlaylist to show function and don't check for user permission to avoid call to non-existant user object
$sid = $si->getShowId();
$playlistrepeat = new Application_Model_Show($sid);
$introplaylistid = Application_Model_Preference::GetIntroPlaylist();
$outroplaylistid = Application_Model_Preference::GetOutroPlaylist();
if ($playlistrepeat->getAutoPlaylistRepeat()) {
$full = false;
while(!$full) {
$si = new Application_Model_ShowInstance($autoplaylist->getDbId());
$si->addPlaylistToShow($playlistid, false);
$ps = $si->getPercentScheduled();
//Logging::info("The total percent scheduled is % $ps");
if ($ps > 100) {
$full = true;
}
}
}
else {
// we want to check and see if we need to repeat this process until the show is 100% scheduled
// so we create a while loop and break it immediately if repeat until full isn't enabled
// otherwise we continue to go through adding playlists, including the intro and outro if enabled
$full = false;
$repeatuntilfull = $playlistrepeat->getAutoPlaylistRepeat();
while(!$full) {
$si = new Application_Model_ShowInstance($autoplaylist->getDbId());
$si->addPlaylistToShow($playlistid, false);
$ps = $si->getPercentScheduled();
//Logging::info($ps);
if ($introplaylistid != null) {
//Logging::info('adding intro');
$si->addPlaylistToShowStart($introplaylistid, false);
}
if ($outroplaylistid != null) {
//Logging::info('adding outro');
$si->addPlaylistToShow($outroplaylistid, false);
//Logging::info("The total percent scheduled is % $ps");
}
if ($ps > 100) {
$full = true;
}
elseif (!$repeatuntilfull) {
break;
}
}
$si->setAutoPlaylistBuilt(true);

View File

@ -47,6 +47,8 @@ class PreferenceController extends Zend_Controller_Action
Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]);
Application_Model_Preference::SetPodcastAlbumOverride($values["podcastAlbumOverride"]);
Application_Model_Preference::SetPodcastAutoSmartblock($values["podcastAutoSmartblock"]);
Application_Model_Preference::SetIntroPlaylist($values["introPlaylistSelect"]);
Application_Model_Preference::SetOutroPlaylist($values["outroPlaylistSelect"]);
Application_Model_Preference::SetAllow3rdPartyApi($values["thirdPartyApi"]);
Application_Model_Preference::SetAllowedCorsUrls($values["allowedCorsUrls"]);
Application_Model_Preference::SetDefaultLocale($values["locale"]);

View File

@ -101,6 +101,21 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
));
// add intro playlist select here
$introPlaylistSelect = new Zend_Form_Element_Select("introPlaylistSelect");
$introPlaylistSelect->setLabel(_("Intro Autoloading Playlist"));
$introPlaylistSelect->setMultiOptions(Application_Model_Library::getPlaylistNames(true));
$introPlaylistSelect->setValue(Application_Model_Preference::GetIntroPlaylist());
$this->addElement($introPlaylistSelect);
$outroPlaylistSelect = new Zend_Form_Element_Select("outroPlaylistSelect");
$outroPlaylistSelect->setLabel(_("Outro Autoloading Playlist"));
$outroPlaylistSelect->setMultiOptions(Application_Model_Library::getPlaylistNames(true));
$outroPlaylistSelect->setValue(Application_Model_Preference::GetOutroPlaylist());
$this->addElement($outroPlaylistSelect);
$podcast_album_override = new Zend_Form_Element_Radio('podcastAlbumOverride');
$podcast_album_override->setLabel(_('Podcast Metadata Override'));
$podcast_album_override->setMultiOptions(array(

View File

@ -1776,7 +1776,6 @@ SQL;
// construct limit restriction
$limits = array();
if (isset($storedCrit['limit'])) {
if ($storedCrit['limit']['modifier'] == "items") {
$limits['time'] = 1440 * 60;

View File

@ -387,6 +387,26 @@ class Application_Model_Preference
return $val === '1' ? true : false;
}
public static function GetIntroPlaylist()
{
return self::getValue("intro_playlist");
}
public static function GetOutroPlaylist()
{
return self::getValue("outro_playlist");
}
public static function SetIntroPlaylist($playlist)
{
self::setValue("intro_playlist", $playlist);
}
public static function SetOutroPlaylist($playlist)
{
self::setValue("outro_playlist", $playlist);
}
public static function SetPhone($phone)
{

View File

@ -214,7 +214,6 @@ final class Application_Model_Scheduler
private function retrieveMediaFiles($id, $type, $show)
{
$files = array();
if ($type === "audioclip") {
$file = CcFilesQuery::create()->findPK($id, $this->con);

View File

@ -242,9 +242,30 @@ SQL;
array(array("id" => $lastid, "instance" => $id, "timestamp" => $ts)),
array(array("id" => $pl_id, "type" => "playlist"))
);
// doing this to update the database schedule so that subsequent adds will work.
$con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME);
$this->_showInstance->updateScheduleStatus($con);
}
/**
* Add a playlist as the first item of the current show.
*
* @param int $plId
* Playlist ID.
*/
public function addPlaylistToShowStart($pl_id, $checkUserPerm = true)
{
$ts = intval($this->_showInstance->getDbLastScheduled("U")) ? : 0;
$id = $this->_showInstance->getDbId();
$scheduler = new Application_Model_Scheduler($checkUserPerm);
$scheduler->scheduleAfter(
array(array("id" => 0, "instance" => $id, "timestamp" => $ts)),
array(array("id" => $pl_id, "type" => "playlist"))
);
// doing this to update the database schedule so that subsequent adds will work.
$con = Propel::getConnection(CcShowInstancesPeer::DATABASE_NAME);
$this->_showInstance->updateScheduleStatus($con);
}
/**

View File

@ -31,6 +31,10 @@
<?php echo $this->element->getElement('stationDefaultCrossfadeDuration')->render() ?>
<?php echo $this->element->getElement('introPlaylistSelect')->render() ?>
<?php echo $this->element->getElement('outroPlaylistSelect')->render() ?>
<?php echo $this->element->getElement('podcastAlbumOverride')->render() ?>
<?php echo $this->element->getElement('podcastAutoSmartblock')->render() ?>