refactored autoplaylist and updated showinstance to make sequential adds possible

This commit is contained in:
Robbt 2019-02-09 10:58:00 -05:00
parent 8de94a670f
commit 6f7c2f2cc9
2 changed files with 26 additions and 34 deletions

View file

@ -23,59 +23,45 @@ class AutoPlaylistManager {
* *
*/ */
public static function buildAutoPlaylist() { public static function buildAutoPlaylist() {
Logging::info("Checking to run Auto Playlist"); //Logging::info("Checking to run Auto Playlist");
$autoPlaylists = static::_upcomingAutoPlaylistShows(); $autoPlaylists = static::_upcomingAutoPlaylistShows();
foreach ($autoPlaylists as $autoplaylist) { foreach ($autoPlaylists as $autoplaylist) {
// creates a ShowInstance object to build the playlist in from the ShowInstancesQuery Object // creates a ShowInstance object to build the playlist in from the ShowInstancesQuery Object
$si = new Application_Model_ShowInstance($autoplaylist->getDbId()); $si = new Application_Model_ShowInstance($autoplaylist->getDbId());
$playlistid = $si->GetAutoPlaylistId(); $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 // call the addPlaylist to show function and don't check for user permission to avoid call to non-existant user object
$sid = $si->getShowId(); $sid = $si->getShowId();
$playlistrepeat = new Application_Model_Show($sid); $playlistrepeat = new Application_Model_Show($sid);
$introplaylistid = Application_Model_Preference::GetIntroPlaylist(); $introplaylistid = Application_Model_Preference::GetIntroPlaylist();
Logging::info("intro");
Logging::info($introplaylistid);
Logging::info($playlistid);
Logging::info("outro");
$outroplaylistid = Application_Model_Preference::GetOutroPlaylist(); $outroplaylistid = Application_Model_Preference::GetOutroPlaylist();
Logging::info($outroplaylistid);
if ($playlistrepeat->getAutoPlaylistRepeat()) { // 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; $full = false;
$repeatuntilfull = $playlistrepeat->getAutoPlaylistRepeat();
while(!$full) { while(!$full) {
$si = new Application_Model_ShowInstance($autoplaylist->getDbId()); $si = new Application_Model_ShowInstance($autoplaylist->getDbId());
$si->addPlaylistToShow($playlistid, false);
$ps = $si->getPercentScheduled(); $ps = $si->getPercentScheduled();
//Logging::info($ps);
if ($introplaylistid != null) { if ($introplaylistid != null) {
sleep(20); //Logging::info('adding intro');
Logging::info('adding intro');
$si->addPlaylistToShowStart($introplaylistid, false); $si->addPlaylistToShowStart($introplaylistid, false);
} }
if ($outroplaylistid != null) { if ($outroplaylistid != null) {
sleep(20); //Logging::info('adding outro');
Logging::info('adding outro');
$si->addPlaylistToShow($outroplaylistid, false); $si->addPlaylistToShow($outroplaylistid, false);
//Logging::info("The total percent scheduled is % $ps"); //Logging::info("The total percent scheduled is % $ps");
} }
if ($ps > 100) { if ($ps > 100) {
$full = true; $full = true;
} }
elseif (!$repeatuntilfull) {
break;
}
} }
}
else {
$si->addPlaylistToShow($playlistid, false);
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);
}
}
$si->setAutoPlaylistBuilt(true); $si->setAutoPlaylistBuilt(true);
} }

View file

@ -242,6 +242,9 @@ SQL;
array(array("id" => $lastid, "instance" => $id, "timestamp" => $ts)), array(array("id" => $lastid, "instance" => $id, "timestamp" => $ts)),
array(array("id" => $pl_id, "type" => "playlist")) 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" => 0, "instance" => $id, "timestamp" => $ts)),
array(array("id" => $pl_id, "type" => "playlist")) 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);
} }