Merge branch 'devel' of dev.sourcefabric.org:airtime into devel
This commit is contained in:
commit
bca7fbf50e
15 changed files with 124 additions and 127 deletions
|
@ -337,6 +337,7 @@ class ApiController extends Zend_Controller_Action
|
|||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
$data = Application_Model_Schedule::getSchedule();
|
||||
header("Content-Type: application/json");
|
||||
echo json_encode($data, JSON_FORCE_OBJECT);
|
||||
}
|
||||
|
||||
|
@ -688,9 +689,12 @@ class ApiController extends Zend_Controller_Action
|
|||
{
|
||||
$request = $this->getRequest();
|
||||
$dir_id = $request->getParam('dir_id');
|
||||
$all = $request->getParam('all');
|
||||
|
||||
Logging::info("All param is: $all");
|
||||
|
||||
$this->view->files =
|
||||
Application_Model_StoredFile::listAllFiles($dir_id,$all=true);
|
||||
Application_Model_StoredFile::listAllFiles($dir_id,$all);
|
||||
}
|
||||
|
||||
public function listAllWatchedDirsAction()
|
||||
|
|
|
@ -339,7 +339,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
return false;
|
||||
}
|
||||
|
||||
if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER) && $user->isHostOfShow($show->getShowId())))
|
||||
if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)) || $user->isHostOfShow($show->getShowId()))
|
||||
$show->clearShow();
|
||||
}
|
||||
|
||||
|
@ -404,7 +404,7 @@ class ScheduleController extends Zend_Controller_Action
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER) && $user->isHostOfShow($show->getShowId()))) {
|
||||
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)) || $user->isHostOfShow($show->getShowId())) {
|
||||
$show->removeGroupFromShow($group_id);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,9 @@ class Application_Model_Datatables
|
|||
if ($dbname == 'utime' || $dbname == 'mtime') {
|
||||
$input1 = isset($info[0])?Application_Common_DateHelper::ConvertToUtcDateTimeString($info[0]):null;
|
||||
$input2 = isset($info[1])?Application_Common_DateHelper::ConvertToUtcDateTimeString($info[1]):null;
|
||||
} else if($dbname == 'bit_rate') {
|
||||
$input1 = isset($info[0])?intval($info[0]) * 1000:null;
|
||||
$input2 = isset($info[1])?intval($info[1]) * 1000:null;
|
||||
} else {
|
||||
$input1 = isset($info[0])?$info[0]:null;
|
||||
$input2 = isset($info[1])?$info[1]:null;
|
||||
|
|
|
@ -79,16 +79,29 @@ class Application_Model_MusicDir
|
|||
|
||||
$music_dir_id = $this->getId();
|
||||
|
||||
$sql = "SELECT DISTINCT s.instance_id from cc_music_dirs as md "
|
||||
." LEFT JOIN cc_files as f on f.directory = md.id"
|
||||
." RIGHT JOIN cc_schedule as s on s.file_id = f.id WHERE md.id = $music_dir_id";
|
||||
|
||||
$show_instances = $con->query($sql)->fetchAll();
|
||||
$sql = <<<SQL
|
||||
SELECT DISTINCT s.instance_id
|
||||
FROM cc_music_dirs AS md
|
||||
LEFT JOIN cc_files AS f ON f.directory = md.id
|
||||
RIGHT JOIN cc_schedule AS s ON s.file_id = f.id
|
||||
WHERE md.id = :musicDirId;
|
||||
SQL;
|
||||
$show_instances = Application_Common_Database::prepareAndExecute($sql,
|
||||
array( ':musicDirId' => $music_dir_id ), 'all' );
|
||||
|
||||
// get all the files on this dir
|
||||
$sql = "UPDATE cc_files SET file_exists = 'f' WHERE id IN (SELECT f.id FROM cc_music_dirs as md "
|
||||
." LEFT JOIN cc_files as f on f.directory = md.id WHERE md.id = $music_dir_id)";
|
||||
$affected = $con->exec($sql);
|
||||
$sql = <<<SQL
|
||||
UPDATE cc_files
|
||||
SET file_exists = 'f'
|
||||
WHERE id IN
|
||||
(SELECT f.id
|
||||
FROM cc_music_dirs AS md
|
||||
LEFT JOIN cc_files AS f ON f.directory = md.id
|
||||
WHERE md.id = :musicDirId);
|
||||
SQL;
|
||||
|
||||
$affected = Application_Common_Database::prepareAndExecute($sql,
|
||||
array( ':musicDirId' => $music_dir_id ), 'all');
|
||||
|
||||
// set RemovedFlag to true
|
||||
if ($userAddedWatchedDir) {
|
||||
|
|
|
@ -172,20 +172,21 @@ class Application_Model_Schedule
|
|||
public static function GetLastScheduleItem($p_timeNow)
|
||||
{
|
||||
global $CC_CONFIG;
|
||||
$sql = "SELECT"
|
||||
." ft.artist_name, ft.track_title,"
|
||||
." st.starts as starts, st.ends as ends"
|
||||
." FROM $CC_CONFIG[scheduleTable] st"
|
||||
." LEFT JOIN $CC_CONFIG[filesTable] ft"
|
||||
." ON st.file_id = ft.id"
|
||||
." LEFT JOIN $CC_CONFIG[showInstances] sit"
|
||||
." ON st.instance_id = sit.id"
|
||||
." WHERE st.ends < TIMESTAMP :timeNow"
|
||||
." AND st.starts >= sit.starts" //this and the next line are necessary since we can overbook shows.
|
||||
." AND st.starts < sit.ends"
|
||||
." ORDER BY st.ends DESC"
|
||||
." LIMIT 1";
|
||||
$sql = <<<SQL
|
||||
SELECT ft.artist_name,
|
||||
ft.track_title,
|
||||
st.starts AS starts,
|
||||
st.ends AS ends
|
||||
FROM $CC_CONFIG[scheduleTable] st
|
||||
LEFT JOIN $CC_CONFIG[filesTable] ft ON st.file_id = ft.id
|
||||
LEFT JOIN $CC_CONFIG[showInstances] sit ON st.instance_id = sit.id
|
||||
-- this and the next line are necessary since we can overbook shows.
|
||||
WHERE st.ends < TIMESTAMP :timeNow
|
||||
|
||||
AND st.starts >= sit.starts
|
||||
AND st.starts < sit.ends
|
||||
ORDER BY st.ends DESC LIMIT 1;
|
||||
SQL;
|
||||
$row = Application_Common_Database::prepareAndExecute($sql, array(':timeNow'=>$p_timeNow));
|
||||
|
||||
return $row;
|
||||
|
@ -527,14 +528,17 @@ SQL;
|
|||
//." st.type AS type,"
|
||||
." si.starts AS show_start,"
|
||||
." si.ends AS show_end,"
|
||||
." s.name AS show_name,"
|
||||
." f.id AS file_id,"
|
||||
." f.replay_gain AS replay_gain,"
|
||||
." ws.id as stream_id,"
|
||||
." ws.url as url"
|
||||
." FROM $CC_CONFIG[scheduleTable] AS st"
|
||||
." LEFT JOIN $CC_CONFIG[showInstances] AS si"
|
||||
." FROM cc_schedule AS st"
|
||||
." LEFT JOIN cc_show_instances AS si"
|
||||
." ON st.instance_id = si.id"
|
||||
." LEFT JOIN $CC_CONFIG[filesTable] AS f"
|
||||
." LEFT JOIN cc_show as s"
|
||||
." ON s.id = si.show_id"
|
||||
." LEFT JOIN cc_files AS f"
|
||||
." ON st.file_id = f.id"
|
||||
." LEFT JOIN cc_webstream AS ws"
|
||||
." ON st.stream_id = ws.id";
|
||||
|
@ -547,11 +551,10 @@ SQL;
|
|||
|
||||
$sql = $baseQuery.$predicates;
|
||||
|
||||
$rows = Application_Common_Database::prepareAndExecute($sql, array(':startTime1'=>$p_startTime, ':endTime'=>$p_endTime, ':startTime2'=>$p_startTime));
|
||||
$rows = Application_Common_Database::prepareAndExecute($sql,
|
||||
array(':startTime1'=>$p_startTime, ':endTime'=>$p_endTime, ':startTime2'=>$p_startTime));
|
||||
|
||||
if (count($rows) < 3) {
|
||||
Logging::debug("Get Schedule: Less than 3 results returned. Doing another query since we need a minimum of 3 results.");
|
||||
|
||||
$dt = new DateTime("@".time());
|
||||
$dt->add(new DateInterval("PT24H"));
|
||||
$range_end = $dt->format("Y-m-d H:i:s");
|
||||
|
@ -564,12 +567,31 @@ SQL;
|
|||
." LIMIT 3";
|
||||
|
||||
$sql = $baseQuery.$predicates;
|
||||
$rows = Application_Common_Database::prepareAndExecute($sql, array(':startTime1'=>$p_startTime, ':rangeEnd'=>$range_end, ':startTime2'=>$p_startTime));
|
||||
$rows = Application_Common_Database::prepareAndExecute($sql,
|
||||
array(':startTime1'=>$p_startTime, ':rangeEnd'=>$range_end, ':startTime2'=>$p_startTime));
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will ensure that an existing index in the
|
||||
* associative array is never overwritten, instead appending
|
||||
* _0, _1, _2, ... to the end of the key to make sure it is unique
|
||||
*/
|
||||
private static function appendScheduleItem(&$data, $time, $item)
|
||||
{
|
||||
$key = $time;
|
||||
$i = 0;
|
||||
|
||||
while (array_key_exists($key, $data["media"])) {
|
||||
$key = "{$time}_{$i}";
|
||||
$i++;
|
||||
}
|
||||
|
||||
$data["media"][$key] = $item;
|
||||
}
|
||||
|
||||
private static function createInputHarborKickTimes(&$data, $range_start, $range_end)
|
||||
{
|
||||
$utcTimeZone = new DateTimeZone("UTC");
|
||||
|
@ -601,7 +623,7 @@ SQL;
|
|||
}
|
||||
}
|
||||
|
||||
private static function createFileScheduleEvent(&$data, $item, $media_id)
|
||||
private static function createFileScheduleEvent(&$data, $item, $media_id, $uri)
|
||||
{
|
||||
$start = self::AirtimeTimeToPypoTime($item["start"]);
|
||||
$end = self::AirtimeTimeToPypoTime($item["end"]);
|
||||
|
@ -617,14 +639,14 @@ SQL;
|
|||
'cue_out' => Application_Common_DateHelper::CalculateLengthInSeconds($item["cue_out"]),
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'show_name' => $showName,
|
||||
'show_name' => $item["show_name"],
|
||||
'replay_gain' => is_null($item["replay_gain"]) ? "0": $item["replay_gain"],
|
||||
'independent_event' => true
|
||||
);
|
||||
$data["media"][$start] = $schedule_item;
|
||||
self::appendScheduleItem($data, $start, $schedule_item);
|
||||
}
|
||||
|
||||
private static function createStreamScheduleEvent(&$data, $item, $media_id)
|
||||
private static function createStreamScheduleEvent(&$data, $item, $media_id, $uri)
|
||||
{
|
||||
$start = self::AirtimeTimeToPypoTime($item["start"]);
|
||||
$end = self::AirtimeTimeToPypoTime($item["end"]);
|
||||
|
@ -644,8 +666,8 @@ SQL;
|
|||
'independent_event' => true
|
||||
);
|
||||
|
||||
//TODO: Make sure no other media is being overwritten!
|
||||
$data["media"][$stream_buffer_start] = $schedule_item;
|
||||
self::appendScheduleItem($data, $start, $schedule_item);
|
||||
|
||||
$schedule_item = array(
|
||||
'id' => $media_id,
|
||||
'type' => 'stream_output_start',
|
||||
|
@ -653,21 +675,16 @@ SQL;
|
|||
'uri' => $uri,
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'show_name' => $showName,
|
||||
'show_name' => $item["show_name"],
|
||||
'independent_event' => true
|
||||
);
|
||||
$data["media"][$start] = $schedule_item;
|
||||
self::appendScheduleItem($data, $start, $schedule_item);
|
||||
|
||||
//since a stream never ends we have to insert an additional "kick stream" event. The "start"
|
||||
//time of this event is the "end" time of the stream minus 1 second.
|
||||
$dt = new DateTime($item["end"], new DateTimeZone('UTC'));
|
||||
$dt->sub(new DateInterval("PT1S"));
|
||||
|
||||
//make sure the webstream doesn't play past the end time of the show
|
||||
if ($dt->getTimestamp() > $showEndDateTime->getTimestamp()) {
|
||||
$dt = $showEndDateTime;
|
||||
}
|
||||
|
||||
$stream_end = self::AirtimeTimeToPypoTime($dt->format("Y-m-d H:i:s"));
|
||||
|
||||
$schedule_item = array(
|
||||
|
@ -677,8 +694,7 @@ SQL;
|
|||
'type' => 'stream_buffer_end',
|
||||
'independent_event' => true
|
||||
);
|
||||
$data["media"][$stream_end] = $schedule_item;
|
||||
|
||||
self::appendScheduleItem($data, $stream_end, $schedule_item);
|
||||
|
||||
$schedule_item = array(
|
||||
'start' => $stream_end,
|
||||
|
@ -687,7 +703,7 @@ SQL;
|
|||
'type' => 'stream_output_end',
|
||||
'independent_event' => true
|
||||
);
|
||||
$data["media"][$stream_end] = $schedule_item;
|
||||
self::appendScheduleItem($data, $stream_end, $schedule_item);
|
||||
}
|
||||
|
||||
private static function getRangeStartAndEnd($p_fromDateTime, $p_toDateTime)
|
||||
|
@ -723,28 +739,14 @@ SQL;
|
|||
return array($range_start, $range_end);
|
||||
}
|
||||
|
||||
public static function getSchedule($p_fromDateTime = null, $p_toDateTime = null)
|
||||
|
||||
private static function createScheduledEvents(&$data, $range_start, $range_end)
|
||||
{
|
||||
|
||||
list($range_start, $range_end) = self::getRangeStartAndEnd($p_fromDateTime, $p_toDateTime);
|
||||
|
||||
$data = array();
|
||||
$utcTimeZone = new DateTimeZone("UTC");
|
||||
|
||||
$data["status"] = array();
|
||||
$data["media"] = array();
|
||||
|
||||
self::createInputHarborKickTimes($data, $range_start, $range_end);
|
||||
|
||||
$items = self::getItems($range_start, $range_end);
|
||||
foreach ($items as $item) {
|
||||
|
||||
$showInstance = CcShowInstancesQuery::create()->findPK($item["instance_id"]);
|
||||
$showId = $showInstance->getDbShowId();
|
||||
$show = CcShowQuery::create()->findPK($showId);
|
||||
$showName = $show->getDbName();
|
||||
|
||||
$showEndDateTime = new DateTime($item["show_end"], $utcTimeZone);
|
||||
|
||||
$trackStartDateTime = new DateTime($item["start"], $utcTimeZone);
|
||||
$trackEndDateTime = new DateTime($item["end"], $utcTimeZone);
|
||||
|
||||
|
@ -773,29 +775,21 @@ SQL;
|
|||
self::createStreamScheduleEvent($data, $item, $media_id, $uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getSchedule($p_fromDateTime = null, $p_toDateTime = null)
|
||||
{
|
||||
list($range_start, $range_end) = self::getRangeStartAndEnd($p_fromDateTime, $p_toDateTime);
|
||||
|
||||
$data = array();
|
||||
$data["media"] = array();
|
||||
|
||||
self::createInputHarborKickTimes($data, $range_start, $range_end);
|
||||
self::createScheduledEvents($data, $range_start, $range_end);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/*
|
||||
private static function collapseEvents($data)
|
||||
{
|
||||
$keys = array_keys($data);
|
||||
|
||||
for ($i = 0, $len = count($keys); $i < $len; $i++) {
|
||||
$cur = $data[$keys[$i]];
|
||||
$next = null;
|
||||
if ($i+1 < $len) {
|
||||
$next = $data[$keys[$i+1]];
|
||||
}
|
||||
|
||||
if ($cur['type'] == 'stream_buffer_end' && !is_null($next) && $next['type'] == 'stream_buffer_start') {
|
||||
unset($data[$keys[$i]]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public static function deleteAll()
|
||||
{
|
||||
global $CC_CONFIG;
|
||||
|
@ -896,10 +890,12 @@ SQL;
|
|||
$when = $formWhen->isValid($data);
|
||||
|
||||
if ($when && $formWhen->checkReliantFields($data, true, null, true)) {
|
||||
$start_dt = new DateTime($data['add_show_start_date']." ".$data['add_show_start_time'], new DateTimeZone(date_default_timezone_get()));
|
||||
$start_dt = new DateTime($data['add_show_start_date']." ".$data['add_show_start_time'],
|
||||
new DateTimeZone(date_default_timezone_get()));
|
||||
$start_dt->setTimezone(new DateTimeZone('UTC'));
|
||||
|
||||
$end_dt = new DateTime($data['add_show_end_date_no_repeat']." ".$data['add_show_end_time'], new DateTimeZone(date_default_timezone_get()));
|
||||
$end_dt = new DateTime($data['add_show_end_date_no_repeat']." ".$data['add_show_end_time'],
|
||||
new DateTimeZone(date_default_timezone_get()));
|
||||
$end_dt->setTimezone(new DateTimeZone('UTC'));
|
||||
|
||||
$ccShowInstance = CcShowInstancesQuery::create()->findPK($data["add_show_instance_id"]);
|
||||
|
@ -1122,12 +1118,6 @@ SQL;
|
|||
*/
|
||||
//$se = $show_end->format('Y-m-d H:i:s');
|
||||
if ($update) {
|
||||
$sql = "SELECT id, starts, ends FROM ".$CC_CONFIG["showInstances"]."
|
||||
where (ends <= '{$show_end->format('Y-m-d H:i:s')}'
|
||||
or starts <= '{$show_end->format('Y-m-d H:i:s')}')
|
||||
and date(starts) >= (date('{$show_end->format('Y-m-d H:i:s')}') - INTERVAL '2 days')
|
||||
and modified_instance = false and id != ".$instanceId. " order by ends";
|
||||
|
||||
$stmt = $con->prepare("SELECT id, starts, ends FROM {$CC_CONFIG['showInstances']}
|
||||
where (ends <= :show_end1
|
||||
or starts <= :show_end2)
|
||||
|
@ -1141,13 +1131,6 @@ SQL;
|
|||
':instanceId' => $instanceId
|
||||
));
|
||||
} else {
|
||||
// TODO : Remove raw sql later
|
||||
$sql = "SELECT id, starts, ends FROM ".$CC_CONFIG["showInstances"]."
|
||||
where (ends <= '{$show_end->format('Y-m-d H:i:s')}'
|
||||
or starts <= '{$show_end->format('Y-m-d H:i:s')}')
|
||||
and date(starts) >= (date('{$show_end->format('Y-m-d H:i:s')}') - INTERVAL '2 days')
|
||||
and modified_instance = false order by ends";
|
||||
|
||||
$stmt = $con->prepare("SELECT id, starts, ends FROM
|
||||
{$CC_CONFIG['showInstances']}
|
||||
where (ends <= :show_end1 or starts <= :show_end2)
|
||||
|
@ -1160,7 +1143,6 @@ SQL;
|
|||
':show_end3' => $show_end->format('Y-m-d H:i:s')
|
||||
));
|
||||
}
|
||||
//$rows = $con->query($sql);
|
||||
$rows = $stmt->fetchAll();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
|
|
|
@ -51,11 +51,6 @@ class Application_Model_StoredFile
|
|||
"owner_id" => "DbOwnerId"
|
||||
);
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->_file->getDbId();
|
||||
|
|
|
@ -262,7 +262,6 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
|
|||
private static function getPlsUrl($url)
|
||||
{
|
||||
$content = self::getUrlData($url);
|
||||
|
||||
$ini = parse_ini_string($content, true);
|
||||
|
||||
if ($ini !== false && isset($ini["playlist"]) && isset($ini["playlist"]["File1"])) {
|
||||
|
|
|
@ -416,7 +416,7 @@ var AIRTIME = (function(AIRTIME) {
|
|||
/* Language */ { "sTitle" : "Language" , "mDataProp" : "language" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" } ,
|
||||
/* Owner */ { "sTitle" : "Owner" , "mDataProp" : "owner" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" } ,
|
||||
/* Conductor */ { "sTitle" : "Conductor" , "mDataProp" : "conductor" , "bVisible" : false , "sClass" : "library_conductor" , "sWidth" : "125px" },
|
||||
/* Replay Gain */ { "sTitle" : "Replay Gain" , "mDataProp" : "replay_gain" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" }
|
||||
/* Replay Gain */ { "sTitle" : "Replay Gain" , "mDataProp" : "replay_gain" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "80px" }
|
||||
],
|
||||
|
||||
"bProcessing": true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue