Merge branch '2.0.x' into devel

Conflicts:
	VERSION
	airtime_mvc/application/Bootstrap.php
	airtime_mvc/application/controllers/LibraryController.php
	airtime_mvc/application/controllers/ScheduleController.php
	airtime_mvc/application/models/Nowplaying.php
	airtime_mvc/application/models/Show.php
	airtime_mvc/application/models/airtime/CcShowInstances.php
This commit is contained in:
Martin Konecny 2012-02-14 14:47:07 -05:00
commit 54cbc86a0a
3234 changed files with 71062 additions and 781848 deletions

View file

@ -9,16 +9,16 @@ class Application_Model_Nowplaying
private static function CreateDatatableRows($p_dbRows){
$dataTablesRows = array();
$epochNow = time();
foreach ($p_dbRows as $dbRow){
$showStartDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($dbRow['show_starts']);
$showEndDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($dbRow['show_ends']);
$itemStartDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($dbRow['item_starts']);
$itemEndDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($dbRow['item_ends']);
$showStarts = $showStartDateTime->format("Y-m-d H:i:s");
$showEnds = $showEndDateTime->format("Y-m-d H:i:s");
$itemStarts = $itemStartDateTime->format("Y-m-d H:i:s");
@ -28,29 +28,29 @@ class Application_Model_Nowplaying
$status = ($showEnds < $itemEnds) ? "x" : "";
$type = "a";
$type .= ($itemStartDateTime->getTimestamp() <= $epochNow
$type .= ($itemStartDateTime->getTimestamp() <= $epochNow
&& $epochNow < $itemEndDateTime->getTimestamp()
&& $epochNow < $showEndDateTime->getTimestamp()) ? "c" : "";
// remove millisecond from the time format
$itemStart = explode('.', $dbRow['item_starts']);
$itemEnd = explode('.', $dbRow['item_ends']);
//format duration
$duration = explode('.', $dbRow['clip_length']);
$formatted = self::FormatDuration($duration[0]);
$dataTablesRows[] = array($type, $showStarts, $itemStarts, $itemEnds,
$dataTablesRows[] = array($type, $itemStarts, $itemStarts, $itemEnds,
$formatted, $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'],
$dbRow['playlist_name'], $dbRow['show_name'], $status);
}
return $dataTablesRows;
}
private static function CreateGapRow($p_gapTime){
return array("g", "", "", "", $p_gapTime, "", "", "", "", "", "");
}
private static function CreateRecordingRow($p_showInstance){
return array("r", "", "", "", $p_showInstance->getName(), "", "", "", "", "", "");
}
@ -60,7 +60,7 @@ class Application_Model_Nowplaying
if ($viewType == "now"){
$dateTime = new DateTime("now", new DateTimeZone("UTC"));
$timeNow = $dateTime->format("Y-m-d H:i:s");
$startCutoff = 60;
$endCutoff = 86400; //60*60*24 - seconds in a day
} else {
@ -72,30 +72,30 @@ class Application_Model_Nowplaying
$startCutoff = $date->getNowDayStartDiff();
$endCutoff = $date->getNowDayEndDiff();
}
$data = array();
$showIds = Application_Model_ShowInstance::GetShowsInstancesIdsInRange($timeNow, $startCutoff, $endCutoff);
foreach ($showIds as $showId){
$instanceId = $showId['id'];
$si = new Application_Model_ShowInstance($instanceId);
$showId = $si->getShowId();
$show = new Application_Model_Show($showId);
$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);
$dataTablesRows = self::CreateDatatableRows($scheduledItems);
//append show audio item rows
$data = array_merge($data, $dataTablesRows);
//append show gap time row
$gapTime = self::FormatDuration($si->getShowEndGapTime(), true);
if ($si->isRecorded())
@ -118,7 +118,7 @@ class Application_Model_Nowplaying
}
/*
* default $time format should be in format of 00:00:00
* if $inSecond = true, then $time should be in seconds
* if $inSecond = true, then $time should be in seconds
*/
private static function FormatDuration($time, $inSecond=false){
if($inSecond == false){
@ -129,13 +129,13 @@ class Application_Model_Nowplaying
$duration[1] = intval(($time/60)%60);
$duration[2] = $time%60;
}
if($duration[2] == 0){
$duration[2] = '';
}else{
$duration[2] = intval($duration[2],10).'s';
}
if($duration[1] == 0){
if($duration[2] == ''){
$duration[1] = '';
@ -145,13 +145,13 @@ class Application_Model_Nowplaying
}else{
$duration[1] = intval($duration[1],10).'m ';
}
if($duration[0] == 0){
$duration[0] = '';
}else{
$duration[0] = intval($duration[0],10).'h ';
}
$out = $duration[0].$duration[1].$duration[2];
return $out;
}

View file

@ -102,7 +102,6 @@ class Application_Model_Preference
public static function SetHeadTitle($title, $view=null){
self::SetValue("station_name", $title);
Application_Model_RabbitMq::PushSchedule();
// in case this is called from airtime-saas script
if($view !== null){
@ -111,6 +110,11 @@ class Application_Model_Preference
$view->headTitle()->exchangeArray(array()); //clear headTitle ArrayObject
$view->headTitle(self::GetHeadTitle());
}
$eventType = "update_station_name";
$md = array("station_name"=>$title);
Application_Model_RabbitMq::SendMessageToPypo($eventType, $md);
}
/**
@ -153,7 +157,11 @@ class Application_Model_Preference
public static function SetStreamLabelFormat($type){
self::SetValue("stream_label_format", $type);
Application_Model_RabbitMq::PushSchedule();
$eventType = "update_stream_format";
$md = array("stream_format"=>$type);
Application_Model_RabbitMq::SendMessageToPypo($eventType, $md);
}
public static function GetStreamLabelFormat(){

View file

@ -46,7 +46,8 @@ class Application_Model_RabbitMq
$conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"],
$CC_CONFIG["rabbitmq"]["port"],
$CC_CONFIG["rabbitmq"]["user"],
$CC_CONFIG["rabbitmq"]["password"]);
$CC_CONFIG["rabbitmq"]["password"],
$CC_CONFIG["rabbitmq"]["vhost"]);
$channel = $conn->channel();
$channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true);
@ -68,7 +69,8 @@ class Application_Model_RabbitMq
$conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"],
$CC_CONFIG["rabbitmq"]["port"],
$CC_CONFIG["rabbitmq"]["user"],
$CC_CONFIG["rabbitmq"]["password"]);
$CC_CONFIG["rabbitmq"]["password"],
$CC_CONFIG["rabbitmq"]["vhost"]);
$channel = $conn->channel();
$channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true);

View file

@ -351,13 +351,15 @@ class Application_Model_Show {
public function isRepeating()
{
$showDaysRow = CcShowDaysQuery::create()
->filterByDbShowId($this->_showId)
->findOne();
->filterByDbShowId($this->_showId)
->findOne();
if (!is_null($showDaysRow)){
return ($showDaysRow->getDbRepeatType() != -1);
} else
}
else {
return false;
}
}
/**
@ -1164,7 +1166,9 @@ class Application_Model_Show {
Logging::log('$start time of non repeating record '.$start);
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
if ($newInstance){
self::createRebroadcastInstances($rebroadcasts, $currentUtcTimestamp, $show_id, $show_instance_id, $start, $duration, $timezone);
}
}
}
@ -1392,7 +1396,7 @@ class Application_Model_Show {
Application_Model_Preference::SetShowsPopulatedUntil($end_timestamp);
}
$sql = "SELECT starts, ends, record, rebroadcast, instance_id, show_id, name, description,
$sql = "SELECT starts, ends, record, rebroadcast, instance_id, show_id, name,
color, background_color, file_id, cc_show_instances.id AS instance_id
FROM cc_show_instances
LEFT JOIN cc_show ON cc_show.id = cc_show_instances.show_id
@ -1455,18 +1459,18 @@ class Application_Model_Show {
$endTimeString = $p_endTimestamp->format("Y-m-d H:i:s");
if (!is_null($p_startTimestamp)) {
$startTimeString = $p_startTimestamp->format("Y-m-d H:i:s");
$sql = "SELECT * FROM cc_show_days
WHERE last_show IS NULL
OR first_show < '{$endTimeString}' AND last_show > '{$startTimeString}'";
}
else {
$today_timestamp = new DateTime("now", new DateTimeZone("UTC"));
$today_timestamp_string = $today_timestamp->format("Y-m-d H:i:s");
$sql = "SELECT * FROM cc_show_days
WHERE last_show IS NULL
OR first_show < '{$endTimeString}' AND last_show > '{$today_timestamp_string}'";
$startTimeString = $today_timestamp->format("Y-m-d H:i:s");
}
$sql = "SELECT * FROM cc_show_days
WHERE last_show IS NULL
OR first_show < '{$endTimeString}' AND last_show > '{$startTimeString}'";
Logging::log($sql);
$res = $CC_DBC->GetAll($sql);
foreach ($res as $row) {

View file

@ -58,21 +58,19 @@ class Application_Model_ShowInstance {
/**
* Return the start time of the Show (UTC time)
* @return string in format "Y-m-d H:i:s" (PHP time notation)
* TODO: make this function return a DateTime object instead.
*/
public function getShowInstanceStart()
public function getShowInstanceStart($format="Y-m-d H:i:s")
{
return $this->_showInstance->getDbStarts();
return $this->_showInstance->getDbStarts($format);
}
/**
* Return the end time of the Show (UTC time)
* @return string in format "Y-m-d H:i:s" (PHP time notation)
* TODO: make this function return a DateTime object instead.
*/
public function getShowInstanceEnd()
public function getShowInstanceEnd($format="Y-m-d H:i:s")
{
return $this->_showInstance->getDbEnds();
return $this->_showInstance->getDbEnds($format);
}
public function getStartDate()
@ -444,6 +442,81 @@ class Application_Model_ShowInstance {
$this->updateScheduledTime();
}
private function checkToDeleteShow($showId)
{
//UTC DateTime object
$showsPopUntil = Application_Model_Preference::GetShowsPopulatedUntil();
$showDays = CcShowDaysQuery::create()
->filterByDbShowId($showId)
->findOne();
$showEnd = $showDays->getDbLastShow();
//there will always be more shows populated.
if (is_null($showEnd)) {
return false;
}
$lastShowStartDateTime = new DateTime("{$showEnd} {$showDays->getDbStartTime()}", new DateTimeZone($showDays->getDbTimezone()));
//end dates were non inclusive.
$lastShowStartDateTime = self::addDeltas($lastShowStartDateTime, -1, 0);
//there's still some shows left to be populated.
if ($lastShowStartDateTime->getTimestamp() > $showsPopUntil->getTimestamp()) {
return false;
}
// check if there are any non deleted show instances remaining.
$showInstances = CcShowInstancesQuery::create()
->filterByDbShowId($showId)
->filterByDbModifiedInstance(false)
->filterByDbRebroadcast(0)
->find();
if (is_null($showInstances)){
return true;
}
//only 1 show instance left of the show, make it non repeating.
else if (count($showInstances) === 1) {
$showInstance = $showInstances[0];
$showDaysOld = CcShowDaysQuery::create()
->filterByDbShowId($showId)
->find();
$tz = $showDaysOld[0]->getDbTimezone();
$startDate = new DateTime($showInstance->getDbStarts(), new DateTimeZone("UTC"));
$startDate->setTimeZone(new DateTimeZone($tz));
$endDate = self::addDeltas($startDate, 1, 0);
//make a new rule for a non repeating show.
$showDayNew = new CcShowDays();
$showDayNew->setDbFirstShow($startDate->format("Y-m-d"));
$showDayNew->setDbLastShow($endDate->format("Y-m-d"));
$showDayNew->setDbStartTime($startDate->format("H:i:s"));
$showDayNew->setDbTimezone($tz);
$showDayNew->setDbDay($startDate->format('w'));
$showDayNew->setDbDuration($showDaysOld[0]->getDbDuration());
$showDayNew->setDbRepeatType(-1);
$showDayNew->setDbShowId($showDaysOld[0]->getDbShowId());
$showDayNew->setDbRecord($showDaysOld[0]->getDbRecord());
$showDayNew->save();
//delete the old rules for repeating shows
$showDaysOld->delete();
//remove the old repeating deleted instances.
$showInstances = CcShowInstancesQuery::create()
->filterByDbShowId($showId)
->filterByDbModifiedInstance(true)
->delete();
}
return false;
}
public function delete()
{
global $CC_DBC;
@ -465,6 +538,10 @@ class Application_Model_ShowInstance {
->setDbModifiedInstance(true)
->save();
if ($this->isRebroadcast()) {
return;
}
//delete the rebroadcasts of the removed recorded show.
if ($recording) {
CcShowInstancesQuery::create()
@ -477,17 +554,8 @@ class Application_Model_ShowInstance {
->filterByDbInstanceId($this->_instanceId)
->delete();
// check if we can safely delete the show
$showInstancesRow = CcShowInstancesQuery::create()
->filterByDbShowId($showId)
->filterByDbModifiedInstance(false)
->findOne();
/* If we didn't find any instances of the show that haven't
* been deleted, then just erase everything related to that show.
* We can just delete, the show and the foreign key-constraint should
* take care of deleting all of its instances. */
if(is_null($showInstancesRow)){
if ($this->checkToDeleteShow($showId)){
CcShowQuery::create()
->filterByDbId($showId)
->delete();
@ -537,20 +605,26 @@ class Application_Model_ShowInstance {
return $time;
}
public function getTimeScheduledSecs()
{
$time_filled = $this->getTimeScheduled();
return Application_Model_Schedule::WallTimeToMillisecs($time_filled) / 1000;
}
public function getDurationSecs()
{
$ends = $this->getShowInstanceEnd(null);
$starts = $this->getShowInstanceStart(null);
return $ends->format('U') - $starts->format('U');
}
public function getPercentScheduled()
{
$start_timestamp = $this->getShowInstanceStart();
$end_timestamp = $this->getShowInstanceEnd();
$time_filled = $this->getTimeScheduled();
$durationSeconds = $this->getDurationSecs();
$timeSeconds = $this->getTimeScheduledSecs();
$s_epoch = strtotime($start_timestamp);
$e_epoch = strtotime($end_timestamp);
$i_epoch = Application_Model_Schedule::WallTimeToMillisecs($time_filled) / 1000;
$percent = ceil(($i_epoch / ($e_epoch - $s_epoch)) * 100);
if ($percent > 100)
$percent = 100;
$percent = ceil(($timeSeconds / $durationSeconds) * 100);
return $percent;
}
@ -714,6 +788,7 @@ class Application_Model_ShowInstance {
$sql = "SELECT si.id"
." FROM $CC_CONFIG[showInstances] si"
." WHERE si.ends < TIMESTAMP '$p_timeNow'"
." AND si.modified_instance = 'f'"
." ORDER BY si.ends DESC"
." LIMIT 1";
@ -728,10 +803,18 @@ class Application_Model_ShowInstance {
public static function GetCurrentShowInstance($p_timeNow){
global $CC_CONFIG, $CC_DBC;
/* Orderby si.starts descending, because in some cases
* we can have multiple shows overlapping each other. In
* this case, the show that started later is the one that
* is actually playing, and so this is the one we want.
*/
$sql = "SELECT si.id"
." FROM $CC_CONFIG[showInstances] si"
." WHERE si.starts <= TIMESTAMP '$p_timeNow'"
." AND si.ends > TIMESTAMP '$p_timeNow'"
." AND si.modified_instance = 'f'"
." ORDER BY si.starts DESC"
." LIMIT 1";
$id = $CC_DBC->GetOne($sql);
@ -748,6 +831,7 @@ class Application_Model_ShowInstance {
$sql = "SELECT si.id"
." FROM $CC_CONFIG[showInstances] si"
." WHERE si.starts > TIMESTAMP '$p_timeNow'"
." AND si.modified_instance = 'f'"
." ORDER BY si.starts"
." LIMIT 1";

View file

@ -83,8 +83,12 @@ class Application_Model_StreamSetting {
$CC_DBC->query($sql);
} else if ($key == "output_sound_device_type") {
$sql = "UPDATE cc_stream_setting SET value='$d' WHERE keyname='$key'";
$CC_DBC->query($sql);
} else {
$CC_DBC->query($sql);
} else if ($key == "streamFormat"){
// this goes into cc_pref table
Logging::log("Insert stream label format $d");
Application_Model_Preference::SetStreamLabelFormat($d);
} else if (is_array($d)) {
$temp = explode('_', $key);
$prefix = $temp[0];
foreach ($d as $k=>$v) {
@ -96,6 +100,8 @@ class Application_Model_StreamSetting {
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'";
$CC_DBC->query($sql);
}
} else {
Logging::log("Warning unexpected value: ".$key);
}
}
}

View file

@ -120,23 +120,31 @@ class Application_Model_Systemstatus
public static function GetPypoStatus(){
$component = CcServiceRegisterQuery::create()->findOneByDbName("pypo");
$ip = $component->getDbIp();
$docRoot = self::GetMonitStatus($ip);
$data = self::ExtractServiceInformation($docRoot, "airtime-playout");
if (is_null($component)){
return null;
} else {
$ip = $component->getDbIp();
$docRoot = self::GetMonitStatus($ip);
$data = self::ExtractServiceInformation($docRoot, "airtime-playout");
return $data;
return $data;
}
}
public static function GetLiquidsoapStatus(){
$component = CcServiceRegisterQuery::create()->findOneByDbName("pypo");
$ip = $component->getDbIp();
$docRoot = self::GetMonitStatus($ip);
$data = self::ExtractServiceInformation($docRoot, "airtime-liquidsoap");
if (is_null($component)){
return null;
} else {
$ip = $component->getDbIp();
$docRoot = self::GetMonitStatus($ip);
$data = self::ExtractServiceInformation($docRoot, "airtime-liquidsoap");
return $data;
return $data;
}
}
public static function GetShowRecorderStatus(){

View file

@ -1,5 +1,4 @@
<?php
$path = dirname(__FILE__).'/../../../library/pear';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
$WHITE_SCREEN_OF_DEATH = false;