diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php
index 81a1503f5..fe783d953 100644
--- a/airtime_mvc/application/controllers/LibraryController.php
+++ b/airtime_mvc/application/controllers/LibraryController.php
@@ -50,10 +50,14 @@ class LibraryController extends Zend_Controller_Action
$file = Application_Model_StoredFile::Recall($id);
if (isset($this->obj_sess->id) && $screen == "playlist") {
- // if the user is not admin or pm, check the creator and see if this person owns the playlist
- $playlist = new Application_Model_Playlist($this->obj_sess->id);
- if ($isAdminOrPM || $playlist->getCreatorId() == $user->getId()) {
- $menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
+ // if the user is not admin or pm, check the creator and see if this person owns the playlist or Block
+ if ($this->obj_sess->type == 'playlist') {
+ $obj = new Application_Model_Playlist($this->obj_sess->id);
+ } else {
+ $obj = new Application_Model_Block($this->obj_sess->id);
+ }
+ if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
+ $menu["pl_add"] = array("name"=> "Add to ".ucfirst($this->obj_sess->type), "icon" => "add-playlist", "icon" => "copy");
}
}
if ($isAdminOrPM) {
@@ -63,14 +67,19 @@ class LibraryController extends Zend_Controller_Action
$url = $file->getRelativeFileUrl($baseUrl).'/download/true';
$menu["download"] = array("name" => "Download", "icon" => "download", "url" => $url);
- } elseif ($type === "playlist") {
- $playlist = new Application_Model_Playlist($id);
+ } elseif ($type === "playlist" || $type === "block") {
+ if ($type === 'playlist') {
+ $obj = new Application_Model_Playlist($id);
+ } else {
+ $obj = new Application_Model_Block($id);
+ }
+
if ($this->obj_sess->id !== $id && $screen == "playlist") {
- if ($isAdminOrPM || $playlist->getCreatorId() == $user->getId()) {
+ if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
$menu["edit"] = array("name"=> "Edit", "icon" => "edit");
}
}
- if ($isAdminOrPM || $playlist->getCreatorId() == $user->getId()) {
+ if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
$menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/library/delete");
}
}
@@ -113,6 +122,7 @@ class LibraryController extends Zend_Controller_Action
$files = array();
$playlists = array();
+ $blocks = array();
$message = null;
@@ -122,13 +132,19 @@ class LibraryController extends Zend_Controller_Action
$files[] = intval($media["id"]);
} elseif ($media["type"] === "playlist") {
$playlists[] = intval($media["id"]);
+ } elseif ($media["type"] === "block") {
+ $blocks[] = intval($media["id"]);
}
}
try {
- Application_Model_Playlist::deletePlaylists($playlists, $user->getId());
+ if ($media["type"] === "playlist") {
+ Application_Model_Playlist::deletePlaylists($playlists, $user->getId());
+ } elseif ($media["type"] === "block") {
+ Application_Model_Block::deleteBlocks($blocks, $user->getId());
+ }
} catch (PlaylistNoPermissionException $e) {
- $this->view->message = "You don't have permission to delete selected playlists/files.";
+ $this->view->message = "You don't have permission to delete selected items.";
return;
}
@@ -155,6 +171,7 @@ class LibraryController extends Zend_Controller_Action
public function contentsFeedAction()
{
$params = $this->getRequest()->getParams();
+
$r = Application_Model_StoredFile::searchLibraryFiles($params);
//TODO move this to the datatables row callback.
diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php
index 26f58b451..abac5d840 100644
--- a/airtime_mvc/application/controllers/PlaylistController.php
+++ b/airtime_mvc/application/controllers/PlaylistController.php
@@ -203,7 +203,7 @@ class PlaylistController extends Zend_Controller_Action
$this->view->type = $this->obj_sess->type;
}
} catch (PlaylistNotFoundException $e) {
- $this->playlistNotFound();
+ $this->playlistNotFound($this->obj_sess->type);
} catch (Exception $e) {
$this->playlistUnknownError($e);
}
@@ -230,31 +230,20 @@ class PlaylistController extends Zend_Controller_Action
$this->createFullResponse($obj);
}
- /*public function newBlockAction()
- {
- $bl_sess = $this->bl_sess;
- $userInfo = Zend_Auth::getInstance()->getStorage()->read();
-
- $bl = new Application_Model_Block();
- $bl->setName("Untitled Smart Block");
- $bl->setBLMetaData('dc:creator', $userInfo->id);
-
- $this->changePlaylist($bl->getId(), 'block');
- $this->createFullResponse($bl);
- }*/
-
public function editAction()
{
$id = $this->_getParam('id', null);
- Logging::log("editing playlist {$id}");
+ $type = $this->_getParam('type');
+ $objInfo = $this->getObjInfo($type);
+ Logging::log("editing {$type} {$id}");
if (!is_null($id)) {
- $this->changePlaylist($id, 'playlist');
+ $this->changePlaylist($id, $type);
}
try {
- $pl = new Application_Model_Playlist($id);
- $this->createFullResponse($pl);
+ $obj = new $objInfo['className']($id);
+ $this->createFullResponse($obj);
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound();
} catch (Exception $e) {
diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php
index 1d8addf61..ae05316bc 100644
--- a/airtime_mvc/application/models/Block.php
+++ b/airtime_mvc/application/models/Block.php
@@ -94,7 +94,7 @@ class Application_Model_Block
}
} else {
$this->block = new CcBlock();
- $this->block->setDbUTime("now", new DateTimeZone("UTC"));
+ $this->block->setDbUTime(new DateTime("now", new DateTimeZone("UTC")));
$this->block->save();
}
diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php
index cb84db467..8de5ec463 100644
--- a/airtime_mvc/application/models/Playlist.php
+++ b/airtime_mvc/application/models/Playlist.php
@@ -56,7 +56,7 @@ class Application_Model_Playlist
}
} else {
$this->pl = new CcPlaylist();
- $this->pl->setDbUTime("now", new DateTimeZone("UTC"));
+ $this->pl->setDbUTime(new DateTime("now", new DateTimeZone("UTC")));
$this->pl->save();
}
@@ -135,6 +135,9 @@ class Application_Model_Playlist
public function getLastModified($format = null)
{
+ //Logging::log($this->pl->getDbMtime($format));
+ //Logging::log($this->pl);
+ Logging::log("5555");
return $this->pl->getDbMtime($format);
}
diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php
index accb02f9d..e57647f9c 100644
--- a/airtime_mvc/application/models/StoredFile.php
+++ b/airtime_mvc/application/models/StoredFile.php
@@ -648,49 +648,60 @@ Logging::log("getting media! - 2");
);
$plSelect = array();
+ $blSelect = array();
$fileSelect = array();
foreach ($displayColumns as $key) {
if ($key === "id") {
$plSelect[] = "PL.id AS ".$key;
+ $blSelect[] = "BL.id AS ".$key;
$fileSelect[] = $key;
} elseif ($key === "track_title") {
$plSelect[] = "name AS ".$key;
+ $blSelect[] = "name AS ".$key;
$fileSelect[] = $key;
} elseif ($key === "ftype") {
$plSelect[] = "'playlist'::varchar AS ".$key;
+ $blSelect[] = "'block'::varchar AS ".$key;
$fileSelect[] = $key;
} elseif ($key === "artist_name") {
$plSelect[] = "login AS ".$key;
+ $blSelect[] = "login AS ".$key;
$fileSelect[] = $key;
}
//same columns in each table.
else if (in_array($key, array("length", "utime", "mtime"))) {
$plSelect[] = $key;
+ $blSelect[] = $key;
$fileSelect[] = $key;
} elseif ($key === "year") {
$plSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS ".$key;
+ $blSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS ".$key;
$fileSelect[] = "year AS ".$key;
}
//need to cast certain data as ints for the union to search on.
else if (in_array($key, array("track_number", "bit_rate", "sample_rate"))) {
$plSelect[] = "NULL::int AS ".$key;
+ $blSelect[] = "NULL::int AS ".$key;
$fileSelect[] = $key;
} else {
$plSelect[] = "NULL::text AS ".$key;
+ $blSelect[] = "NULL::text AS ".$key;
$fileSelect[] = $key;
}
}
$plSelect = "SELECT ". join(",", $plSelect);
+ $blSelect = "SELECT ". join(",", $blSelect);
$fileSelect = "SELECT ". join(",", $fileSelect);
$type = intval($datatables["type"]);
$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')";
- $unionTable = "({$plTable} UNION {$fileTable} ) AS RESULTS";
+ $unionTable = "({$plTable} UNION {$blTable} UNION {$fileTable} ) AS RESULTS";
//choose which table we need to select data from.
switch ($type) {
@@ -703,6 +714,9 @@ Logging::log("getting media! - 2");
case 2:
$fromTable = $plTable." AS Playlist"; //need an alias for the table if it's standalone.
break;
+ case 3:
+ $fromTable = $blTable." AS Block"; //need an alias for the table if it's standalone.
+ break;
default:
$fromTable = $unionTable;
}
@@ -723,16 +737,15 @@ Logging::log("getting media! - 2");
$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()));
$row['mtime'] = $row['mtime']->format('Y-m-d H:i:s');
-
$row['utime'] = new DateTime($row['utime'], new DateTimeZone('UTC'));
$row['utime']->setTimeZone(new DateTimeZone(date_default_timezone_get()));
$row['utime'] = $row['utime']->format('Y-m-d H:i:s');
-
+
// add checkbox row
$row['checkbox'] = "";
diff --git a/airtime_mvc/application/models/airtime/CcBlock.php b/airtime_mvc/application/models/airtime/CcBlock.php
index 447433cd1..fb519bbd3 100644
--- a/airtime_mvc/application/models/airtime/CcBlock.php
+++ b/airtime_mvc/application/models/airtime/CcBlock.php
@@ -14,5 +14,87 @@
* @package propel.generator.airtime
*/
class CcBlock extends BaseCcBlock {
+/**
+ * Get the [optionally formatted] temporal [utime] column value.
+ *
+ *
+ * @param string $format The date/time format string (either date()-style or strftime()-style).
+ * If format is NULL, then the raw DateTime object will be returned.
+ * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
+ * @throws PropelException - if unable to parse/validate the date/time value.
+ */
+ public function getDbUtime($format = 'Y-m-d H:i:s')
+ {
+ if ($this->utime === null) {
+ return null;
+ }
+ try {
+ $dt = new DateTime($this->utime, new DateTimeZone("UTC"));
+ } catch (Exception $x) {
+ throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->utime, true), $x);
+ }
+
+ if ($format === null) {
+ // Because propel.useDateTimeClass is TRUE, we return a DateTime object.
+ return $dt;
+ } elseif (strpos($format, '%') !== false) {
+ return strftime($format, $dt->format('U'));
+ } else {
+ return $dt->format($format);
+ }
+ }
+
+ /**
+ * Get the [optionally formatted] temporal [mtime] column value.
+ *
+ *
+ * @param string $format The date/time format string (either date()-style or strftime()-style).
+ * If format is NULL, then the raw DateTime object will be returned.
+ * @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
+ * @throws PropelException - if unable to parse/validate the date/time value.
+ */
+ public function getDbMtime($format = 'Y-m-d H:i:s')
+ {
+ if ($this->mtime === null) {
+ return null;
+ }
+
+ try {
+ $dt = new DateTime($this->mtime, new DateTimeZone("UTC"));
+ } catch (Exception $x) {
+ throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->mtime, true), $x);
+ }
+
+ if ($format === null) {
+ // Because propel.useDateTimeClass is TRUE, we return a DateTime object.
+ return $dt;
+ } elseif (strpos($format, '%') !== false) {
+ return strftime($format, $dt->format('U'));
+ } else {
+ return $dt->format($format);
+ }
+ }
+
+ /**
+ * Computes the value of the aggregate column length
+ * Overridden to provide a default of 00:00:00 if the playlist is empty.
+ *
+ * @param PropelPDO $con A connection object
+ *
+ * @return mixed The scalar result from the aggregate query
+ */
+ public function computeDbLength(PropelPDO $con)
+ {
+ $stmt = $con->prepare('SELECT SUM(cliplength) FROM "cc_playlistcontents" WHERE cc_playlistcontents.PLAYLIST_ID = :p1');
+ $stmt->bindValue(':p1', $this->getDbId());
+ $stmt->execute();
+ $length = $stmt->fetchColumn();
+
+ if (is_null($length)) {
+ $length = "00:00:00";
+ }
+
+ return $length;
+ }
} // CcBlock
diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js
index 32db95a02..b2c890795 100644
--- a/airtime_mvc/public/js/airtime/library/library.js
+++ b/airtime_mvc/public/js/airtime/library/library.js
@@ -542,6 +542,7 @@ var AIRTIME = (function(AIRTIME) {
.append('')
.append('')
.append('')
+ .append('')
.end()
.change(function(ev){
oTable.fnDraw();
@@ -613,7 +614,11 @@ var AIRTIME = (function(AIRTIME) {
}
else {
callback = function() {
- AIRTIME.playlist.fnEdit(data.id);
+ if (data.ftype === "playlist") {
+ AIRTIME.playlist.fnEdit(data.id, 'playlist');
+ } else {
+ AIRTIME.playlist.fnEdit(data.id, 'block');
+ }
};
}
oItems.edit.callback = callback;
diff --git a/airtime_mvc/public/js/airtime/library/spl.js b/airtime_mvc/public/js/airtime/library/spl.js
index a6a69dfad..f270a305b 100644
--- a/airtime_mvc/public/js/airtime/library/spl.js
+++ b/airtime_mvc/public/js/airtime/library/spl.js
@@ -641,13 +641,13 @@ var AIRTIME = (function(AIRTIME){
});
};
- mod.fnEdit = function(id) {
- var url = '/Playlist/edit';;
+ mod.fnEdit = function(id, type) {
+ var url = '/Playlist/edit';
stopAudioPreview();
$.post(url,
- {format: "json", id: id},
+ {format: "json", id: id, type: type},
function(json){
openPlaylist(json);
});
diff --git a/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js
index 69a2e7b72..af82f0893 100644
--- a/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js
+++ b/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js
@@ -5,18 +5,6 @@ $(document).ready(function() {
function setSmartPlaylistEvents() {
var form = $('#smart-playlist-form');
- /*
- sets.each(function(index, set){
- $(set).live('click', function(){
- if ($(this).next().hasClass('closed')) {
- $(this).next().removeClass('closed sp-closed');
- } else {
- $(this).next().addClass('closed sp-closed');
- }
- });
- });
- */
-
form.find('.criteria_add').live('click', function(){
var div = $('dd[id="sp_criteria-element"]').children('div:visible:last').next();