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

View File

@ -322,10 +322,21 @@ class Application_Model_StoredFile
{ {
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection(); $con = Propel::getConnection();
$sql = "SELECT playlist_id " $sql = "SELECT playlist_id "
." FROM ".$CC_CONFIG['playistTable'] ." FROM cc_playlist"
." WHERE file_id='{$this->id}'"; ." WHERE file_id = :file_id";
$ids = $con->query($sql)->fetchAll();
$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(); $playlists = array();
if (is_array($ids) && count($ids) > 0) { if (is_array($ids) && count($ids) > 0) {
foreach ($ids as $id) { foreach ($ids as $id) {
@ -951,7 +962,7 @@ class Application_Model_StoredFile
$uid = $user->getId(); $uid = $user->getId();
} }
$id_file = "$audio_stor.identifier"; $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("Could not write file to identify user: '$uid'");
Logging::info("Id file path: '$id_file'"); Logging::info("Id file path: '$id_file'");
Logging::info("Defaulting to admin (no identification file was Logging::info("Defaulting to admin (no identification file was
@ -1003,7 +1014,7 @@ class Application_Model_StoredFile
global $CC_CONFIG; global $CC_CONFIG;
$con = Propel::getConnection(); $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); return $con->query($sql)->fetchColumn(0);
} }
@ -1012,53 +1023,59 @@ class Application_Model_StoredFile
* *
* Enter description here ... * Enter description here ...
* @param $dir_id - if this is not provided, it returns all files with full path constructed. * @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(); $con = Propel::getConnection();
$file_exists = $all ? "" : "and f.file_exists = 'TRUE'"; $sql = "SELECT filepath as fp"
." FROM CC_FILES as f"
if ($propelObj) { ." WHERE f.directory = :dir_id";
$sql = "SELECT m.directory || f.filepath as fp"
." FROM CC_MUSIC_DIRS m" if (!$all) {
." LEFT JOIN CC_FILES f" $sql .= " AND f.file_exists = 'TRUE'";
." 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";
} }
$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(); $results = array();
foreach ($rows as $row) { foreach ($rows as $row) {
if ($propelObj) { $results[] = $row["fp"];
$results[] = Application_Model_StoredFile::RecallByFilepath($row["fp"]);
} else {
$results[] = $row["fp"];
}
} }
return $results; return $results;
} }
//TODO: MERGE THIS FUNCTION AND "listAllFiles" -MK //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(); $con = Propel::getConnection();
$sql = "SELECT id, filepath as fp" $sql = "SELECT id, filepath as fp"
." FROM CC_FILES" ." FROM CC_FILES"
." WHERE directory = $dir_id" ." WHERE directory = :dir_id"
." AND file_exists = 'TRUE'" ." AND file_exists = 'TRUE'"
." AND replay_gain is NULL"; ." AND replay_gain is NULL"
if (!is_null($limit) && is_int($limit)) { ." LIMIT :lim";
$sql .= " LIMIT $limit";
}
$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; return $rows;
} }

View File

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

View File

@ -168,6 +168,9 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
if ($result == 0) { if ($result == 0) {
$valid['url'][0] = false; $valid['url'][0] = false;
$valid['url'][1] = 'URL should be of form "http://domain"'; $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 { } else {
try { try {

View File

@ -4,7 +4,7 @@
<p>Here's how you can get started using Airtime to automate your broadcasts: </p> <p>Here's how you can get started using Airtime to automate your broadcasts: </p>
<ol> <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>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>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> <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" /> <column name="name" phpName="DbName" type="VARCHAR" size="255" required="true" />
<!-- TODO, remove hardlimit on this column length? --> <!-- TODO, remove hardlimit on this column length? -->
<column name="description" phpName="DbDescription" type="VARCHAR" size="255" required="true" /> <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="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="creator_id" phpName="DbCreatorId" type="INTEGER" required="true" />
<column name="mtime" phpName="DbMtime" type="TIMESTAMP" size="6" 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, id integer DEFAULT nextval('cc_webstream_id_seq'::regclass) NOT NULL,
name character varying(255) NOT NULL, name character varying(255) NOT NULL,
description 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, length interval DEFAULT '00:00:00'::interval NOT NULL,
creator_id integer NOT NULL, creator_id integer NOT NULL,
mtime timestamp(6) without time zone NOT NULL, mtime timestamp(6) without time zone NOT NULL,