diff --git a/LICENSE_3RD_PARTY b/LICENSE_3RD_PARTY index e48f0b314..7096a6f55 100644 --- a/LICENSE_3RD_PARTY +++ b/LICENSE_3RD_PARTY @@ -8,7 +8,7 @@ Common Non-linked Code - Web site: https://github.com/torvalds/linux - License: GPLv2 - * RabbitMQ (works with version 1.7.2 and above) + * RabbitMQ - What is it: Interprocess Message Passing with Queuing - Web site: http://www.rabbitmq.com/ - License: Mozilla Public License (http://www.rabbitmq.com/mpl.html) @@ -63,11 +63,11 @@ Non-linked code: - Web site: http://httpd.apache.org/ - License: Apache 2.0. See http://httpd.apache.org/docs/2.2/license.html - * PostgreSQL 8.4 + * PostgreSQL 9.1 - Web site: http://www.postgresql.org/ - License: The PostgreSQL License. See http://www.postgresql.org/about/licence - * PHP 5.3 + * PHP 5.3 - Web site: http://www.php.net/ - License: The PHP License. See http://www.php.net/license/3_01.txt @@ -137,7 +137,7 @@ Linked code: - License: MIT Non-linked code: - * Python 2.6 + * Python 2.7 - Web site: http://www.python.org/ - License: PSF License. See http://docs.python.org/license.html @@ -158,11 +158,11 @@ Linked code: - Compatible with GPLv3? Yes. Non-linked code: - * Python 2.6 + * Python 2.7 - Web site: http://www.python.org/ - License: PSF License. See http://docs.python.org/license.html - * ecasound 2.7.2 + * ecasound 2.8.1 - What is it: Records audio from line-in - Web site: http://www.eca.cx/ecasound/ - License: GPLv2 @@ -177,10 +177,10 @@ Linked code: - Compatible with GPLv3? Yes. Non-linked code: - * Python 2.6 + * Python 2.7 - Web site: http://www.python.org/ - License: PSF License. See http://docs.python.org/license.html - * Liquidsoap 1.0.1 + * Liquidsoap 1.1.1 - Web site: http://savonet.sourceforge.net/ - License: GPLv2 diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 63c24d14a..6c16dc07a 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -209,6 +209,43 @@ class ApiController extends Zend_Controller_Action } } + public function onAirLightAction() + { + $this->view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + $result = array(); + $result["on_air_light"] = false; + $result["on_air_light_expected_status"] = false; + $result["station_down"] = false; + + $range = Application_Model_Schedule::GetPlayOrderRange(); + + $isItemCurrentlyScheduled = !is_null($range["current"]) && count($range["currentShow"]) > 0 ? true : false; + + $isCurrentItemPlaying = $range["current"]["media_item_played"] ? true : false; + + if ($isItemCurrentlyScheduled || + Application_Model_Preference::GetSourceSwitchStatus("live_dj") == "on" || + Application_Model_Preference::GetSourceSwitchStatus("master_dj") == "on") + { + $result["on_air_light_expected_status"] = true; + } + + if (($isItemCurrentlyScheduled && $isCurrentItemPlaying) || + Application_Model_Preference::GetSourceSwitchStatus("live_dj") == "on" || + Application_Model_Preference::GetSourceSwitchStatus("master_dj") == "on") + { + $result["on_air_light"] = true; + } + + if ($result["on_air_light_expected_status"] != $result["on_air_light"]) { + $result["station_down"] = true; + } + + echo isset($_GET['callback']) ? $_GET['callback'].'('.json_encode($result).')' : json_encode($result); + } + /** * Retrieve the currently playing show as well as upcoming shows. * Number of shows returned and the time interval in which to diff --git a/airtime_mvc/application/controllers/ListenerstatController.php b/airtime_mvc/application/controllers/ListenerstatController.php index bb280378d..3ec495839 100644 --- a/airtime_mvc/application/controllers/ListenerstatController.php +++ b/airtime_mvc/application/controllers/ListenerstatController.php @@ -9,36 +9,36 @@ class ListenerstatController extends Zend_Controller_Action ->addActionContext('get-data', 'json') ->initContext(); } - + public function indexAction() { $CC_CONFIG = Config::getConfig(); - + $request = $this->getRequest(); $baseUrl = Application_Common_OsPath::getBaseDir(); - + $this->view->headScript()->appendFile($baseUrl.'js/flot/jquery.flot.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/flot/jquery.flot.crosshair.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/listenerstat/listenerstat.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - + $offset = date("Z") * -1; $this->view->headScript()->appendScript("var serverTimezoneOffset = {$offset}; //in seconds"); $this->view->headScript()->appendFile($baseUrl.'js/timepicker/jquery.ui.timepicker.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/utilities/utilities.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - + $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']); - + //default time is the last 24 hours. $now = time(); $from = $request->getParam("from", $now - (24*60*60)); $to = $request->getParam("to", $now); - + $start = DateTime::createFromFormat("U", $from, new DateTimeZone("UTC")); $start->setTimezone(new DateTimeZone(date_default_timezone_get())); $end = DateTime::createFromFormat("U", $to, new DateTimeZone("UTC")); $end->setTimezone(new DateTimeZone(date_default_timezone_get())); - + $form = new Application_Form_DateRange(); $form->populate(array( 'his_date_start' => $start->format("Y-m-d"), @@ -46,7 +46,7 @@ class ListenerstatController extends Zend_Controller_Action 'his_date_end' => $end->format("Y-m-d"), 'his_time_end' => $end->format("H:i") )); - + $errorStatus = Application_Model_StreamSetting::GetAllListenerStatErrors(); Logging::info($errorStatus); $out = array(); @@ -57,25 +57,24 @@ class ListenerstatController extends Zend_Controller_Action } $out[$key[0]] = $v['value']; } - + $this->view->errorStatus = $out; $this->view->date_form = $form; } - + public function getDataAction(){ $request = $this->getRequest(); $current_time = time(); - + $params = $request->getParams(); - + $starts_epoch = $request->getParam("startTimestamp", $current_time - (60*60*24)); $ends_epoch = $request->getParam("endTimestamp", $current_time); - $mountName = $request->getParam("mountName", null); - + $startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC")); $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); - - $data = Application_Model_ListenerStat::getDataPointsWithinRange($startsDT->format("Y-m-d H:i:s"), $endsDT->format("Y-m-d H:i:s"), $mountName); - $this->_helper->json->sendJson($data); + + $data = Application_Model_ListenerStat::getDataPointsWithinRange($startsDT->format("Y-m-d H:i:s"), $endsDT->format("Y-m-d H:i:s")); + $this->_helper->json->sendJson($data); } } diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index cd588a215..52ea8d86d 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -5,7 +5,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm private $stringCriteriaOptions; private $numericCriteriaOptions; private $limitOptions; - + /* We need to know if the criteria value will be a string * or numeric value in order to populate the modifier * select list @@ -40,7 +40,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm "info_url" => "s", "year" => "n" ); - + private function getCriteriaOptions($option = null) { if (!isset($this->criteriaOptions)) { @@ -75,7 +75,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm "year" => _("Year") ); } - + if (is_null($option)) return $this->criteriaOptions; else return $this->criteriaOptions[$option]; } @@ -122,7 +122,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm } return $this->limitOptions; } - + public function init() { @@ -259,7 +259,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $repeatTracks->setChecked($storedCrit["repeat_tracks"]["value"] == 1?true:false); } $this->addElement($repeatTracks); - + $limit = new Zend_Form_Element_Select('sp_limit_options'); $limit->setAttrib('class', 'sp_input_select') ->setDecorators(array('viewHelper')) @@ -268,7 +268,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $limit->setValue($storedCrit["limit"]["modifier"]); } $this->addElement($limit); - + $limitValue = new Zend_Form_Element_Text('sp_limit_value'); $limitValue->setAttrib('class', 'sp_input_text_limit') ->setLabel(_('Limit to')) @@ -541,7 +541,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $isValid = false; } // length check - if (intval($d['sp_criteria_value']) >= pow(2,31)) { + if ($d['sp_criteria_value'] >= pow(2,31)) { $element->addError(_("The value should be less then 2147483648")); $isValid = false; } diff --git a/airtime_mvc/application/models/ListenerStat.php b/airtime_mvc/application/models/ListenerStat.php index 52360c55a..69560b320 100644 --- a/airtime_mvc/application/models/ListenerStat.php +++ b/airtime_mvc/application/models/ListenerStat.php @@ -4,7 +4,7 @@ class Application_Model_ListenerStat public function __construct() { } - + public static function getDataPointsWithinRange($p_start, $p_end) { $sql = <<$p_start, 'p2'=>$p_end)); - + $out = array(); foreach ($data as $d) { $jump = intval($d['count']/1000); $jump = max(1, $jump); $remainder = $jump == 1?0:1; - + $sql = <<setTimezone(new DateTimeZone(date_default_timezone_get())); // tricking javascript so it thinks the server timezone is in UTC $dt = new DateTime($t->format("Y-m-d H:i:s"), new DateTimeZone("UTC")); - + $r['timestamp'] = $dt->format("U"); $out[$r['mount_name']][] = $r; } } - + $enabledStreamIds = Application_Model_StreamSetting::getEnabledStreamIds(); $enabledOut = array(); - + foreach ($enabledStreamIds as $sId) { - + $sql = "SELECT value FROM cc_stream_setting" ." WHERE keyname = :key"; - + $result = Application_Common_Database::prepareAndExecute($sql, array('key' => $sId."_mount"), "single"); - + $enabledMountPoint = $result["value"]; - + if (isset($out[$enabledMountPoint])) { $enabledOut[$enabledMountPoint] = $out[$enabledMountPoint]; } + else { + //TODO fix this hack (here for CC-5254) + //all shoutcast streams are automatically put under "shoutcast" mount point. + if (isset($out["shoutcast"])) { + $enabledOut["shoutcast"] = $out["shoutcast"]; + } + } } - + return $enabledOut; } diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php index c62fed647..661df065b 100644 --- a/airtime_mvc/application/models/Scheduler.php +++ b/airtime_mvc/application/models/Scheduler.php @@ -17,7 +17,7 @@ class Application_Model_Scheduler private $epochNow; private $nowDT; private $user; - + private $crossfadeDuration; private $checkUserPermissions = true; @@ -40,7 +40,7 @@ class Application_Model_Scheduler } $this->user = Application_Model_User::getCurrentUser(); - + $this->crossfadeDuration = Application_Model_Preference::GetDefaultCrossfadeDuration(); } @@ -200,9 +200,12 @@ class Application_Model_Scheduler } else { $data = $this->fileInfo; $data["id"] = $id; - $data["cliplength"] = Application_Model_StoredFile::getRealClipLength( - $file->getDbCuein(), - $file->getDbCueout()); + + $cuein = Application_Common_DateHelper::playlistTimeToSeconds($file->getDbCuein()); + $cueout = Application_Common_DateHelper::playlistTimeToSeconds($file->getDbCueout()); + $row_length = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein); + + $data["cliplength"] = $row_length; $data["cuein"] = $file->getDbCuein(); $data["cueout"] = $file->getDbCueout(); @@ -265,11 +268,11 @@ class Application_Model_Scheduler $cuein = Application_Common_DateHelper::calculateLengthInSeconds($data["cuein"]); $cueout = Application_Common_DateHelper::calculateLengthInSeconds($data["cueout"]); $data["cliplength"] = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein); - + //fade is in format SS.uuuuuu $data["fadein"] = $defaultFadeIn; $data["fadeout"] = $defaultFadeOut; - + $data["type"] = 0; $files[] = $data; } @@ -324,11 +327,11 @@ class Application_Model_Scheduler $cuein = Application_Common_DateHelper::calculateLengthInSeconds($data["cuein"]); $cueout = Application_Common_DateHelper::calculateLengthInSeconds($data["cueout"]); $data["cliplength"] = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein); - + //fade is in format SS.uuuuuu $data["fadein"] = $defaultFadeIn; $data["fadeout"] = $defaultFadeOut; - + $data["type"] = 0; $files[] = $data; } @@ -338,7 +341,7 @@ class Application_Model_Scheduler return $files; } - + /* * @param DateTime startDT in UTC * @param string duration @@ -349,18 +352,18 @@ class Application_Model_Scheduler private function findTimeDifference($p_startDT, $p_seconds) { $startEpoch = $p_startDT->format("U.u"); - + //add two float numbers to 6 subsecond precision //DateTime::createFromFormat("U.u") will have a problem if there is no decimal in the resulting number. $newEpoch = bcsub($startEpoch , (string) $p_seconds, 6); - + $dt = DateTime::createFromFormat("U.u", $newEpoch, new DateTimeZone("UTC")); - + if ($dt === false) { //PHP 5.3.2 problem $dt = DateTime::createFromFormat("U", intval($newEpoch), new DateTimeZone("UTC")); } - + return $dt; } @@ -420,7 +423,7 @@ class Application_Model_Scheduler return $nextDT; } - + /* * @param int $showInstance * This function recalculates the start/end times of items in a gapless show to @@ -499,7 +502,7 @@ class Application_Model_Scheduler } /** - * + * * Enter description here ... * @param $scheduleItems * cc_schedule items, where the items get inserted after @@ -882,7 +885,7 @@ class Application_Model_Scheduler private function updateMovedItem() { - + } private function getInstances($instanceId) @@ -1102,7 +1105,7 @@ class Application_Model_Scheduler } else { $removedItem->delete($this->con); } - + // update is_scheduled in cc_files but only if // the file is not scheduled somewhere else $fileId = $removedItem->getDbFileId(); diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 0c503344c..9640c36bc 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -778,17 +778,18 @@ SQL; foreach ($results['aaData'] as &$row) { $row['id'] = intval($row['id']); - $len_formatter = new LengthFormatter( - self::getRealClipLength($row["cuein"], $row["cueout"])); - $row['length'] = $len_formatter->format(); - - $cuein_formatter = new LengthFormatter($row["cuein"]); - $row["cuein"] = $cuein_formatter->format(); - - $cueout_formatter = new LengthFormatter($row["cueout"]); - $row["cueout"] = $cueout_formatter->format(); - if ($row['ftype'] === "audioclip") { + + $cuein_formatter = new LengthFormatter($row["cuein"]); + $row["cuein"] = $cuein_formatter->format(); + + $cueout_formatter = new LengthFormatter($row["cueout"]); + $row["cueout"] = $cueout_formatter->format(); + + $cuein = Application_Common_DateHelper::playlistTimeToSeconds($row["cuein"]); + $cueout = Application_Common_DateHelper::playlistTimeToSeconds($row["cueout"]); + $row_length = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein); + $formatter = new SamplerateFormatter($row['sample_rate']); $row['sample_rate'] = $formatter->format(); @@ -801,9 +802,16 @@ SQL; // for audio preview $row['audioFile'] = $row['id'].".".pathinfo($row['filepath'], PATHINFO_EXTENSION); - } else { - $row['audioFile'] = $row['id']; + } + else { + + $row['audioFile'] = $row['id']; + $row_length = $row['length']; + } + + $len_formatter = new LengthFormatter($row_length); + $row['length'] = $len_formatter->format(); //convert mtime and utime to localtime $row['mtime'] = new DateTime($row['mtime'], new DateTimeZone('UTC')); @@ -1347,14 +1355,6 @@ SQL; Application_Common_Database::prepareAndExecute($sql, array(), Application_Common_Database::EXECUTE); } - - public static function getRealClipLength($p_cuein, $p_cueout) { - $sql = "SELECT :cueout::INTERVAL - :cuein::INTERVAL"; - - return Application_Common_Database::prepareAndExecute($sql, array( - ':cueout' => $p_cueout, - ':cuein' => $p_cuein), 'column'); - } } class DeleteScheduledFileException extends Exception {} diff --git a/airtime_mvc/application/services/CalendarService.php b/airtime_mvc/application/services/CalendarService.php index b0a98174f..d0091d589 100644 --- a/airtime_mvc/application/services/CalendarService.php +++ b/airtime_mvc/application/services/CalendarService.php @@ -75,10 +75,10 @@ class Application_Service_CalendarService } } else { //Show content can be modified from the calendar if: - // the show has not ended, + // the show has not started, // the user is admin or hosting the show, // the show is not recorded - if ($now < $end && ($isAdminOrPM || $isHostOfShow) && + if ($now < $start && ($isAdminOrPM || $isHostOfShow) && !$this->ccShowInstance->isRecorded() ) { $menu["schedule"] = array( @@ -328,4 +328,4 @@ class Application_Service_CalendarService } } -} \ No newline at end of file +} diff --git a/airtime_mvc/application/services/SchedulerService.php b/airtime_mvc/application/services/SchedulerService.php index 7ab662c5c..c1dd6fc1f 100644 --- a/airtime_mvc/application/services/SchedulerService.php +++ b/airtime_mvc/application/services/SchedulerService.php @@ -248,22 +248,24 @@ class Application_Service_SchedulerService } } //foreach linked instance - $insert_sql = "INSERT INTO cc_schedule (starts, ends, ". - "clip_length, fade_in, fade_out, cue_in, cue_out, ". - "file_id, stream_id, instance_id, position) VALUES ". - implode($values, ","); + if (!empty($values)) { + $insert_sql = "INSERT INTO cc_schedule (starts, ends, ". + "clip_length, fade_in, fade_out, cue_in, cue_out, ". + "file_id, stream_id, instance_id, position) VALUES ". + implode($values, ","); - Application_Common_Database::prepareAndExecute( - $insert_sql, array(), Application_Common_Database::EXECUTE); + Application_Common_Database::prepareAndExecute( + $insert_sql, array(), Application_Common_Database::EXECUTE); - //update time_filled in cc_show_instances - $now = gmdate("Y-m-d H:i:s"); - $update_sql = "UPDATE cc_show_instances SET ". - "time_filled = '{$timeFilled}', ". - "last_scheduled = '{$now}' ". - "WHERE show_id = {$ccShow->getDbId()}"; - Application_Common_Database::prepareAndExecute( - $update_sql, array(), Application_Common_Database::EXECUTE); + //update time_filled in cc_show_instances + $now = gmdate("Y-m-d H:i:s"); + $update_sql = "UPDATE cc_show_instances SET ". + "time_filled = '{$timeFilled}', ". + "last_scheduled = '{$now}' ". + "WHERE show_id = {$ccShow->getDbId()}"; + Application_Common_Database::prepareAndExecute( + $update_sql, array(), Application_Common_Database::EXECUTE); + } } //if at least one linked instance has content } diff --git a/airtime_mvc/application/services/ShowFormService.php b/airtime_mvc/application/services/ShowFormService.php index 6b3e67239..c651c8ebd 100644 --- a/airtime_mvc/application/services/ShowFormService.php +++ b/airtime_mvc/application/services/ShowFormService.php @@ -441,7 +441,7 @@ class Application_Service_ShowFormService $rebroadcast = true; $absRebroadcast = true; - if ($formData["add_show_rebroadcast"]) { + if (isset($formData["add_show_rebroadcast"]) && $formData["add_show_rebroadcast"]) { $formData["add_show_duration"] = Application_Service_ShowService::formatShowDuration( $formData["add_show_duration"]); $absRebroadcast = $forms["abs_rebroadcast"]->isValid($formData); diff --git a/airtime_mvc/application/services/ShowService.php b/airtime_mvc/application/services/ShowService.php index f0adcbfff..2216af5f8 100644 --- a/airtime_mvc/application/services/ShowService.php +++ b/airtime_mvc/application/services/ShowService.php @@ -179,9 +179,6 @@ class Application_Service_ShowService if (is_null($this->ccShow)) { $ccShowDays = $this->getShowDaysInRange($populateUntil, $end); - if (count($ccShowDays) > 0) { - $this->ccShow = $ccShowDays[0]->getCcShow(); - } } else { $ccShowDays = $this->ccShow->getCcShowDays(); } @@ -190,7 +187,18 @@ class Application_Service_ShowService $populateUntil = $end; } + /* In case the user is moving forward in the calendar and there are + * linked shows in the schedule we need to keep track of each cc_show + * so we know which shows need to be filled with content + */ + $ccShows = array(); + foreach ($ccShowDays as $day) { + $this->ccShow = $day->getCcShow(); + if (!isset($ccShows[$day->getDbShowId()])) { + $ccShows[$day->getDbShowId()] = $day->getccShow(); + } + switch ($day->getDbRepeatType()) { case NO_REPEAT: $this->createNonRepeatingInstance($day, $populateUntil); @@ -212,9 +220,10 @@ class Application_Service_ShowService } } - if (isset($this->ccShow) && ($this->isUpdate || $fillInstances) && - $this->ccShow->isLinked()) { - Application_Service_SchedulerService::fillNewLinkedInstances($this->ccShow); + foreach ($ccShows as $ccShow) { + if (($this->isUpdate || $fillInstances) && $ccShow->isLinked()) { + Application_Service_SchedulerService::fillNewLinkedInstances($ccShow); + } } if (isset($this->linkedShowContent)) { @@ -618,29 +627,45 @@ SQL; ->filterByDbShowId($showId) ->filterByDbModifiedInstance(false) ->filterByDbRebroadcast(0) + ->orderByDbStarts() ->find(); if ($ccShowInstances->isEmpty()) { return true; } - //only 1 show instance left of the show, make it non repeating. - else if (count($ccShowInstances) === 1) { - $ccShowInstance = $ccShowInstances[0]; + /* We need to update the last_show in cc_show_days so the instances + * don't get recreated as the user moves forward in the calendar + */ + else if (count($ccShowInstances) >= 1) { + $lastShowDays = array(); + /* Creates an array where the key is the day of the week (monday, + * tuesday, etc.) and the value is the last show date for each + * day of the week. We will use this array to update the last_show + * for each cc_show_days entry of a cc_show + */ + foreach ($ccShowInstances as $instance) { + $instanceStartDT = new DateTime($instance->getDbStarts(), + new DateTimeZone("UTC")); + $lastShowDays[$instanceStartDT->format("w")] = $instanceStartDT; + } - $ccShowDay = CcShowDaysQuery::create() - ->filterByDbShowId($showId) - ->findOne(); - $tz = $ccShowDay->getDbTimezone(); + foreach ($lastShowDays as $dayOfWeek => $lastShowStartDT) { + $ccShowDay = CcShowDaysQuery::create() + ->filterByDbShowId($showId) + ->filterByDbDay($dayOfWeek) + ->findOne(); - $startDate = new DateTime($ccShowInstance->getDbStarts(), new DateTimeZone("UTC")); - $startDate->setTimeZone(new DateTimeZone($tz)); - $endDate = Application_Service_CalendarService::addDeltas($startDate, 1, 0); + if (isset($ccShowDay)) { + $lastShowStartDT->setTimeZone(new DateTimeZone( + $ccShowDay->getDbTimezone())); + $lastShowEndDT = Application_Service_CalendarService::addDeltas( + $lastShowStartDT, 1, 0); - $ccShowDay->setDbFirstShow($startDate->format("Y-m-d")); - $ccShowDay->setDbLastShow($endDate->format("Y-m-d")); - $ccShowDay->setDbStartTime($startDate->format("H:i:s")); - $ccShowDay->setDbRepeatType(-1); - $ccShowDay->save(); + $ccShowDay + ->setDbLastShow($lastShowEndDT->format("Y-m-d")) + ->save(); + } + } //remove the old repeating deleted instances. CcShowInstancesQuery::create() @@ -848,6 +873,7 @@ SQL; private function createWeeklyRepeatInstances($showDay, $populateUntil, $repeatType, $repeatInterval, $daysAdded=null) { + $show_id = $showDay->getDbShowId(); $first_show = $showDay->getDbFirstShow(); //non-UTC $last_show = $showDay->getDbLastShow(); //non-UTC @@ -870,10 +896,9 @@ SQL; $utcLastShowDateTime = $last_show ? Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null; - $utcStartDateTime = new DateTime("now"); $previousDate = clone $start; - foreach ($datePeriod as $date) { + foreach ($datePeriod as $date) { list($utcStartDateTime, $utcEndDateTime) = $this->createUTCStartEndDateTime( $date, $duration); /* @@ -887,6 +912,7 @@ SQL; ( is_null($utcLastShowDateTime) || $utcStartDateTime->format("Y-m-d H:i:s") < $utcLastShowDateTime->format("Y-m-d H:i:s")) ) { + $lastCreatedShow = clone $utcStartDateTime; /* There may not always be an instance when editing a show * This will be the case when we are adding a new show day to * a repeating show @@ -930,12 +956,19 @@ SQL; $previousDate = clone $date; } - /* Set UTC to local time before setting the next repeat date. If we don't - * the next repeat date might be scheduled for the following day + /* We need to set the next populate date for repeat shows so when a user + * moves forward in the calendar we know when to start generating new + * show instances. + * If $utcStartDateTime is not set then we know zero new shows were + * created and we shouldn't update the next populate date. */ - $utcStartDateTime->setTimezone(new DateTimeZone(Application_Model_Preference::GetTimezone())); - $nextDate = $utcStartDateTime->add($repeatInterval); - $this->setNextRepeatingShowDate($nextDate->format("Y-m-d"), $day, $show_id); + if (isset($lastCreatedShow)) { + /* Set UTC to local time before setting the next repeat date. If we don't + * the next repeat date might be scheduled for the following day */ + $lastCreatedShow->setTimezone(new DateTimeZone(Application_Model_Preference::GetTimezone())); + $nextDate = $lastCreatedShow->add($repeatInterval); + $this->setNextRepeatingShowDate($nextDate->format("Y-m-d"), $day, $show_id); + } } private function createMonthlyRepeatInstances($showDay, $populateUntil) @@ -977,6 +1010,7 @@ SQL; ( is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp()) ) { + $lastCreatedShow = clone $utcStartDateTime; /* There may not always be an instance when editing a show * This will be the case when we are adding a new show day to * a repeating show @@ -1484,4 +1518,4 @@ SQL; $repeatInfo->setDbNextPopDate($nextInfo[0]) ->save(); } -} \ No newline at end of file +} diff --git a/airtime_mvc/application/views/scripts/audiopreview/audio-preview.phtml b/airtime_mvc/application/views/scripts/audiopreview/audio-preview.phtml index e8196913f..fcade27d9 100644 --- a/airtime_mvc/application/views/scripts/audiopreview/audio-preview.phtml +++ b/airtime_mvc/application/views/scripts/audiopreview/audio-preview.phtml @@ -18,18 +18,26 @@