From 6f7c2f2cc95e7b7b59fad830d6c139188f088f42 Mon Sep 17 00:00:00 2001 From: Robbt Date: Sat, 9 Feb 2019 10:58:00 -0500 Subject: [PATCH] refactored autoplaylist and updated showinstance to make sequential adds possible --- .../common/AutoPlaylistManager.php | 54 +++++++------------ .../application/models/ShowInstance.php | 6 +++ 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/airtime_mvc/application/common/AutoPlaylistManager.php b/airtime_mvc/application/common/AutoPlaylistManager.php index 47b0c188c..7e052087e 100644 --- a/airtime_mvc/application/common/AutoPlaylistManager.php +++ b/airtime_mvc/application/common/AutoPlaylistManager.php @@ -23,58 +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(); - Logging::info("intro"); - Logging::info($introplaylistid); - Logging::info($playlistid); - Logging::info("outro"); $outroplaylistid = Application_Model_Preference::GetOutroPlaylist(); - Logging::info($outroplaylistid); - if ($playlistrepeat->getAutoPlaylistRepeat()) { - $full = false; - while(!$full) { - $si = new Application_Model_ShowInstance($autoplaylist->getDbId()); - $ps = $si->getPercentScheduled(); - if ($introplaylistid != null) { - sleep(20); - Logging::info('adding intro'); - $si->addPlaylistToShowStart($introplaylistid, false); - } - if ($outroplaylistid != null) { - sleep(20); - Logging::info('adding outro'); - $si->addPlaylistToShow($outroplaylistid, false); - //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) { - sleep(20); - Logging::info('adding intro'); + //Logging::info('adding intro'); $si->addPlaylistToShowStart($introplaylistid, false); } if ($outroplaylistid != null) { - sleep(20); - Logging::info('adding outro'); + //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); diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index a2a873df2..1cb7e8057 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -242,6 +242,9 @@ 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); } /** @@ -259,6 +262,9 @@ SQL; 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); }