Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
Martin Konecny 2012-09-07 00:10:54 -04:00
commit 0ad4e0dd28
6 changed files with 119 additions and 101 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
class Application_Common_Database class Application_Common_Database
{ {
public static function prepareAndExecute($sql, array $paramValueMap, public static function prepareAndExecute($sql, array $paramValueMap,
$type='all', $fetchType=PDO::FETCH_ASSOC) $type='all', $fetchType=PDO::FETCH_ASSOC)
{ {
$con = Propel::getConnection(); $con = Propel::getConnection();
@ -15,8 +15,13 @@ class Application_Common_Database
$rows = $stmt->fetch($fetchType); $rows = $stmt->fetch($fetchType);
} else if ($type == 'column'){ } else if ($type == 'column'){
$rows = $stmt->fetchColumn(); $rows = $stmt->fetchColumn();
} else { } else if ($type == 'all') {
$rows = $stmt->fetchAll($fetchType); $rows = $stmt->fetchAll($fetchType);
} else if ($type == 'execute') {
$rows = null;
} else {
$msg = "bad type passed: type($type)";
throw new Exception("Error: $msg");
} }
} else { } else {
$msg = implode(',', $stmt->errorInfo()); $msg = implode(',', $stmt->errorInfo());

View File

@ -175,7 +175,7 @@ class Application_Model_Playlist implements Application_Model_LibraryEditable
f.length AS orig_length f.length AS orig_length
FROM cc_playlistcontents AS pc FROM cc_playlistcontents AS pc
JOIN cc_files AS f ON pc.file_id=f.id JOIN cc_files AS f ON pc.file_id=f.id
WHERE pc.playlist_id = {$this->id} WHERE pc.playlist_id = :playlist_id1
AND TYPE = 0) AND TYPE = 0)
UNION ALL UNION ALL
(SELECT pc.id AS id, (SELECT pc.id AS id,
@ -194,7 +194,7 @@ class Application_Model_Playlist implements Application_Model_LibraryEditable
FROM cc_playlistcontents AS pc FROM cc_playlistcontents AS pc
JOIN cc_webstream AS ws ON pc.stream_id=ws.id JOIN cc_webstream AS ws ON pc.stream_id=ws.id
LEFT JOIN cc_subjs AS sub ON sub.id = ws.creator_id LEFT JOIN cc_subjs AS sub ON sub.id = ws.creator_id
WHERE pc.playlist_id = {$this->id} WHERE pc.playlist_id = :playlist_id2
AND pc.TYPE = 1) AND pc.TYPE = 1)
UNION ALL UNION ALL
(SELECT pc.id AS id, (SELECT pc.id AS id,
@ -213,13 +213,12 @@ class Application_Model_Playlist implements Application_Model_LibraryEditable
FROM cc_playlistcontents AS pc FROM cc_playlistcontents AS pc
JOIN cc_block AS bl ON pc.block_id=bl.id JOIN cc_block AS bl ON pc.block_id=bl.id
JOIN cc_subjs AS sbj ON bl.creator_id=sbj.id JOIN cc_subjs AS sbj ON bl.creator_id=sbj.id
WHERE pc.playlist_id = {$this->id} WHERE pc.playlist_id = :playlist_id3
AND pc.TYPE = 2)) AS temp AND pc.TYPE = 2)) AS temp
ORDER BY temp.position; ORDER BY temp.position;
SQL; SQL;
$con = Propel::getConnection(); $rows = Application_Common_Database::prepareAndExecute($sql, array(':playlist_id1'=>$this->id, ':playlist_id2'=>$this->id, ':playlist_id3'=>$this->id));
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$offset = 0; $offset = 0;
foreach ($rows as &$row) { foreach ($rows as &$row) {
@ -291,9 +290,9 @@ SQL;
{ {
$sql = "SELECT bl.id FROM cc_playlistcontents as pc $sql = "SELECT bl.id FROM cc_playlistcontents as pc
JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic' JOIN cc_block as bl ON pc.type=2 AND pc.block_id=bl.id AND bl.type='dynamic'
WHERE playlist_id={$this->id} AND pc.type=2"; WHERE playlist_id=:playlist_id AND pc.type=2";
$r = $this->con->query($sql);
$result = $r->fetchAll(PDO::FETCH_ASSOC); $result = Application_Common_Database::prepareAndExecute($sql, array(':playlist_id'=>$this->id));
return $result; return $result;
} }
@ -625,9 +624,8 @@ SQL;
if (!is_null($fadeIn)) { if (!is_null($fadeIn)) {
$sql = "SELECT INTERVAL '{$fadeIn}' > INTERVAL '{$clipLength}'"; $sql = "SELECT INTERVAL :fadein > INTERVAL '{$clipLength}'";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':fadein'=>$fadeIn), 'column')) {
if ($r->fetchColumn(0)) {
//"Fade In can't be larger than overall playlength."; //"Fade In can't be larger than overall playlength.";
$fadeIn = $clipLength; $fadeIn = $clipLength;
} }
@ -635,9 +633,8 @@ SQL;
} }
if (!is_null($fadeOut)) { if (!is_null($fadeOut)) {
$sql = "SELECT INTERVAL '{$fadeOut}' > INTERVAL '{$clipLength}'"; $sql = "SELECT INTERVAL :fadeout > INTERVAL '{$clipLength}'";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':fadeout'=>$fadeOut), 'column')) {
if ($r->fetchColumn(0)) {
//Fade Out can't be larger than overall playlength."; //Fade Out can't be larger than overall playlength.";
$fadeOut = $clipLength; $fadeOut = $clipLength;
} }
@ -727,25 +724,22 @@ SQL;
$cueOut = $origLength; $cueOut = $origLength;
} }
$sql = "SELECT INTERVAL '{$cueIn}' > INTERVAL '{$cueOut}'"; $sql = "SELECT INTERVAL :cueIn > INTERVAL :cueOut";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':cueIn'=>$cueIn, ':cueOut'=>$cueOut), 'column')) {
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue in to be larger than cue out."; $errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray; return $errArray;
} }
$sql = "SELECT INTERVAL '{$cueOut}' > INTERVAL '{$origLength}'"; $sql = "SELECT INTERVAL :cueOut > INTERVAL :origLength";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':cueOut'=>$cueOut, ':origLength'=>$origLength), 'column')) {
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be greater than file length."; $errArray["error"] = "Can't set cue out to be greater than file length.";
return $errArray; return $errArray;
} }
$sql = "SELECT INTERVAL '{$cueOut}' - INTERVAL '{$cueIn}'"; $sql = "SELECT INTERVAL :cueOut - INTERVAL :cueIn";
$r = $this->con->query($sql); $cliplength = Application_Common_Database::prepareAndExecute($sql, array(':cueOut'=>$cueOut, ':cueIn'=>$cueIn), 'column');
$cliplength = $r->fetchColumn(0);
$row->setDbCuein($cueIn); $row->setDbCuein($cueIn);
$row->setDbCueout($cueOut); $row->setDbCueout($cueOut);
@ -753,17 +747,15 @@ SQL;
} elseif (!is_null($cueIn)) { } elseif (!is_null($cueIn)) {
$sql = "SELECT INTERVAL '{$cueIn}' > INTERVAL '{$oldCueOut}'"; $sql = "SELECT INTERVAL :cueIn > INTERVAL :oldCueOut";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':cueIn'=>$cueIn, ':oldCueOut'=>$oldCueOut), 'column')) {
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue in to be larger than cue out."; $errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray; return $errArray;
} }
$sql = "SELECT INTERVAL '{$oldCueOut}' - INTERVAL '{$cueIn}'"; $sql = "SELECT INTERVAL :oldCueOut - INTERVAL :cueIn";
$r = $this->con->query($sql); $cliplength = Application_Common_Database::prepareAndExecute($sql, array(':cueIn'=>$cueIn, ':oldCueOut'=>$oldCueOut, 'column'));
$cliplength = $r->fetchColumn(0);
$row->setDbCuein($cueIn); $row->setDbCuein($cueIn);
$row->setDBCliplength($cliplength); $row->setDBCliplength($cliplength);
@ -773,25 +765,22 @@ SQL;
$cueOut = $origLength; $cueOut = $origLength;
} }
$sql = "SELECT INTERVAL '{$cueOut}' < INTERVAL '{$oldCueIn}'"; $sql = "SELECT INTERVAL :cueOut < INTERVAL :oldCueIn";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':cueOut'=>$cueOut, ':oldCueIn'=>$oldCueIn, 'column'))) {
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be smaller than cue in."; $errArray["error"] = "Can't set cue out to be smaller than cue in.";
return $errArray; return $errArray;
} }
$sql = "SELECT INTERVAL '{$cueOut}' > INTERVAL '{$origLength}'"; $sql = "SELECT INTERVAL :cueOut > INTERVAL :origLength";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':cueOut'=>$cueOut, ':origLength'=>$origLength, 'column'))) {
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be greater than file length."; $errArray["error"] = "Can't set cue out to be greater than file length.";
return $errArray; return $errArray;
} }
$sql = "SELECT INTERVAL '{$cueOut}' - INTERVAL '{$oldCueIn}'"; $sql = "SELECT INTERVAL :cueOut - INTERVAL :oldCueIn";
$r = $this->con->query($sql); $cliplength = Application_Common_Database::prepareAndExecute($sql, array(':cueOut'=>$cueOut, ':oldCueIn'=>$oldCueIn, 'column'));
$cliplength = $r->fetchColumn(0);
$row->setDbCueout($cueOut); $row->setDbCueout($cueOut);
$row->setDBCliplength($cliplength); $row->setDBCliplength($cliplength);
@ -799,16 +788,14 @@ SQL;
$cliplength = $row->getDbCliplength(); $cliplength = $row->getDbCliplength();
$sql = "SELECT INTERVAL '{$fadeIn}' > INTERVAL '{$cliplength}'"; $sql = "SELECT INTERVAL :fadeIn > INTERVAL :cliplength";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':fadeIn'=>$fadeIn, ':cliplength'=>$cliplength, 'column'))) {
if ($r->fetchColumn(0)) {
$fadeIn = $cliplength; $fadeIn = $cliplength;
$row->setDbFadein($fadeIn); $row->setDbFadein($fadeIn);
} }
$sql = "SELECT INTERVAL '{$fadeOut}' > INTERVAL '{$cliplength}'"; $sql = "SELECT INTERVAL :fadeOut > INTERVAL :cliplength";
$r = $this->con->query($sql); if (Application_Common_Database::prepareAndExecute($sql, array(':fadeOut'=>$fadeOut, ':cliplength'=>$cliplength, 'column'))) {
if ($r->fetchColumn(0)) {
$fadeOut = $cliplength; $fadeOut = $cliplength;
$row->setDbFadein($fadeOut); $row->setDbFadein($fadeOut);
} }

View File

@ -18,48 +18,57 @@ class Application_Model_Preference
//Check if key already exists //Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref" $sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = '$key'"; ." WHERE keystr = :key";
$paramMap = array();
$paramMap[':key'] = $key;
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if ($isUserValue) { if ($isUserValue) {
$sql .= " AND subjid = '$id'"; $sql .= " AND subjid = :id";
$paramMap[':id'] = $id;
} }
$result = $con->query($sql)->fetchColumn(0); $result = Application_Common_Database::prepareAndExecute($sql, $paramMap, 'column');
if ($value == "") { if ($value == "") {
$value = "NULL"; $value = "NULL";
} else { } else {
$value = "'$value'"; $value = "$value";
} }
$paramMap = array();
if ($result == 1) { if ($result == 1) {
// result found // result found
if (is_null($id) || !$isUserValue) { if (is_null($id) || !$isUserValue) {
// system pref // system pref
$sql = "UPDATE cc_pref" $sql = "UPDATE cc_pref"
." SET subjid = NULL, valstr = $value" ." SET subjid = NULL, valstr = :value"
." WHERE keystr = '$key'"; ." WHERE keystr = :key";
} else { } else {
// user pref // user pref
$sql = "UPDATE cc_pref" $sql = "UPDATE cc_pref"
. " SET valstr = $value" . " SET valstr = :value"
. " WHERE keystr = '$key' AND subjid = $id"; . " WHERE keystr = :key AND subjid = :id";
$paramMap[':id'] = $id;
} }
} else { } else {
// result not found // result not found
if (is_null($id) || !$isUserValue) { if (is_null($id) || !$isUserValue) {
// system pref // system pref
$sql = "INSERT INTO cc_pref (keystr, valstr)" $sql = "INSERT INTO cc_pref (keystr, valstr)"
." VALUES ('$key', $value)"; ." VALUES (:key, :value)";
} else { } else {
// user pref // user pref
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)" $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES ($id, '$key', $value)"; ." VALUES (:id, :key, :value)";
$paramMap[':id'] = $id;
} }
} }
$paramMap[':key'] = $key;
$paramMap[':value'] = $value;
$con->exec($sql); Application_Common_Database::prepareAndExecute($sql, $paramMap, 'execute');
} catch (Exception $e) { } catch (Exception $e) {
header('HTTP/1.0 503 Service Unavailable'); header('HTTP/1.0 503 Service Unavailable');
@ -77,28 +86,39 @@ class Application_Model_Preference
//Check if key already exists //Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref" $sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = '$key'"; ." WHERE keystr = '$key'";
/*." WHERE keystr = :key";
$paramMap = array();
$paramMap[':key'] = $key;*/
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if ($isUserValue) { if ($isUserValue) {
$auth = Zend_Auth::getInstance(); $auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) { if ($auth->hasIdentity()) {
$id = $auth->getIdentity()->id; $id = $auth->getIdentity()->id;
$sql .= " AND subjid = '$id'"; $sql .= " AND subjid = '$id'";
/*$sql .= " AND subjid = :id";
$paramMap[':id'] = $id;*/
} }
} }
$result = $con->query($sql)->fetchColumn(0); $result = $con->query($sql)->fetchColumn(0);
//$result = Application_Common_Database::prepareAndExecute($sql, $paramMap, 'column');
if ($result == 0) if ($result == 0)
return ""; return "";
else { else {
$sql = "SELECT valstr FROM cc_pref" $sql = "SELECT valstr FROM cc_pref"
." WHERE keystr = '$key'"; ." WHERE keystr = '$key'";
/*." WHERE keystr = :key";
$paramMap = array();
$paramMap[':key'] = $key;*/
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if ($isUserValue && $auth->hasIdentity()) { if ($isUserValue && $auth->hasIdentity()) {
$sql .= " AND subjid = '$id'"; $sql .= " AND subjid = '$id'";
/*$sql .= " AND subjid = :id";
$paramMap[':id'] = $id;*/
} }
$result = $con->query($sql)->fetchColumn(0); $result = $con->query($sql)->fetchColumn(0);
//$result = Application_Common_Database::prepareAndExecute($sql, $paramMap, 'column');
return ($result !== false) ? $result : ""; return ($result !== false) ? $result : "";
} }

View File

@ -10,10 +10,9 @@ class Application_Model_Schedule
public function IsFileScheduledInTheFuture($p_fileId) public function IsFileScheduledInTheFuture($p_fileId)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"] $sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"]
." WHERE file_id = {$p_fileId} AND ends > NOW() AT TIME ZONE 'UTC'"; ." WHERE file_id = :file_id AND ends > NOW() AT TIME ZONE 'UTC'";
$count = $con->query($sql)->fetchColumn(0); $count = Application_Common_Database::prepareAndExecute($sql, array(':file_id'=>$p_fileId), 'column');
return (is_numeric($count) && ($count != '0')); return (is_numeric($count) && ($count != '0'));
} }
@ -88,14 +87,18 @@ class Application_Model_Schedule
LEFT JOIN (SELECT * FROM cc_webstream_metadata ORDER BY start_time DESC LIMIT 1) AS wm on st.id = wm.instance_id"; LEFT JOIN (SELECT * FROM cc_webstream_metadata ORDER BY start_time DESC LIMIT 1) AS wm on st.id = wm.instance_id";
$predicateArr = array(); $predicateArr = array();
$paramMap = array();
if (isset($p_previousShowID)) { if (isset($p_previousShowID)) {
$predicateArr[] = 'st.instance_id = '.$p_previousShowID; $predicateArr[] = 'st.instance_id = :previousShowId';
$paramMap[':previousShowId'] = $p_previousShowID;
} }
if (isset($p_currentShowID)) { if (isset($p_currentShowID)) {
$predicateArr[] = 'st.instance_id = '.$p_currentShowID; $predicateArr[] = 'st.instance_id = :currentShowId';
$paramMap[':currentShowId'] = $p_currentShowID;
} }
if (isset($p_nextShowID)) { if (isset($p_nextShowID)) {
$predicateArr[] = 'st.instance_id = '.$p_nextShowID; $predicateArr[] = 'st.instance_id = :nextShowId';
$paramMap[':nextShowId'] = $p_nextShowID;
} }
$sql .= " (".implode(" OR ", $predicateArr).") "; $sql .= " (".implode(" OR ", $predicateArr).") ";
@ -109,7 +112,7 @@ class Application_Model_Schedule
$sql = "SELECT * FROM (($filesSql) UNION ($streamSql)) AS unioned ORDER BY starts"; $sql = "SELECT * FROM (($filesSql) UNION ($streamSql)) AS unioned ORDER BY starts";
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC); $rows = Application_Common_Database::prepareAndExecute($sql, $paramMap);
$numberOfRows = count($rows); $numberOfRows = count($rows);
$results['previous'] = null; $results['previous'] = null;
@ -169,7 +172,6 @@ class Application_Model_Schedule
public static function GetLastScheduleItem($p_timeNow) public static function GetLastScheduleItem($p_timeNow)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT" $sql = "SELECT"
." ft.artist_name, ft.track_title," ." ft.artist_name, ft.track_title,"
." st.starts as starts, st.ends as ends" ." st.starts as starts, st.ends as ends"
@ -178,13 +180,13 @@ class Application_Model_Schedule
." ON st.file_id = ft.id" ." ON st.file_id = ft.id"
." LEFT JOIN $CC_CONFIG[showInstances] sit" ." LEFT JOIN $CC_CONFIG[showInstances] sit"
." ON st.instance_id = sit.id" ." ON st.instance_id = sit.id"
." WHERE st.ends < TIMESTAMP '$p_timeNow'" ." 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.starts" //this and the next line are necessary since we can overbook shows.
." AND st.starts < sit.ends" ." AND st.starts < sit.ends"
." ORDER BY st.ends DESC" ." ORDER BY st.ends DESC"
." LIMIT 1"; ." LIMIT 1";
$row = $con->query($sql)->fetchAll(); $row = Application_Common_Database::prepareAndExecute($sql, array(':timeNow'=>$p_timeNow));
return $row; return $row;
} }
@ -192,7 +194,6 @@ class Application_Model_Schedule
public static function GetCurrentScheduleItem($p_timeNow, $p_instanceId) public static function GetCurrentScheduleItem($p_timeNow, $p_instanceId)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection();
/* Note that usually there will be one result returned. In some /* Note that usually there will be one result returned. In some
* rare cases two songs are returned. This happens when a track * rare cases two songs are returned. This happens when a track
* that was overbooked from a previous show appears as if it * that was overbooked from a previous show appears as if it
@ -204,13 +205,13 @@ class Application_Model_Schedule
." FROM $CC_CONFIG[scheduleTable] st" ." FROM $CC_CONFIG[scheduleTable] st"
." LEFT JOIN $CC_CONFIG[filesTable] ft" ." LEFT JOIN $CC_CONFIG[filesTable] ft"
." ON st.file_id = ft.id" ." ON st.file_id = ft.id"
." WHERE st.starts <= TIMESTAMP '$p_timeNow'" ." WHERE st.starts <= TIMESTAMP :timeNow1"
." AND st.instance_id = $p_instanceId" ." AND st.instance_id = :instanceId"
." AND st.ends > TIMESTAMP '$p_timeNow'" ." AND st.ends > TIMESTAMP :timeNow2"
." ORDER BY st.starts DESC" ." ORDER BY st.starts DESC"
." LIMIT 1"; ." LIMIT 1";
$row = $con->query($sql)->fetchAll(); $row = Application_Common_Database::prepareAndExecute($sql, array(':timeNow1'=>$p_timeNow, ':instanceId'=>$p_instanceId, ':timeNow2'=>$p_timeNow,));
return $row; return $row;
} }
@ -218,7 +219,6 @@ class Application_Model_Schedule
public static function GetNextScheduleItem($p_timeNow) public static function GetNextScheduleItem($p_timeNow)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT" $sql = "SELECT"
." ft.artist_name, ft.track_title," ." ft.artist_name, ft.track_title,"
." st.starts as starts, st.ends as ends" ." st.starts as starts, st.ends as ends"
@ -227,13 +227,13 @@ class Application_Model_Schedule
." ON st.file_id = ft.id" ." ON st.file_id = ft.id"
." LEFT JOIN $CC_CONFIG[showInstances] sit" ." LEFT JOIN $CC_CONFIG[showInstances] sit"
." ON st.instance_id = sit.id" ." ON st.instance_id = sit.id"
." WHERE st.starts > TIMESTAMP '$p_timeNow'" ." WHERE st.starts > TIMESTAMP :timeNow"
." AND st.starts >= sit.starts" //this and the next line are necessary since we can overbook shows. ." AND st.starts >= sit.starts" //this and the next line are necessary since we can overbook shows.
." AND st.starts < sit.ends" ." AND st.starts < sit.ends"
." ORDER BY st.starts" ." ORDER BY st.starts"
." LIMIT 1"; ." LIMIT 1";
$row = $con->query($sql)->fetchAll(); $row = Application_Common_Database::prepareAndExecute($sql, array(':timeNow'=>$p_timeNow));
return $row; return $row;
} }
@ -514,7 +514,6 @@ SQL;
public static function GetItems($p_startTime, $p_endTime) public static function GetItems($p_startTime, $p_endTime)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection();
$baseQuery = "SELECT st.file_id AS file_id," $baseQuery = "SELECT st.file_id AS file_id,"
." st.id AS id," ." st.id AS id,"
@ -540,15 +539,15 @@ SQL;
." LEFT JOIN cc_webstream AS ws" ." LEFT JOIN cc_webstream AS ws"
." ON st.stream_id = ws.id"; ." ON st.stream_id = ws.id";
$predicates = " WHERE st.ends > '$p_startTime'" $predicates = " WHERE st.ends > :startTime1"
." AND st.starts < '$p_endTime'" ." AND st.starts < :endTime"
." AND st.playout_status > 0" ." AND st.playout_status > 0"
." AND si.ends > '$p_startTime'" ." AND si.ends > :startTime2"
." ORDER BY st.starts"; ." ORDER BY st.starts";
$sql = $baseQuery.$predicates; $sql = $baseQuery.$predicates;
$rows = $con->query($sql)->fetchAll(); $rows = Application_Common_Database::prepareAndExecute($sql, array(':startTime1'=>$p_startTime, ':endTime'=>$p_endTime, ':startTime2'=>$p_startTime));
if (count($rows) < 3) { if (count($rows) < 3) {
Logging::debug("Get Schedule: Less than 3 results returned. Doing another query since we need a minimum of 3 results."); Logging::debug("Get Schedule: Less than 3 results returned. Doing another query since we need a minimum of 3 results.");
@ -557,15 +556,15 @@ SQL;
$dt->add(new DateInterval("PT24H")); $dt->add(new DateInterval("PT24H"));
$range_end = $dt->format("Y-m-d H:i:s"); $range_end = $dt->format("Y-m-d H:i:s");
$predicates = " WHERE st.ends > '$p_startTime'" $predicates = " WHERE st.ends > :startTime1"
." AND st.starts < '$range_end'" ." AND st.starts < :rangeEnd"
." AND st.playout_status > 0" ." AND st.playout_status > 0"
." AND si.ends > '$p_startTime'" ." AND si.ends > :startTime2"
." ORDER BY st.starts" ." ORDER BY st.starts"
." LIMIT 3"; ." LIMIT 3";
$sql = $baseQuery.$predicates; $sql = $baseQuery.$predicates;
$rows = $con->query($sql)->fetchAll(); $rows = Application_Common_Database::prepareAndExecute($sql, array(':startTime1'=>$p_startTime, ':rangeEnd'=>$range_end, ':startTime2'=>$p_startTime));
} }
return $rows; return $rows;
@ -748,9 +747,8 @@ SQL;
public static function deleteWithFileId($fileId) public static function deleteWithFileId($fileId)
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection(); $sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"]." WHERE file_id=:file_id";
$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"]." WHERE file_id=$fileId"; $res = Application_Common_Database::prepareAndExecute($sql, array(':file_id'=>$fileId), 'execute');
$res = $con->query($sql);
} }
public static function createNewFormSections($p_view) public static function createNewFormSections($p_view)
@ -861,12 +859,12 @@ SQL;
$formStyle->disable(); $formStyle->disable();
//$formLive->disable(); //$formLive->disable();
$controller->view->what = $formWhat; $controller->view->what = $formWhat;
$controller->view->when = $formWhen; $controller->view->when = $formWhen;
$controller->view->repeats = $formRepeats; $controller->view->repeats = $formRepeats;
$controller->view->who = $formWho; $controller->view->who = $formWho;
$controller->view->style = $formStyle; $controller->view->style = $formStyle;
$controller->view->live = $formLive; $controller->view->live = $formLive;
if (!$isSaas) { if (!$isSaas) {
$controller->view->rr = $formRecord; $controller->view->rr = $formRecord;
$controller->view->absoluteRebroadcast = $formAbsoluteRebroadcast; $controller->view->absoluteRebroadcast = $formAbsoluteRebroadcast;
@ -1091,7 +1089,7 @@ SQL;
and date(starts) >= (date('{$show_end->format('Y-m-d H:i:s')}') - INTERVAL '2 days') and date(starts) >= (date('{$show_end->format('Y-m-d H:i:s')}') - INTERVAL '2 days')
and modified_instance = false order by ends"; and modified_instance = false order by ends";
$stmt = $con->prepare("SELECT id, starts, ends FROM $stmt = $con->prepare("SELECT id, starts, ends FROM
{$CC_CONFIG['showInstances']} {$CC_CONFIG['showInstances']}
where (ends <= :show_end1 or starts <= :show_end2) where (ends <= :show_end1 or starts <= :show_end2)
and date(starts) >= (date(:show_end3) - INTERVAL '2 days') and date(starts) >= (date(:show_end3) - INTERVAL '2 days')

View File

@ -803,12 +803,19 @@ SQL;
':add_show_id' => $p_data['add_show_id'] ':add_show_id' => $p_data['add_show_id']
)); ));
$sql = "UPDATE cc_show_instances "
."SET ends = starts + INTERVAL '$p_data[add_show_duration]' "
."WHERE show_id = $p_data[add_show_id] "
."AND ends > TIMESTAMP '$timestamp'";
$con->exec($sql);
$sql = <<<SQL
UPDATE cc_show_instances
SET ends = starts + :add_show_duration::INTERVAL
WHERE show_id = :show_id
AND ends > :timestamp::TIMESTAMP
SQL;
Application_Common_Database::prepareAndExecute( $sql, array(
':add_show_duration' => $p_data['add_show_duration'],
':show_id' => $p_data['add_show_id'],
':timestamp' => $timestamp), "execute");
} }
private function updateStartDateTime($p_data, $p_endDate) private function updateStartDateTime($p_data, $p_endDate)

View File

@ -35,7 +35,8 @@ var AIRTIME = (function(AIRTIME) {
"sample_rate" : "n", "sample_rate" : "n",
"track_title" : "s", "track_title" : "s",
"track_num" : "n", "track_num" : "n",
"year" : "n" "year" : "n",
"owner" : "s"
}; };
if (AIRTIME.library === undefined) { if (AIRTIME.library === undefined) {