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

This commit is contained in:
denise 2012-08-07 11:08:34 -04:00
commit d05661afff
26 changed files with 244 additions and 160 deletions

View file

@ -258,29 +258,39 @@ class ApiController extends Zend_Controller_Action
$request = $this->getRequest();
$type = $request->getParam('type');
/* This is some *extremely* lazy programming that needs to bi fixed. For some reason
* we are using two entirely different codepaths for very similar functionality (type = endofday
* vs type = interval). Needs to be fixed for 2.2 - MK */
if ($type == "endofday") {
$limit = $request->getParam('limit');
if($limit == "" || !is_numeric($limit)) {
if ($limit == "" || !is_numeric($limit)) {
$limit = "5";
}
// make GetNextShows use end of day
// make getNextShows use end of day
$utcTimeEnd = Application_Common_DateHelper::GetDayEndTimestampInUtc();
$result = array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"),
"nextShow"=>Application_Model_Show::getNextShows($utcTimeNow, $limit, $utcTimeEnd));
"currentShow"=>Application_Model_Show::getCurrentShow($utcTimeNow),
"nextShow"=>Application_Model_Show::getNextShows($utcTimeNow, $limit, $utcTimeEnd)
);
Application_Model_Show::convertToLocalTimeZone($result["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
Application_Model_Show::convertToLocalTimeZone($result["currentShow"],
array("starts", "ends", "start_timestamp", "end_timestamp"));
Application_Model_Show::convertToLocalTimeZone($result["nextShow"],
array("starts", "ends", "start_timestamp", "end_timestamp"));
} else {
$result = Application_Model_Schedule::GetPlayOrderRange();
//Convert from UTC to localtime for Web Browser.
Application_Model_Show::convertToLocalTimeZone($result["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
Application_Model_Show::convertToLocalTimeZone($result["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
Application_Model_Show::ConvertToLocalTimeZone($result["currentShow"],
array("starts", "ends", "start_timestamp", "end_timestamp"));
Application_Model_Show::ConvertToLocalTimeZone($result["nextShow"],
array("starts", "ends", "start_timestamp", "end_timestamp"));
}
$result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION; //used by caller to determine if the airtime they are running or widgets in use is out of date.
//used by caller to determine if the airtime they are running or widgets in use is out of date.
$result['AIRTIME_API_VERSION'] = AIRTIME_API_VERSION;
header("Content-type: text/javascript");
// If a callback is not given, then just provide the raw JSON.

View file

@ -7,6 +7,7 @@ class WebstreamController extends Zend_Controller_Action
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('new', 'json')
->addActionContext('save', 'json')
->addActionContext('edit', 'json')
->initContext();
//TODO
//$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME);
@ -29,14 +30,52 @@ class WebstreamController extends Zend_Controller_Action
*/
}
public function editAction()
{
$request = $this->getRequest();
$id = $request->getParam("id");
if (is_null($id)) {
throw new Exception("Missing parameter 'id'");
}
$this->view->ws = new Application_Model_Webstream($id);
$this->view->html = $this->view->render('webstream/webstream.phtml');
}
public function saveAction()
{
$request = $this->getRequest();
$user = Application_Model_User::getCurrentUser();
$hasPermission = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST));
$id = $request->getParam("id");
if ($id == -1) {
$webstream = new CcWebstream();
} else {
$webstream = CcWebstreamQuery::create()->findPK($id);
}
if ($id != -1) {
//we are updating a playlist. Ensure that if the user is a host/dj, that he has the correct permission.
$user = Application_Model_User::getCurrentUser();
if ($webstream->getDbCreatorId() != $user->getId()) {
header("Status: 401 Not Authorized");
return;
}
}
if (!$hasPermission) {
header("Status: 401 Not Authorized");
return;
}
$analysis = Application_Model_Webstream::analyzeFormData($request);
if (Application_Model_Webstream::isValid($analysis)) {
Application_Model_Webstream::save($request);
Application_Model_Webstream::save($request, $webstream);
$this->view->statusMessage = "<div class='success'>Webstream saved.</div>";
} else {
$this->view->statusMessage = "<div class='errors'>Invalid form values.</div>";

View file

@ -107,8 +107,7 @@ class Application_Model_Schedule
$sql = "SELECT * FROM (($filesSql) UNION ($streamSql)) AS unioned ORDER BY starts";
$rows = $con->query($sql)->fetchAll();
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$numberOfRows = count($rows);
$results['previous'] = null;

View file

@ -1763,8 +1763,7 @@ class Application_Model_Show
." AND modified_instance != TRUE";
// Convert back to local timezone
$rows = $con->query($sql)->fetchAll();
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC);
return $rows;
}
@ -1894,7 +1893,7 @@ class Application_Model_Show
}
//TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
$sql = "SELECT *, si.starts as start_timestamp, si.ends as end_timestamp FROM "
$sql = "SELECT si.starts as start_timestamp, si.ends as end_timestamp, s.name, s.id, si.id as instance_id, si.record, s.url, starts, ends"
." $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] s"
." WHERE si.show_id = s.id"
." AND si.starts >= TIMESTAMP '$timeStart'"
@ -1907,8 +1906,7 @@ class Application_Model_Show
$sql = $sql . " LIMIT $limit";
}
$rows = $con->query($sql)->fetchAll();
$rows = $con->query($sql)->fetchAll(PDO::FETCH_ASSOC);
return $rows;
}

View file

@ -606,7 +606,7 @@ class Application_Model_StoredFile
$plSelect[] = "PL.id AS ".$key;
$blSelect[] = "BL.id AS ".$key;
$fileSelect[] = $key;
$streamSelect[] = $key;
$streamSelect[] = "ws.id AS ".$key;
} elseif ($key === "track_title") {
$plSelect[] = "name AS ".$key;
$blSelect[] = "name AS ".$key;
@ -621,7 +621,7 @@ class Application_Model_StoredFile
$plSelect[] = "login AS ".$key;
$blSelect[] = "login AS ".$key;
$fileSelect[] = $key;
$streamSelect[] = "creator_id AS ".$key;
$streamSelect[] = "login AS ".$key;
}
//same columns in each table.
else if (in_array($key, array("length", "utime", "mtime"))) {
@ -659,7 +659,7 @@ class Application_Model_StoredFile
$plTable = "({$plSelect} FROM cc_playlist AS PL LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id))";
$blTable = "({$blSelect} FROM cc_block AS BL LEFT JOIN cc_subjs AS sub ON (sub.id = BL.creator_id))";
$fileTable = "({$fileSelect} FROM cc_files AS FILES WHERE file_exists = 'TRUE')";
$streamTable = "({$streamSelect} FROM cc_webstream AS WEBSTREAM)";
$streamTable = "({$streamSelect} FROM cc_webstream AS ws LEFT JOIN cc_subjs AS sub ON (sub.id = ws.creator_id))";
$unionTable = "({$plTable} UNION {$blTable} UNION {$fileTable} UNION {$streamTable}) AS RESULTS";
//choose which table we need to select data from.
@ -676,6 +676,9 @@ class Application_Model_StoredFile
case 3:
$fromTable = $blTable." AS Block"; //need an alias for the table if it's standalone.
break;
case 4:
$fromTable = $streamTable." AS StreamTable"; //need an alias for the table if it's standalone.
break;
default:
$fromTable = $unionTable;
}
@ -696,7 +699,7 @@ class Application_Model_StoredFile
$formatter = new BitrateFormatter($row['bit_rate']);
$row['bit_rate'] = $formatter->format();
}
//convert mtime and utime to localtime
$row['mtime'] = new DateTime($row['mtime'], new DateTimeZone('UTC'));
$row['mtime']->setTimeZone(new DateTimeZone(date_default_timezone_get()));

View file

@ -4,34 +4,59 @@ class Application_Model_Webstream{
private $id;
public function __construct($id)
public function __construct($id=-1)
{
$this->id = $id;
if ($id == -1) {
$this->webstream = new CcWebstream();
//We're not saving this object in the database, so -1 ID is OK.
$this->webstream->setDbId(-1);
$this->webstream->setDbName("Untitled Webstream");
$this->webstream->setDbDescription("");
$this->webstream->setDbUrl("http://");
$this->webstream->setDbLength("00:00:00");
$this->webstream->setDbName("Untitled Webstream");
} else {
$this->id = $id;
$this->webstream = CcWebstreamQuery::create()->findPK($this->id);
}
}
public static function getName()
public function getName()
{
return "Default";
return $this->webstream->getDbName();
}
public static function getId()
public function getId()
{
return "id";
return $this->webstream->getDbId();
}
public static function getLastModified($p_type)
public function getLastModified($p_type)
{
return "modified";
}
public static function getDefaultLength()
public function getDefaultLength()
{
return "length";
$dateString = $this->webstream->getDbLength();
$arr = explode(":", $dateString);
if (count($arr) == 3) {
list($hours, $min, $sec) = $arr;
$di = new DateInterval("PT{$hours}H{$min}M{$sec}S");
return $di->format("%Hh %Im");
}
return "";
}
public static function getDescription()
public function getDescription()
{
return "desc";
return $this->webstream->getDbDescription();
}
public function getUrl()
{
return $this->webstream->getDbUrl();
}
public function getMetadata()
@ -41,11 +66,11 @@ class Application_Model_Webstream{
$username = $subjs->getDbLogin();
return array(
"name" => $webstream->getDbName(),
"length" => $webstream->getDbLength(),
"description" => $webstream->getDbDescription(),
"name" => $this->webstream->getDbName(),
"length" => $this->webstream->getDbLength(),
"description" => $this->webstream->getDbDescription(),
"login"=> $username,
"url" => $webstream->getDbUrl(),
"url" => $this->webstream->getDbUrl(),
);
}
@ -75,25 +100,12 @@ class Application_Model_Webstream{
return $leftOvers;
}
/*
Array
(
[controller] => Webstream
[action] => save
[module] => default
[format] => json
[description] => desc
[url] => http://
[length] => 00h 20m
[name] => Default
)
*/
public static function analyzeFormData($request)
{
$valid = array("length" => array(true, ''),
"url" => array(true, ''));
"url" => array(true, ''),
"name" => array(true, ''));
$length = trim($request->getParam("length"));
$result = preg_match("/^([0-9]{1,2})h ([0-5][0-9])m$/", $length, $matches);
@ -120,6 +132,19 @@ Array
$valid['name'][1] = 'Webstream name cannot be empty';
}
$id = trim($request->getParam("id"));
if (!is_null($id)) {
// user has performed a create stream action instead of edit
// stream action. Check if user has the rights to edit this stream.
Logging::log("CREATE");
} else {
Logging::log("EDIT");
}
return $valid;
}
@ -134,12 +159,13 @@ Array
return true;
}
public static function save($request)
public static function save($request, $webstream)
{
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$length = trim($request->getParam("length"));
$result = preg_match("/^([0-9]{1,2})h ([0-5][0-9])m$/", $length, $matches);
if ($result == 1 && count($matches) == 3) {
$hours = $matches[1];
$minutes = $matches[2];
@ -150,9 +176,8 @@ Array
//in the controller
throw new Exception("Invalid date format: $length");
}
#TODO: These should be validated by a Zend Form.
$webstream = new CcWebstream();
$webstream->setDbName($request->getParam("name"));
$webstream->setDbDescription($request->getParam("description"));
$webstream->setDbUrl($request->getParam("url"));

View file

@ -43,7 +43,7 @@ class CcWebstreamTableMap extends TableMap {
$this->addColumn('DESCRIPTION', 'DbDescription', 'VARCHAR', true, 255, null);
$this->addColumn('URL', 'DbUrl', 'VARCHAR', true, 255, null);
$this->addColumn('LENGTH', 'DbLength', 'VARCHAR', true, null, '00:00:00');
$this->addColumn('CREATOR_ID', 'DbCreatorId', 'VARCHAR', true, 255, null);
$this->addColumn('CREATOR_ID', 'DbCreatorId', 'INTEGER', true, null, null);
$this->addColumn('MTIME', 'DbMtime', 'TIMESTAMP', true, 6, null);
$this->addColumn('UTIME', 'DbUtime', 'TIMESTAMP', true, 6, null);
// validators

View file

@ -57,7 +57,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
/**
* The value for the creator_id field.
* @var string
* @var int
*/
protected $creator_id;
@ -166,7 +166,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
/**
* Get the [creator_id] column value.
*
* @return string
* @return int
*/
public function getDbCreatorId()
{
@ -342,13 +342,13 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
/**
* Set the value of [creator_id] column.
*
* @param string $v new value
* @param int $v new value
* @return CcWebstream The current object (for fluent API support)
*/
public function setDbCreatorId($v)
{
if ($v !== null) {
$v = (string) $v;
$v = (int) $v;
}
if ($this->creator_id !== $v) {
@ -498,7 +498,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
$this->description = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
$this->url = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
$this->length = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
$this->creator_id = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
$this->creator_id = ($row[$startcol + 5] !== null) ? (int) $row[$startcol + 5] : null;
$this->mtime = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
$this->utime = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
$this->resetModified();

View file

@ -40,7 +40,7 @@
* @method CcWebstream findOneByDbDescription(string $description) Return the first CcWebstream filtered by the description column
* @method CcWebstream findOneByDbUrl(string $url) Return the first CcWebstream filtered by the url column
* @method CcWebstream findOneByDbLength(string $length) Return the first CcWebstream filtered by the length column
* @method CcWebstream findOneByDbCreatorId(string $creator_id) Return the first CcWebstream filtered by the creator_id column
* @method CcWebstream findOneByDbCreatorId(int $creator_id) Return the first CcWebstream filtered by the creator_id column
* @method CcWebstream findOneByDbMtime(string $mtime) Return the first CcWebstream filtered by the mtime column
* @method CcWebstream findOneByDbUtime(string $utime) Return the first CcWebstream filtered by the utime column
*
@ -49,7 +49,7 @@
* @method array findByDbDescription(string $description) Return CcWebstream objects filtered by the description column
* @method array findByDbUrl(string $url) Return CcWebstream objects filtered by the url column
* @method array findByDbLength(string $length) Return CcWebstream objects filtered by the length column
* @method array findByDbCreatorId(string $creator_id) Return CcWebstream objects filtered by the creator_id column
* @method array findByDbCreatorId(int $creator_id) Return CcWebstream objects filtered by the creator_id column
* @method array findByDbMtime(string $mtime) Return CcWebstream objects filtered by the mtime column
* @method array findByDbUtime(string $utime) Return CcWebstream objects filtered by the utime column
*
@ -269,20 +269,29 @@ abstract class BaseCcWebstreamQuery extends ModelCriteria
/**
* Filter the query on the creator_id column
*
* @param string $dbCreatorId The value to use as filter.
* Accepts wildcards (* and % trigger a LIKE)
* @param int|array $dbCreatorId The value to use as filter.
* Accepts an associative array('min' => $minValue, 'max' => $maxValue)
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return CcWebstreamQuery The current query, for fluid interface
*/
public function filterByDbCreatorId($dbCreatorId = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($dbCreatorId)) {
if (is_array($dbCreatorId)) {
$useMinMax = false;
if (isset($dbCreatorId['min'])) {
$this->addUsingAlias(CcWebstreamPeer::CREATOR_ID, $dbCreatorId['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($dbCreatorId['max'])) {
$this->addUsingAlias(CcWebstreamPeer::CREATOR_ID, $dbCreatorId['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $dbCreatorId)) {
$dbCreatorId = str_replace('*', '%', $dbCreatorId);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(CcWebstreamPeer::CREATOR_ID, $dbCreatorId, $comparison);

View file

@ -26,12 +26,12 @@
<div id="url-error" class="errors" style="display:none;"></div>
<dt id="streamurl-label"><label for="streamurl">Stream URL:</label></dt>
<dd id="streamurl-element">
<input type="text" value="http://" size="40"/>
<input type="text" value="<?php echo $this->ws->getUrl(); ?>" size="40"/>
</dd>
<div id="length-error" class="errors" style="display:none;"></div>
<dt id="streamlength-label"><label for="streamlength">Default Length:</label></dt>
<dd id="streamlength-element">
<input type="text" value="00h 20m"/>
<input type="text" value="<?php echo $this->ws->getDefaultLength() ?>"/>
</dd>
<dd id="submit-element" class="buttons">
<input class="ui-button ui-state-default" type="submit" value="Save" id="webstream_save" name="submit">

View file

@ -419,7 +419,7 @@
<column name="description" phpName="DbDescription" type="VARCHAR" size="255" required="true" />
<column name="url" phpName="DbUrl" type="VARCHAR" size="255" required="true" />
<column name="length" phpName="DbLength" type="VARCHAR" sqlType="interval" required="true" defaultValue="00:00:00"/>
<column name="creator_id" phpName="DbCreatorId" type="VARCHAR" size="255" 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="utime" phpName="DbUtime" type="TIMESTAMP" size="6" required="true" />
</table>

View file

@ -1,9 +1,9 @@
INSERT INTO cc_subjs ("login", "type", "pass") VALUES ('admin', 'A', md5('admin'));
-- added in 2.2
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_name', 'Airtime!', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_name', '', 'string');
INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_name', '', 'string');
-- INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s1_name', 'Airtime!', 'string');
-- INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s2_name', '', 'string');
-- INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s3_name', '', 'string');
-- end of added in 2.2
-- added in 2.1

View file

@ -635,7 +635,7 @@ CREATE TABLE "cc_webstream"
"description" VARCHAR(255) NOT NULL,
"url" VARCHAR(255) NOT NULL,
"length" interval default '00:00:00' NOT NULL,
"creator_id" VARCHAR(255) NOT NULL,
"creator_id" INTEGER NOT NULL,
"mtime" TIMESTAMP(6) NOT NULL,
"utime" TIMESTAMP(6) NOT NULL,
PRIMARY KEY ("id")

View file

@ -543,6 +543,7 @@ var AIRTIME = (function(AIRTIME) {
.append('<option value="1">Files</option>')
.append('<option value="2">Playlists</option>')
.append('<option value="3">Smart Playlists</option>')
.append('<option value="4">Web Streams</option>')
.end()
.change(function(ev){
oTable.fnDraw();
@ -613,12 +614,18 @@ var AIRTIME = (function(AIRTIME) {
callback = function() {
document.location.href = oItems.edit.url;
};
}
else {
} else if (data.ftype === "playlist" || data.ftype === "block") {
callback = function() {
//TODO
AIRTIME.playlist.fnEdit(data.id, data.ftype);
var url = '/Playlist/edit';
AIRTIME.playlist.fnEdit(data.id, data.ftype, url);
};
} else if (data.ftype === "stream") {
callback = function() {
var url = '/Webstream/edit';
AIRTIME.playlist.fnEdit(data.id, data.ftype, url);
}
} else {
throw new Exception("Unknown type: " + data.ftype);
}
oItems.edit.callback = callback;
}

View file

@ -532,6 +532,7 @@ var AIRTIME = (function(AIRTIME){
//stream url
//default_length
//playlist name
var id = $pl.find("#ws_id").attr("value");
var description = $pl.find("#description").val();
var streamurl = $pl.find("#streamurl-element input").val();
var length = $pl.find("#streamlength-element input").val();
@ -542,7 +543,7 @@ var AIRTIME = (function(AIRTIME){
var url = 'Webstream/save';
$.post(url,
{format: "json", description: description, url:streamurl, length: length, name: name},
{format: "json", id:id, description: description, url:streamurl, length: length, name: name},
function(json){
if (json.analysis){
for (var s in json.analysis){
@ -730,8 +731,7 @@ var AIRTIME = (function(AIRTIME){
});
};
mod.fnEdit = function(id, type) {
var url = '/Playlist/edit';
mod.fnEdit = function(id, type, url) {
stopAudioPreview();
@ -741,6 +741,7 @@ var AIRTIME = (function(AIRTIME){
openPlaylist(json);
});
};
mod.fnDelete = function(plid) {
var url, id, lastMod;