Skip to content

Commit

Permalink
CC-1665: Scheduled stream rebroadcasting and recording
Browse files Browse the repository at this point in the history
-improve working with "webstreams"
  • Loading branch information
mkonecny committed Jul 31, 2012
1 parent 142aa21 commit 7e433b6
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .zfproject.xml
Expand Up @@ -36,7 +36,7 @@
<actionMethod actionName="delete"/>
<actionMethod actionName="contents"/>
<actionMethod actionName="editFileMd"/>
<actionMethod actionName="getFileMetaData"/>
<actionMethod actionName="getFileMetadata"/>
</controllerFile>
<controllerFile controllerName="Plupload">
<actionMethod actionName="index"/>
Expand Down Expand Up @@ -304,7 +304,7 @@
<viewScriptFile forActionName="update"/>
</viewControllerScriptsDirectory>
<viewControllerScriptsDirectory forControllerName="Library">
<viewScriptFile forActionName="getFileMetaData"/>
<viewScriptFile forActionName="getFileMetadata"/>
</viewControllerScriptsDirectory>
<viewControllerScriptsDirectory forControllerName="Nowplaying">
<viewScriptFile forActionName="dayView"/>
Expand Down
59 changes: 48 additions & 11 deletions airtime_mvc/application/controllers/LibraryController.php
Expand Up @@ -17,7 +17,7 @@ public function init()
->addActionContext('delete', 'json')
->addActionContext('delete-group', 'json')
->addActionContext('context-menu', 'json')
->addActionContext('get-file-meta-data', 'html')
->addActionContext('get-file-metadata', 'html')
->addActionContext('upload-file-soundcloud', 'json')
->addActionContext('get-upload-to-soundcloud-status', 'json')
->addActionContext('set-num-entries', 'json')
Expand Down Expand Up @@ -91,6 +91,24 @@ public function contextMenuAction()
if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
$menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/library/delete");
}
} else if ($type == "stream") {

$obj = new Application_Model_Webstream($id);
if (isset($this->obj_sess->id) && $screen == "playlist") {
if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
if ($this->obj_sess->type === "playlist") {
$menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
} else {
$menu["pl_add"] = array("name"=> "Add to Smart Playlist", "icon" => "add-playlist", "icon" => "copy");
}
}
}
if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
$menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/library/delete");
$menu["edit"] = array("name"=> "Edit", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}");
}


}

//SOUNDCLOUD MENU OPTIONS
Expand Down Expand Up @@ -132,6 +150,7 @@ public function deleteAction()
$files = array();
$playlists = array();
$blocks = array();
$streams = array();

$message = null;

Expand All @@ -143,30 +162,41 @@ public function deleteAction()
$playlists[] = intval($media["id"]);
} elseif ($media["type"] === "block") {
$blocks[] = intval($media["id"]);
} elseif ($media["type"] === "stream") {
$streams[] = intval($media["id"]);
}
}

try {
if ($media["type"] === "playlist") {
Application_Model_Playlist::deletePlaylists($playlists, $user->getId());
} elseif ($media["type"] === "block") {
Application_Model_Block::deleteBlocks($blocks, $user->getId());
}
Application_Model_Playlist::deletePlaylists($playlists, $user->getId());
} catch (PlaylistNoPermissionException $e) {
$this->view->message = "You don't have permission to delete selected items.";
return;
}


try {
Application_Model_Block::deleteBlocks($blocks, $user->getId());
} catch (Exception $e) {
//TODO: warn user that not all blocks could be deleted.
}

try {
Application_Model_Webstream::deleteStreams($streams, $user->getId());
} catch (Exception $e) {
//TODO: warn user that not all streams could be deleted.
Logging::log($e);
}

foreach ($files as $id) {

$file = Application_Model_StoredFile::Recall($id);

if (isset($file)) {
try {
$res = $file->delete(true);
}
//could throw a scheduled in future exception.
catch (Exception $e) {
} catch (Exception $e) {
//could throw a scheduled in future exception.
$message = "Could not delete some scheduled files.";
}
}
Expand Down Expand Up @@ -241,7 +271,7 @@ public function editFileMdAction()
$this->view->form = $form;
}

public function getFileMetaDataAction()
public function getFileMetadataAction()
{
$id = $this->_getParam('id');
$type = $this->_getParam('type');
Expand Down Expand Up @@ -270,7 +300,7 @@ public function getFileMetaDataAction()

$this->view->md = $md;

} elseif ($type == "playlist") {
} else if ($type == "playlist") {

$file = new Application_Model_Playlist($id);
$this->view->type = $type;
Expand All @@ -281,6 +311,13 @@ public function getFileMetaDataAction()

$this->view->md = $md;
$this->view->contents = $file->getContents();
} else if ($type == "stream") {
$file = new Application_Model_Webstream($id);

$md = $file->getMetadata();

$this->view->md = $md;
$this->view->type = $type;
}
} catch (Exception $e) {
Logging::log($e->getMessage());
Expand Down
11 changes: 2 additions & 9 deletions airtime_mvc/application/controllers/WebstreamController.php
Expand Up @@ -29,19 +29,12 @@ public function newAction()
*/
}

public function saveAction(){
public function saveAction()
{
$request = $this->getRequest();

Application_Model_Webstream::save($request);


$this->view->x = "hi";


//http://localhost/Library/contents-feed
// 1) Create Propel object and save these parameters
// 2) Make these appear in the library
// 3) Make Web streams + playlists draggable.
// 4)
}
}
2 changes: 1 addition & 1 deletion airtime_mvc/application/models/Playlist.php
Expand Up @@ -178,7 +178,7 @@ public function getContents($filterFiles=false)
JOIN cc_files AS f ON pc.file_id=f.id WHERE pc.playlist_id = {$this->id} AND type = 0)
UNION ALL
(SELECT pc.id as id, pc.type, pc.position, pc.cliplength as length, pc.cuein, pc.cueout, pc.fadein, pc.fadeout,
ws.id as item_id, (ws.name || ': ' || ws.url) as title, ws.login as creator, 't'::boolean as exists, ws.url as path FROM cc_playlistcontents AS pc
ws.id as item_id, (ws.name || ': ' || ws.url) as title, ws.creator_id as creator, 't'::boolean as exists, ws.url as path FROM cc_playlistcontents AS pc
JOIN cc_webstream AS ws on pc.stream_id=ws.id WHERE pc.playlist_id = {$this->id} AND type = 1)
UNION ALL
(SELECT pc.id as id, pc.type, pc.position, pc.cliplength as length, pc.cuein, pc.cueout, pc.fadein, pc.fadeout,
Expand Down
2 changes: 1 addition & 1 deletion airtime_mvc/application/models/StoredFile.php
Expand Up @@ -621,7 +621,7 @@ public static function searchLibraryFiles($datatables)
$plSelect[] = "login AS ".$key;
$blSelect[] = "login AS ".$key;
$fileSelect[] = $key;
$streamSelect[] = "login AS ".$key;
$streamSelect[] = "creator_id AS ".$key;
}
//same columns in each table.
else if (in_array($key, array("length", "utime", "mtime"))) {
Expand Down
51 changes: 50 additions & 1 deletion airtime_mvc/application/models/Webstream.php
Expand Up @@ -2,6 +2,13 @@

class Application_Model_Webstream{

private $id;

public function __construct($id)
{
$this->id = $id;
}

public static function getName()
{
return "Default";
Expand All @@ -27,6 +34,48 @@ public static function getDescription()
return "desc";
}

public function getMetadata()
{
$webstream = CcWebstreamQuery::create()->findPK($this->id);
$subjs = CcSubjsQuery::create()->findPK($webstream->getDbCreatorId());

$username = $subjs->getDbLogin();
return array(
"name" => $webstream->getDbName(),
"length" => $webstream->getDbLength(),
"description" => $webstream->getDbDescription(),
"login"=> $username,
"url" => $webstream->getDbUrl(),
);

}

public static function deleteStreams($p_ids, $p_userId)
{
$leftOver = self::streamsNotOwnedByUser($p_ids, $p_userId);
if (count($leftOver) == 0) {
CcWebstreamQuery::create()->findPKs($p_ids)->delete();
} else {
throw new Exception("Invalid user permissions");
}
}

// This function returns that are not owen by $p_user_id among $p_ids
private static function streamsNotOwnedByUser($p_ids, $p_userId)
{
$ownedByUser = CcWebstreamQuery::create()->filterByDbCreatorId($p_userId)->find()->getData();
$ownedStreams = array();
foreach ($ownedByUser as $pl) {
if (in_array($pl->getDbId(), $p_ids)) {
$ownedStreams[] = $pl->getDbId();
}
}

$leftOvers = array_diff($p_ids, $ownedStreams);
return $leftOvers;

}

public static function save($request)
{
Logging::log($request->getParams());
Expand All @@ -47,7 +96,7 @@ public static function save($request)
$webstream->setDbUrl($request->getParam("url"));

$webstream->setDbLength($dblength);
$webstream->setDbLogin($userInfo->id);
$webstream->setDbCreatorId($userInfo->id);
$webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC')));
$webstream->setDbMtime(new DateTime("now", new DateTimeZone('UTC')));
$webstream->save();
Expand Down
Expand Up @@ -43,7 +43,7 @@ public function initialize()
$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('LOGIN', 'DbLogin', 'VARCHAR', true, 255, null);
$this->addColumn('CREATOR_ID', 'DbCreatorId', 'VARCHAR', true, 255, null);
$this->addColumn('MTIME', 'DbMtime', 'TIMESTAMP', true, 6, null);
$this->addColumn('UTIME', 'DbUtime', 'TIMESTAMP', true, 6, null);
// validators
Expand Down
38 changes: 19 additions & 19 deletions airtime_mvc/application/models/airtime/om/BaseCcWebstream.php
Expand Up @@ -56,10 +56,10 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent
protected $length;

/**
* The value for the login field.
* The value for the creator_id field.
* @var string
*/
protected $login;
protected $creator_id;

/**
* The value for the mtime field.
Expand Down Expand Up @@ -164,13 +164,13 @@ public function getDbLength()
}

/**
* Get the [login] column value.
* Get the [creator_id] column value.
*
* @return string
*/
public function getDbLogin()
public function getDbCreatorId()
{
return $this->login;
return $this->creator_id;
}

/**
Expand Down Expand Up @@ -340,24 +340,24 @@ public function setDbLength($v)
} // setDbLength()

/**
* Set the value of [login] column.
* Set the value of [creator_id] column.
*
* @param string $v new value
* @return CcWebstream The current object (for fluent API support)
*/
public function setDbLogin($v)
public function setDbCreatorId($v)
{
if ($v !== null) {
$v = (string) $v;
}

if ($this->login !== $v) {
$this->login = $v;
$this->modifiedColumns[] = CcWebstreamPeer::LOGIN;
if ($this->creator_id !== $v) {
$this->creator_id = $v;
$this->modifiedColumns[] = CcWebstreamPeer::CREATOR_ID;
}

return $this;
} // setDbLogin()
} // setDbCreatorId()

/**
* Sets the value of [mtime] column to a normalized version of the date/time value specified.
Expand Down Expand Up @@ -498,7 +498,7 @@ public function hydrate($row, $startcol = 0, $rehydrate = false)
$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->login = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
$this->creator_id = ($row[$startcol + 5] !== null) ? (string) $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();
Expand Down Expand Up @@ -842,7 +842,7 @@ public function getByPosition($pos)
return $this->getDbLength();
break;
case 5:
return $this->getDbLogin();
return $this->getDbCreatorId();
break;
case 6:
return $this->getDbMtime();
Expand Down Expand Up @@ -878,7 +878,7 @@ public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColum
$keys[2] => $this->getDbDescription(),
$keys[3] => $this->getDbUrl(),
$keys[4] => $this->getDbLength(),
$keys[5] => $this->getDbLogin(),
$keys[5] => $this->getDbCreatorId(),
$keys[6] => $this->getDbMtime(),
$keys[7] => $this->getDbUtime(),
);
Expand Down Expand Up @@ -928,7 +928,7 @@ public function setByPosition($pos, $value)
$this->setDbLength($value);
break;
case 5:
$this->setDbLogin($value);
$this->setDbCreatorId($value);
break;
case 6:
$this->setDbMtime($value);
Expand Down Expand Up @@ -965,7 +965,7 @@ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
if (array_key_exists($keys[2], $arr)) $this->setDbDescription($arr[$keys[2]]);
if (array_key_exists($keys[3], $arr)) $this->setDbUrl($arr[$keys[3]]);
if (array_key_exists($keys[4], $arr)) $this->setDbLength($arr[$keys[4]]);
if (array_key_exists($keys[5], $arr)) $this->setDbLogin($arr[$keys[5]]);
if (array_key_exists($keys[5], $arr)) $this->setDbCreatorId($arr[$keys[5]]);
if (array_key_exists($keys[6], $arr)) $this->setDbMtime($arr[$keys[6]]);
if (array_key_exists($keys[7], $arr)) $this->setDbUtime($arr[$keys[7]]);
}
Expand All @@ -984,7 +984,7 @@ public function buildCriteria()
if ($this->isColumnModified(CcWebstreamPeer::DESCRIPTION)) $criteria->add(CcWebstreamPeer::DESCRIPTION, $this->description);
if ($this->isColumnModified(CcWebstreamPeer::URL)) $criteria->add(CcWebstreamPeer::URL, $this->url);
if ($this->isColumnModified(CcWebstreamPeer::LENGTH)) $criteria->add(CcWebstreamPeer::LENGTH, $this->length);
if ($this->isColumnModified(CcWebstreamPeer::LOGIN)) $criteria->add(CcWebstreamPeer::LOGIN, $this->login);
if ($this->isColumnModified(CcWebstreamPeer::CREATOR_ID)) $criteria->add(CcWebstreamPeer::CREATOR_ID, $this->creator_id);
if ($this->isColumnModified(CcWebstreamPeer::MTIME)) $criteria->add(CcWebstreamPeer::MTIME, $this->mtime);
if ($this->isColumnModified(CcWebstreamPeer::UTIME)) $criteria->add(CcWebstreamPeer::UTIME, $this->utime);

Expand Down Expand Up @@ -1052,7 +1052,7 @@ public function copyInto($copyObj, $deepCopy = false)
$copyObj->setDbDescription($this->description);
$copyObj->setDbUrl($this->url);
$copyObj->setDbLength($this->length);
$copyObj->setDbLogin($this->login);
$copyObj->setDbCreatorId($this->creator_id);
$copyObj->setDbMtime($this->mtime);
$copyObj->setDbUtime($this->utime);

Expand Down Expand Up @@ -1281,7 +1281,7 @@ public function clear()
$this->description = null;
$this->url = null;
$this->length = null;
$this->login = null;
$this->creator_id = null;
$this->mtime = null;
$this->utime = null;
$this->alreadyInSave = false;
Expand Down

0 comments on commit 7e433b6

Please sign in to comment.