diff --git a/airtime_mvc/application/models/Nowplaying.php b/airtime_mvc/application/models/Nowplaying.php index 870cc4e81..871b83fd9 100644 --- a/airtime_mvc/application/models/Nowplaying.php +++ b/airtime_mvc/application/models/Nowplaying.php @@ -3,16 +3,16 @@ class Application_Model_Nowplaying { - private static function CreateHeaderRow($p_showName, $p_showStart, $p_showEnd){ - return array("h", "", $p_showStart, $p_showEnd, $p_showName, "", "", "", "", "", ""); - } + private static function CreateHeaderRow($p_showName, $p_showStart, $p_showEnd){ + return array("h", "", $p_showStart, $p_showEnd, $p_showName, "", "", "", "", "", ""); + } - private static function CreateDatatableRows($p_dbRows){ + private static function CreateDatatableRows($p_dbRows){ $dataTablesRows = array(); $epochNow = time(); - foreach ($p_dbRows as $dbRow){ + foreach ($p_dbRows as $dbRow) { $showStartDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($dbRow['show_starts']); $showEndDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($dbRow['show_ends']); @@ -43,24 +43,24 @@ class Application_Model_Nowplaying $dbRow['playlist_name'], $dbRow['show_name'], $status); } - return $dataTablesRows; - } + return $dataTablesRows; + } - private static function CreateGapRow($p_gapTime){ - return array("g", "", "", "", $p_gapTime, "", "", "", "", "", ""); - } + private static function CreateGapRow($p_gapTime){ + return array("g", "", "", "", $p_gapTime, "", "", "", "", "", ""); + } - private static function CreateRecordingRow($p_showInstance){ - return array("r", "", "", "", $p_showInstance->getName(), "", "", "", "", "", ""); - } + private static function CreateRecordingRow($p_showInstance){ + return array("r", "", "", "", $p_showInstance->getName(), "", "", "", "", "", ""); + } - public static function GetDataGridData($viewType, $dateString){ + public static function GetDataGridData($viewType, $dateString){ if ($viewType == "now"){ $dateTime = new DateTime("now", new DateTimeZone("UTC")); $timeNow = $dateTime->format("Y-m-d H:i:s"); - $startCutoff = 60; + $startCutoff = 60; $endCutoff = 86400; //60*60*24 - seconds in a day } else { $date = new Application_Model_DateHelper; @@ -75,21 +75,22 @@ class Application_Model_Nowplaying $data = array(); $showIds = Application_Model_ShowInstance::GetShowsInstancesIdsInRange($timeNow, $startCutoff, $endCutoff); - - //get all the pieces to be played between the start cut off and the end cut off. - $scheduledItems = Application_Model_ShowInstance::getScheduleItemsForAllShowsInRange($timeNow, $startCutoff, $endCutoff); - $orderedScheduledItems; - foreach ($scheduledItems as $scheduledItem){ - $orderedScheduledItems[$scheduledItem['instance_id']][] = $scheduledItem; - } - + + //get all the pieces to be played between the start cut off and the end cut off. + $scheduledItems = Application_Model_Schedule::getScheduleItemsInRange($timeNow, $startCutoff, $endCutoff); + + $orderedScheduledItems; + foreach ($scheduledItems as $scheduledItem){ + $orderedScheduledItems[$scheduledItem['instance_id']][] = $scheduledItem; + } + foreach ($showIds as $showId){ $instanceId = $showId['id']; - //gets the show information + //gets the show information $si = new Application_Model_ShowInstance($instanceId); - $showId = $si->getShowId(); + $showId = $si->getShowId(); $show = new Application_Model_Show($showId); $showStartDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($si->getShowInstanceStart()); @@ -106,73 +107,9 @@ class Application_Model_Nowplaying //append show gap time row $gapTime = self::FormatDuration($si->getShowEndGapTime(), true); if ($si->isRecorded()) - $data[] = self::CreateRecordingRow($si); + $data[] = self::CreateRecordingRow($si); else if ($gapTime > 0) - $data[] = self::CreateGapRow($gapTime); - } - - $rows = Application_Model_Show::GetCurrentShow($timeNow); - Application_Model_Show::ConvertToLocalTimeZone($rows, array("starts", "ends", "start_timestamp", "end_timestamp")); - return array("currentShow"=>$rows, "rows"=>$data); - } - - public static function GetDataGridDataOLD($viewType, $dateString){ - - if ($viewType == "now"){ - $dateTime = new DateTime("now", new DateTimeZone("UTC")); - $timeNow = $dateTime->format("Y-m-d H:i:s"); - - $startCutoff = 60; - //$endCutoff = 2592000; // 30 days - //$endCutoff = 604800; // 7 days - $endCutoff = 259200; // 3 days - //$endCutoff = 86400; //60*60*24 - seconds in a day - } else { - $date = new Application_Model_DateHelper; - $time = $date->getTime(); - $date->setDate($dateString." ".$time); - $timeNow = $date->getUtcTimestamp(); - - $startCutoff = $date->getNowDayStartDiff(); - $endCutoff = $date->getNowDayEndDiff(); - } - - $data = array(); - - $showIds = Application_Model_ShowInstance::GetShowsInstancesIdsInRange($timeNow, $startCutoff, $endCutoff); -//Logging::log(print_r($showIds, true)); - - foreach ($showIds as $showId){ - $instanceId = $showId['id']; - - //gets the show information - $si = new Application_Model_ShowInstance($instanceId); -//Logging::log(print_r($si, true)); - - $showId = $si->getShowId(); - $show = new Application_Model_Show($showId); -//Logging::log(print_r($show, true)); - - $showStartDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($si->getShowInstanceStart()); - $showEndDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($si->getShowInstanceEnd()); - - //append show header row - $data[] = self::CreateHeaderRow($show->getName(), $showStartDateTime->format("Y-m-d H:i:s"), $showEndDateTime->format("Y-m-d H:i:s")); - - $scheduledItems = $si->getScheduleItemsInRange($timeNow, $startCutoff, $endCutoff); -//Logging::log(print_r($scheduledItems, true)); - $dataTablesRows = self::CreateDatatableRows($scheduledItems); -//Logging::log(print_r($dataTablesRows, true)); - - //append show audio item rows - $data = array_merge($data, $dataTablesRows); - - //append show gap time row - $gapTime = self::FormatDuration($si->getShowEndGapTime(), true); - if ($si->isRecorded()) - $data[] = self::CreateRecordingRow($si); - else if ($gapTime > 0) - $data[] = self::CreateGapRow($gapTime); + $data[] = self::CreateGapRow($gapTime); } $rows = Application_Model_Show::GetCurrentShow($timeNow); diff --git a/airtime_mvc/application/models/Schedule.php b/airtime_mvc/application/models/Schedule.php index 725578348..b6e8317d2 100644 --- a/airtime_mvc/application/models/Schedule.php +++ b/airtime_mvc/application/models/Schedule.php @@ -276,24 +276,59 @@ class Application_Model_Schedule { ." WHERE st.starts < si.ends"; if ($timePeriod < 0){ - $sql .= " AND st.ends < TIMESTAMP '$timeStamp'" - ." AND st.ends > (TIMESTAMP '$timeStamp' - INTERVAL '$interval')" - ." ORDER BY st.starts DESC" - ." LIMIT $count"; - } else if ($timePeriod == 0){ - $sql .= " AND st.starts <= TIMESTAMP '$timeStamp'" - ." AND st.ends >= TIMESTAMP '$timeStamp'"; - } else if ($timePeriod > 0){ - $sql .= " AND st.starts > TIMESTAMP '$timeStamp'" - ." AND st.starts < (TIMESTAMP '$timeStamp' + INTERVAL '$interval')" - ." ORDER BY st.starts" - ." LIMIT $count"; - } + $sql .= " AND st.ends < TIMESTAMP '$timeStamp'" + ." AND st.ends > (TIMESTAMP '$timeStamp' - INTERVAL '$interval')" + ." ORDER BY st.starts DESC" + ." LIMIT $count"; + } else if ($timePeriod == 0){ + $sql .= " AND st.starts <= TIMESTAMP '$timeStamp'" + ." AND st.ends >= TIMESTAMP '$timeStamp'"; + } else if ($timePeriod > 0){ + $sql .= " AND st.starts > TIMESTAMP '$timeStamp'" + ." AND st.starts < (TIMESTAMP '$timeStamp' + INTERVAL '$interval')" + ." ORDER BY st.starts" + ." LIMIT $count"; + } $rows = $CC_DBC->GetAll($sql); return $rows; - } + } + + public static function getScheduleItemsInRange($timeNow, $start, $end) + { + global $CC_DBC, $CC_CONFIG; + + $sql = "SELECT" + ." si.starts as show_starts," + ." si.ends as show_ends," + ." si.rebroadcast as rebroadcast," + ." st.starts as item_starts," + ." st.ends as item_ends," + ." st.clip_length as clip_length," + ." ft.track_title as track_title," + ." ft.artist_name as artist_name," + ." ft.album_title as album_title," + ." s.name as show_name," + ." si.id as instance_id," + ." pt.name as playlist_name" + ." FROM ".$CC_CONFIG["showInstances"]." si" + ." LEFT JOIN ".$CC_CONFIG[scheduleTable]." st" + ." ON st.instance_id = si.id" + ." LEFT JOIN ".$CC_CONFIG[playListTable]." pt" + ." ON st.playlist_id = pt.id" + ." LEFT JOIN ".$CC_CONFIG[filesTable]." ft" + ." ON st.file_id = ft.id" + ." LEFT JOIN ".$CC_CONFIG[showTable]." s" + ." ON si.show_id = s.id" + ." WHERE ((si.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')" + ." OR (si.starts > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')" + ." OR (si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds' AND si.ends > TIMESTAMP '$timeNow' + INTERVAL '$end seconds'))" + ." AND (st.starts < si.ends)" + ." ORDER BY si.id, si.starts, st.starts"; + + return $CC_DBC->GetAll($sql); + } public static function GetShowInstanceItems($instance_id) { global $CC_CONFIG, $CC_DBC; @@ -322,7 +357,7 @@ class Application_Model_Schedule { } public static function getSchduledPlaylistCount(){ - global $CC_CONFIG, $CC_DBC; + global $CC_CONFIG, $CC_DBC; $sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG['scheduleTable']; return $CC_DBC->GetOne($sql); } @@ -535,16 +570,16 @@ class Application_Model_Schedule { $isSaas = Application_Model_Preference::GetPlanLevel() == 'disabled'?false:true; $formWhat = new Application_Form_AddShowWhat(); - $formWho = new Application_Form_AddShowWho(); - $formWhen = new Application_Form_AddShowWhen(); - $formRepeats = new Application_Form_AddShowRepeats(); - $formStyle = new Application_Form_AddShowStyle(); + $formWho = new Application_Form_AddShowWho(); + $formWhen = new Application_Form_AddShowWhen(); + $formRepeats = new Application_Form_AddShowRepeats(); + $formStyle = new Application_Form_AddShowStyle(); - $formWhat->removeDecorator('DtDdWrapper'); - $formWho->removeDecorator('DtDdWrapper'); - $formWhen->removeDecorator('DtDdWrapper'); - $formRepeats->removeDecorator('DtDdWrapper'); - $formStyle->removeDecorator('DtDdWrapper'); + $formWhat->removeDecorator('DtDdWrapper'); + $formWho->removeDecorator('DtDdWrapper'); + $formWhen->removeDecorator('DtDdWrapper'); + $formRepeats->removeDecorator('DtDdWrapper'); + $formStyle->removeDecorator('DtDdWrapper'); $p_view->what = $formWhat; $p_view->when = $formWhen; @@ -555,12 +590,12 @@ class Application_Model_Schedule { $formWhat->populate(array('add_show_id' => '-1')); $formWhen->populate(array('add_show_start_date' => date("Y-m-d"), 'add_show_start_time' => '00:00', - 'add_show_end_date_no_repeate' => date("Y-m-d"), - 'add_show_end_time' => '01:00', + 'add_show_end_date_no_repeate' => date("Y-m-d"), + 'add_show_end_time' => '01:00', 'add_show_duration' => '1h')); - $formRepeats->populate(array('add_show_end_date' => date("Y-m-d"))); - + $formRepeats->populate(array('add_show_end_date' => date("Y-m-d"))); + if(!$isSaas){ $formRecord = new Application_Form_AddShowRR(); $formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates(); @@ -576,5 +611,4 @@ class Application_Model_Schedule { } $p_view->addNewShow = true; } -} - +} \ No newline at end of file diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 7e11b3584..0fbaa4666 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -756,42 +756,6 @@ class Application_Model_ShowInstance { return $CC_DBC->GetAll($sql); } - - - public static function getScheduleItemsForAllShowsInRange($timeNow, $start, $end) - { - global $CC_DBC, $CC_CONFIG; - - $sql = "SELECT" - ." si.starts as show_starts," - ." si.ends as show_ends," - ." si.rebroadcast as rebroadcast," - ." st.starts as item_starts," - ." st.ends as item_ends," - ." st.clip_length as clip_length," - ." ft.track_title as track_title," - ." ft.artist_name as artist_name," - ." ft.album_title as album_title," - ." s.name as show_name," - ." si.id as instance_id," - ." pt.name as playlist_name" - ." FROM $CC_CONFIG[showInstances] si" - ." LEFT JOIN $CC_CONFIG[scheduleTable] st" - ." ON st.instance_id = si.id" - ." LEFT JOIN $CC_CONFIG[playListTable] pt" - ." ON st.playlist_id = pt.id" - ." LEFT JOIN $CC_CONFIG[filesTable] ft" - ." ON st.file_id = ft.id" - ." LEFT JOIN $CC_CONFIG[showTable] s" - ." ON si.show_id = s.id" - ." WHERE ((si.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')" - ." OR (si.starts > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')" - ." OR (si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds' AND si.ends > TIMESTAMP '$timeNow' + INTERVAL '$end seconds'))" - ." AND (st.starts < si.ends)" - ." ORDER BY si.id, si.starts, st.starts"; - - return $CC_DBC->GetAll($sql); - } public function getLastAudioItemEnd(){ global $CC_DBC;