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

This commit is contained in:
Rudi Grinberg 2012-09-05 10:17:04 -04:00
commit 1590bf4fa0
7 changed files with 242 additions and 100 deletions

View File

@ -196,11 +196,19 @@ class Application_Model_Block implements Application_Model_LibraryEditable
f.id as item_id, f.track_title, f.artist_name as creator, f.file_exists as exists, f.filepath as path FROM cc_blockcontents AS pc
LEFT JOIN cc_files AS f ON pc.file_id=f.id
LEFT JOIN cc_block AS bl ON pc.block_id = bl.id
WHERE pc.block_id = {$this->id}
WHERE pc.block_id = :block_id
ORDER BY pc.position;
EOT;
$con = Propel::getConnection();
$rows = $con->query($sql)->fetchAll();
$stmt = $con->prepare($sql);
$stmt->bindParam(':block_id', $this->id);
if ($stmt->execute()) {
$rows = $stmt->fetchAll();
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$offset = 0;
foreach ($rows as &$row) {
@ -323,10 +331,17 @@ EOT;
// this function returns sum of all track length under this block.
public function getStaticLength()
{
$sql = "SELECT SUM(cliplength) as length FROM cc_blockcontents WHERE block_id={$this->id}";
$r = $this->con->query($sql);
$result = $r->fetchAll(PDO::FETCH_NUM);
$sql = "SELECT SUM(cliplength) as length FROM cc_blockcontents WHERE block_id = :block_id";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':block_id', $this->id);
if ($stmt->execute()) {
$result = $stmt->fetchAll(PDO::FETCH_NUM);
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("error: $msg");
}
return $result[0][0];
}
@ -446,7 +461,7 @@ EOT;
$pos = $pos + 1;
}
} catch (Exception $e) {
Logging::log($e->getMessage());
Logging::info($e->getMessage());
}
}
@ -637,21 +652,40 @@ EOT;
if (!is_null($fadeIn)) {
$sql = "SELECT INTERVAL '{$fadeIn}' > INTERVAL '{$clipLength}'";
$r = $this->con->query($sql);
if ($r->fetchColumn(0)) {
//"Fade In can't be larger than overall playlength.";
$fadeIn = $clipLength;
$sql = "SELECT :fade_in::INTERVAL > :clip_length::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':fade_in', $fadeIn);
$stmt->bindParam(':clip_length', $clipLength);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
//"Fade In can't be larger than overall playlength.";
$fadeIn = $clipLength;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$row->setDbFadein($fadeIn);
}
if (!is_null($fadeOut)) {
$sql = "SELECT INTERVAL '{$fadeOut}' > INTERVAL '{$clipLength}'";
$r = $this->con->query($sql);
if ($r->fetchColumn(0)) {
//Fade Out can't be larger than overall playlength.";
$fadeOut = $clipLength;
$sql = "SELECT :fade_out::INTERVAL > :clip_length::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':fade_out', $fadeOut);
$stmt->bindParam(':clip_length', $clipLength);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
//Fade Out can't be larger than overall playlength.";
$fadeOut = $clipLength;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$row->setDbFadeout($fadeOut);
}
@ -739,25 +773,52 @@ EOT;
$cueOut = $origLength;
}
$sql = "SELECT INTERVAL '{$cueIn}' > INTERVAL '{$cueOut}'";
$r = $this->con->query($sql);
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue in to be larger than cue out.";
$sql = "SELECT :cue_in::INTERVAL > :cue_out::INTERVAL";
return $errArray;
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_in', $cueIn);
$stmt->bindParam(':cue_out', $cueOut);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$sql = "SELECT INTERVAL '{$cueOut}' > INTERVAL '{$origLength}'";
$r = $this->con->query($sql);
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be greater than file length.";
$sql = "SELECT :cue_out::INTERVAL > INTERVAL :orig_length::INTERVAL";
return $errArray;
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_out', $cueOut);
$stmt->bindParam(':orig_length', $origLength);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be greater than file length.";
return $errArray;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$sql = "SELECT INTERVAL '{$cueOut}' - INTERVAL '{$cueIn}'";
$r = $this->con->query($sql);
$cliplength = $r->fetchColumn(0);
$sql = "SELECT :cue_out::INTERVAL - :cue_in::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_out', $cueOut);
$stmt->bindParam(':cue_in', $cueIn);
if ($stmt->execute()) {
$cliplength = $stmt->fetchColumn(0);
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$row->setDbCuein($cueIn);
$row->setDbCueout($cueOut);
@ -765,17 +826,35 @@ EOT;
} elseif (!is_null($cueIn)) {
$sql = "SELECT INTERVAL '{$cueIn}' > INTERVAL '{$oldCueOut}'";
$r = $this->con->query($sql);
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray;
$sql = "SELECT :cue_in::INTERVAL > :old_cue_out::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_in', $cueIn);
$stmt->bindParam(':old_cue_out', $oldCueOut);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$sql = "SELECT INTERVAL '{$oldCueOut}' - INTERVAL '{$cueIn}'";
$r = $this->con->query($sql);
$cliplength = $r->fetchColumn(0);
$sql = "SELECT :old_cue_out::INTERVAL - :cue_in::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':old_cue_out', $oldCueOut);
$stmt->bindParam(':cue_in', $cueIn);
if ($stmt->execute()) {
$cliplength = $stmt->fetchColumn(0);
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$row->setDbCuein($cueIn);
$row->setDBCliplength($cliplength);
@ -785,25 +864,52 @@ EOT;
$cueOut = $origLength;
}
$sql = "SELECT INTERVAL '{$cueOut}' < INTERVAL '{$oldCueIn}'";
$r = $this->con->query($sql);
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be smaller than cue in.";
$sql = "SELECT :cue_out::INTERVAL < :old_cue_in::INTERVAL";
return $errArray;
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_out', $cueOut);
$stmt->bindParam(':old_cue_in', $oldCueIn);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be smaller than cue in.";
return $errArray;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$sql = "SELECT INTERVAL '{$cueOut}' > INTERVAL '{$origLength}'";
$r = $this->con->query($sql);
if ($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be greater than file length.";
$sql = "SELECT :cue_out::INTERVAL > :orig_length::INTERVAL";
return $errArray;
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_out', $cueOut);
$stmt->bindParam(':orig_length', $origLength);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be greater than file length.";
return $errArray;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$sql = "SELECT INTERVAL '{$cueOut}' - INTERVAL '{$oldCueIn}'";
$r = $this->con->query($sql);
$cliplength = $r->fetchColumn(0);
$sql = "SELECT :cue_out::INTERVAL - :old_cue_in::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_out', $cueOut);
$stmt->bindParam(':old_cue_in', $oldCueIn);
if ($stmt->execute()) {
$cliplength = $stmt->fetchColumn(0);
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$row->setDbCueout($cueOut);
$row->setDBCliplength($cliplength);
@ -811,18 +917,36 @@ EOT;
$cliplength = $row->getDbCliplength();
$sql = "SELECT INTERVAL '{$fadeIn}' > INTERVAL '{$cliplength}'";
$r = $this->con->query($sql);
if ($r->fetchColumn(0)) {
$fadeIn = $cliplength;
$row->setDbFadein($fadeIn);
$sql = "SELECT :fade_in::INTERVAL > :clip_length::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':fade_in', $fadeIn);
$stmt->bindParam(':clip_length', $cliplength);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$fadeIn = $cliplength;
$row->setDbFadein($fadeIn);
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$sql = "SELECT INTERVAL '{$fadeOut}' > INTERVAL '{$cliplength}'";
$r = $this->con->query($sql);
if ($r->fetchColumn(0)) {
$fadeOut = $cliplength;
$row->setDbFadein($fadeOut);
$sql = "SELECT :fade_out::INTERVAL > :clip_length::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':fade_out', $fadeOut);
$stmt->bindParam(':clip_length', $cliplength);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$fadeOut = $cliplength;
$row->setDbFadein($fadeOut);
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$row->save($this->con);

View File

@ -322,10 +322,21 @@ class Application_Model_StoredFile
{
global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT playlist_id "
." FROM ".$CC_CONFIG['playistTable']
." WHERE file_id='{$this->id}'";
$ids = $con->query($sql)->fetchAll();
." FROM cc_playlist"
." WHERE file_id = :file_id";
$stmt = $con->prepare($sql);
$stmt->bindParam(':file_id', $this->id, PDO::PARAM_INT);
if ($stmt->execute()) {
$ids = $stmt->fetchAll();
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$playlists = array();
if (is_array($ids) && count($ids) > 0) {
foreach ($ids as $id) {
@ -951,7 +962,7 @@ class Application_Model_StoredFile
$uid = $user->getId();
}
$id_file = "$audio_stor.identifier";
if (file_put_contents($id_file,$uid) === false) {
if (file_put_contents($id_file, $uid) === false) {
Logging::info("Could not write file to identify user: '$uid'");
Logging::info("Id file path: '$id_file'");
Logging::info("Defaulting to admin (no identification file was
@ -1003,7 +1014,7 @@ class Application_Model_StoredFile
global $CC_CONFIG;
$con = Propel::getConnection();
$sql = "SELECT count(*) as cnt FROM ".$CC_CONFIG["filesTable"]." WHERE file_exists";
$sql = "SELECT count(*) as cnt FROM cc_files WHERE file_exists";
return $con->query($sql)->fetchColumn(0);
}
@ -1012,53 +1023,59 @@ class Application_Model_StoredFile
*
* Enter description here ...
* @param $dir_id - if this is not provided, it returns all files with full path constructed.
* @param $propelObj - if this is true, it returns array of proepl obj
*/
public static function listAllFiles($dir_id=null, $all, $propelObj=false)
public static function listAllFiles($dir_id=null, $all)
{
$con = Propel::getConnection();
$file_exists = $all ? "" : "and f.file_exists = 'TRUE'";
if ($propelObj) {
$sql = "SELECT m.directory || f.filepath as fp"
." FROM CC_MUSIC_DIRS m"
." LEFT JOIN CC_FILES f"
." ON m.id = f.directory WHERE m.id = $dir_id $file_exists";
} else {
$sql = "SELECT filepath as fp"
." FROM CC_FILES as f"
." WHERE f.directory = $dir_id $file_exists";
$sql = "SELECT filepath as fp"
." FROM CC_FILES as f"
." WHERE f.directory = :dir_id";
if (!$all) {
$sql .= " AND f.file_exists = 'TRUE'";
}
$rows = $con->query($sql)->fetchAll();
$stmt = $con->prepare($sql);
$stmt->bindParam(':dir_id', $dir_id);
if ($stmt->execute()) {
$rows = $stmt->fetchAll();
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$results = array();
foreach ($rows as $row) {
if ($propelObj) {
$results[] = Application_Model_StoredFile::RecallByFilepath($row["fp"]);
} else {
$results[] = $row["fp"];
}
$results[] = $row["fp"];
}
return $results;
}
//TODO: MERGE THIS FUNCTION AND "listAllFiles" -MK
public static function listAllFiles2($dir_id=null, $limit=null)
public static function listAllFiles2($dir_id=null, $limit="ALL")
{
$con = Propel::getConnection();
$sql = "SELECT id, filepath as fp"
." FROM CC_FILES"
." WHERE directory = $dir_id"
." WHERE directory = :dir_id"
." AND file_exists = 'TRUE'"
." AND replay_gain is NULL";
if (!is_null($limit) && is_int($limit)) {
$sql .= " LIMIT $limit";
}
." AND replay_gain is NULL"
." LIMIT :lim";
$rows = $con->query($sql, PDO::FETCH_ASSOC)->fetchAll();
$stmt = $con->prepare($sql);
$stmt->bindParam(':dir_id', $dir_id);
$stmt->bindParam(':lim', $limit);
if ($stmt->execute()) {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
return $rows;
}

View File

@ -175,15 +175,13 @@ class Application_Model_StreamSetting
*/
public static function setStreamSetting($data)
{
$con = Propel::getConnection();
foreach ($data as $key => $d) {
if ($key == "output_sound_device" || $key == "icecast_vorbis_metadata") {
$v = $d == 1?"true":"false";
$v = ($d == 1) ? "true" : "false";
self::saveStreamSetting($key, $v);
} elseif ($key == "output_sound_device_type") {
self::saveStreamSetting($key, $v);
self::saveStreamSetting($key, $d);
} elseif (is_array($d)) {
$temp = explode('_', $key);
$prefix = $temp[0];

View File

@ -168,6 +168,9 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
if ($result == 0) {
$valid['url'][0] = false;
$valid['url'][1] = 'URL should be of form "http://domain"';
} elseif (strlen($url) > 512) {
$valid['url'][0] = false;
$valid['url'][1] = 'URL should be 512 characters or less';
} else {
try {

View File

@ -4,7 +4,7 @@
<p>Here's how you can get started using Airtime to automate your broadcasts: </p>
<ol>
<li>Add your files to the library using the "Add Media" button. You can drag and drop your files to this window too.</li>
<li>Begin by adding your files to the library using the "Add Media" menu button. You can drag and drop your files to this window too.</li>
<li>Create a show by going to "Calendar" in the menu bar, and then clicking the "+ Show" icon. This can be either a one-time or repeating show. Only admins and program managers can add shows.</li>
<li>Add media to the show by going to your show in the Schedule calendar, left-clicking on it and selecting "Add / Remove Content".</li>
<li>Select your media from the left pane and drag them to your show in the right pane.</li>

View File

@ -420,7 +420,7 @@
<column name="name" phpName="DbName" type="VARCHAR" size="255" required="true" />
<!-- TODO, remove hardlimit on this column length? -->
<column name="description" phpName="DbDescription" type="VARCHAR" size="255" required="true" />
<column name="url" phpName="DbUrl" type="VARCHAR" size="255" required="true" />
<column name="url" phpName="DbUrl" type="VARCHAR" size="512" required="true" />
<column name="length" phpName="DbLength" type="VARCHAR" sqlType="interval" required="true" defaultValue="00:00:00"/>
<column name="creator_id" phpName="DbCreatorId" type="INTEGER" required="true" />
<column name="mtime" phpName="DbMtime" type="TIMESTAMP" size="6" required="true" />

View File

@ -95,7 +95,7 @@ CREATE TABLE cc_webstream (
id integer DEFAULT nextval('cc_webstream_id_seq'::regclass) NOT NULL,
name character varying(255) NOT NULL,
description character varying(255) NOT NULL,
url character varying(255) NOT NULL,
url character varying(512) NOT NULL,
length interval DEFAULT '00:00:00'::interval NOT NULL,
creator_id integer NOT NULL,
mtime timestamp(6) without time zone NOT NULL,