diff --git a/airtime_mvc/application/controllers/DashboardController.php b/airtime_mvc/application/controllers/DashboardController.php index 311210006..d88eb760c 100644 --- a/airtime_mvc/application/controllers/DashboardController.php +++ b/airtime_mvc/application/controllers/DashboardController.php @@ -65,14 +65,18 @@ class DashboardController extends Zend_Controller_Action Application_Model_RabbitMq::SendMessageToPypo("switch_source", $data); if(strtolower($current_status) == "on"){ Application_Model_Preference::SetSourceSwitchStatus($sourcename, "off"); + $this->view->status = "OFF"; + + //Log table updates Application_Model_LiveLog::SetEndTime($sourcename == 'scheduled_play'?'S':'L', new DateTime("now", new DateTimeZone('UTC'))); - $this->view->status = "OFF"; }else{ Application_Model_Preference::SetSourceSwitchStatus($sourcename, "on"); + $this->view->status = "ON"; + + //Log table updates Application_Model_LiveLog::SetNewLogTime($sourcename == 'scheduled_play'?'S':'L', new DateTime("now", new DateTimeZone('UTC'))); - $this->view->status = "ON"; } } else{ diff --git a/airtime_mvc/application/models/LiveLog.php b/airtime_mvc/application/models/LiveLog.php index bf1490155..24130a6dc 100644 --- a/airtime_mvc/application/models/LiveLog.php +++ b/airtime_mvc/application/models/LiveLog.php @@ -7,7 +7,8 @@ class Application_Model_LiveLog try { $con = Propel::getConnection(); - $data = self::GetNumLogs(); + $rows = self::GetNumLogs(); + Logging::log($rows); if ($data['count'] > 1) { $sql = "SELECT * FROM CC_LIVE_LOG" ." WHERE state = 'L'" @@ -78,13 +79,14 @@ class Application_Model_LiveLog public static function GetNumLogs() { try { $con = Propel::getConnection(); - + /* $sql = "SELECT count(*), state FROM CC_LIVE_LOG" ." WHERE (start_time >= (now() - INTERVAL '1 day'))" ." GROUP BY state"; - $row = $con->query($sql)->fetch(); - return $result; + $rows = $con->query($sql)->fetchAll(); + return $rows; + */ } catch (Exception $e) { header('HTTP/1.0 503 Service Unavailable'); @@ -97,10 +99,24 @@ class Application_Model_LiveLog try { $con = Propel::getConnection(); - $sql = "INSERT INTO CC_LIVE_LOG (state, start_time)" - ." VALUES ('$state', '{$dateTime->format("Y-m-d H:i:s")}')"; - - $con->exec($sql); + if ($state == 'L') { + self::SetEndTime('S', $dateTime); + } + + /* Check if airtime is currently broadcasting live. + * Only insert new state if scheduled switch is on + * or live broadcasting is off + */ + $sql_select = "SELECT max(id) from CC_LIVE_LOG" + ." WHERE state='L' and end_time is NULL"; + $id = $con->query($sql_select)->fetchColumn(0); + + if ($id == null) { + + $sql_insert = "INSERT INTO CC_LIVE_LOG (state, start_time)" + ." VALUES ('$state', '{$dateTime->format("Y-m-d H:i:s")}')"; + $con->exec($sql_insert); + } } catch (Exception $e) { header('HTTP/1.0 503 Service Unavailable'); @@ -113,15 +129,31 @@ class Application_Model_LiveLog try { $con = Propel::getConnection(); - $sql = "SELECT max(id) FROM CC_LIVE_LOG" - ." WHERE state = '$state'"; - - $id = $con->query($sql)->fetchColumn(0); + if ($state == 'L') { + $dj_live = Application_Model_Preference::GetSourceSwitchStatus('live_dj'); + $master_live = Application_Model_Preference::GetSourceSwitchStatus('master_dj'); + } - $update_sql = "UPDATE CC_LIVE_LOG" - ." SET end_time = '{$dateTime->format("Y-m-d H:i:s")}'" - ." WHERE id = '$id'"; - $con->exec($update_sql); + if (($dj_live=='off' && $master_live=='off') || $state == 'S') { + $sql = "SELECT max(id) FROM CC_LIVE_LOG" + ." WHERE state = '$state'" + ." UNION" + ." SELECT max(id) FROM CC_LIVE_LOG"; + $row = $con->query($sql)->fetch(); + + if ($row != null && $row['max'] == $row[0]) { + $update_sql = "UPDATE CC_LIVE_LOG" + ." SET end_time = '{$dateTime->format("Y-m-d H:i:s")}'" + ." WHERE id = '$row[0]'"; + $con->exec($update_sql); + } + + //if live broadcasting is off, turn scheduled play on + $scheduled = Application_Model_Preference::GetSourceSwitchStatus('scheduled_play'); + if ($state == 'L' && $scheduled=='on') { + self::SetNewLogTime('S', $dateTime); + } + } } catch (Exception $e) { header('HTTP/1.0 503 Service Unavailable'); diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index 8f690ddcd..ee87885a8 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -415,7 +415,7 @@ class Application_Model_Preference $outputArray = array(); $outputArray['LIVE_DURATION'] = Application_Model_LiveLog::GetLiveShowDuration(); - $outputArray['SCHEDULED_DURATION'] = Application_Model_LiveLog::GetScheduledDuration(); + //$outputArray['SCHEDULED_DURATION'] = Application_Model_LiveLog::GetScheduledDuration(); $outputArray['SOUNDCLOUD_ENABLED'] = self::GetUploadToSoundcloudOption(); if ($outputArray['SOUNDCLOUD_ENABLED']) { $outputArray['NUM_SOUNDCLOUD_TRACKS_UPLOADED'] = Application_Model_StoredFile::getSoundCloudUploads();