diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index 1418b0f0f..0c838693d 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -79,6 +79,10 @@ class LibraryController extends Zend_Controller_Action $file = Application_Model_StoredFile::Recall($id); + if (isset($this->pl_sess->id) && $screen == "playlist") { + $menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "copy"); + } + $menu["edit"] = array("name"=> "Edit Metadata", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}"); if ($user->isAdmin()) { diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php index 65a9e38d8..b40de9d35 100644 --- a/airtime_mvc/application/controllers/PlaylistController.php +++ b/airtime_mvc/application/controllers/PlaylistController.php @@ -52,10 +52,12 @@ class PlaylistController extends Zend_Controller_Action private function createUpdateResponse($pl) { + $formatter = new LengthFormatter($pl->getLength()); + $this->view->length = $formatter->format(); + $this->view->pl = $pl; $this->view->html = $this->view->render('playlist/update.phtml'); $this->view->name = $pl->getName(); - $this->view->length = $pl->getLength(); $this->view->description = $pl->getDescription(); $this->view->modified = $pl->getLastModified("U"); @@ -65,6 +67,9 @@ class PlaylistController extends Zend_Controller_Action private function createFullResponse($pl = null) { if (isset($pl)) { + $formatter = new LengthFormatter($pl->getLength()); + $this->view->length = $formatter->format(); + $this->view->pl = $pl; $this->view->id = $pl->getId(); $this->view->html = $this->view->render('playlist/index.phtml'); @@ -114,6 +119,9 @@ class PlaylistController extends Zend_Controller_Action if (isset($this->pl_sess->id)) { $pl = new Application_Model_Playlist($this->pl_sess->id); $this->view->pl = $pl; + + $formatter = new LengthFormatter($pl->getLength()); + $this->view->length = $formatter->format(); } } catch (PlaylistNotFoundException $e) { diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php index ee264df57..146c07593 100644 --- a/airtime_mvc/application/models/Playlist.php +++ b/airtime_mvc/application/models/Playlist.php @@ -1,5 +1,7 @@ format(); + + $formatter = new LengthFormatter($offset_cliplength); + $files[$i]['offset'] = $formatter->format(); $i++; } diff --git a/airtime_mvc/application/models/ShowInstance.php b/airtime_mvc/application/models/ShowInstance.php index 984304c7b..37ad92b1a 100644 --- a/airtime_mvc/application/models/ShowInstance.php +++ b/airtime_mvc/application/models/ShowInstance.php @@ -1,5 +1,7 @@ _showInstance->getDbTimeFilled(); - if(is_null($time)) { + if (is_null($time)) { $time = "00:00:00"; } + else { + $formatter = new LengthFormatter($time); + $time = $formatter->format(); + } + return $time; } @@ -631,15 +638,11 @@ class Application_Model_ShowInstance { public function getShowLength() { - global $CC_DBC; + $start = $this->getShowInstanceStart(null); + $end = $this->getShowInstanceEnd(null); - $start_timestamp = $this->getShowInstanceStart(); - $end_timestamp = $this->getShowInstanceEnd(); - - $sql = "SELECT TIMESTAMP '{$end_timestamp}' - TIMESTAMP '{$start_timestamp}' "; - $length = $CC_DBC->GetOne($sql); - - return $length; + $interval = $start->diff($end); + return $interval->format("%h:%I:%S"); } public function searchPlaylistsForShow($datatables) @@ -657,47 +660,22 @@ class Application_Model_ShowInstance { WHERE s.instance_id = '{$this->_instanceId}' ORDER BY starts"; - return $CC_DBC->GetAll($sql); - } + Logging::log($sql); - public function getShowContent() - { - global $CC_DBC; + $results = $CC_DBC->GetAll($sql); - $res = $this->getShowListContent(); + foreach ($results as &$row) { - if(count($res) <= 0) { - return $res; + $dt = new DateTime($row["starts"], new DateTimeZone("UTC")); + $dt->setTimezone(new DateTimeZone(date_default_timezone_get())); + $row["starts"] = $dt->format("Y-m-d H:i:s"); + + $formatter = new LengthFormatter($row["clip_length"]); + $row["clip_length"] = $formatter->format(); } - $items = array(); - $currGroupId = -1; - $pl_counter = -1; - $f_counter = -1; - foreach ($res as $row) { - if($currGroupId != $row["group_id"]){ - $currGroupId = $row["group_id"]; - $pl_counter = $pl_counter + 1; - $f_counter = -1; - $items[$pl_counter]["pl_name"] = $row["name"]; - $items[$pl_counter]["pl_creator"] = $row["creator"]; - $items[$pl_counter]["pl_description"] = $row["description"]; - $items[$pl_counter]["pl_group"] = $row["group_id"]; - - $sql = "SELECT SUM(clip_length) FROM cc_schedule WHERE group_id = '{$currGroupId}'"; - $length = $CC_DBC->GetOne($sql); - - $items[$pl_counter]["pl_length"] = $length; - } - $f_counter = $f_counter + 1; - - $items[$pl_counter]["pl_content"][$f_counter]["f_name"] = $row["track_title"]; - $items[$pl_counter]["pl_content"][$f_counter]["f_artist"] = $row["artist_name"]; - $items[$pl_counter]["pl_content"][$f_counter]["f_length"] = $row["length"]; - } - - return $items; + return $results; } public static function GetShowsInstancesIdsInRange($p_timeNow, $p_start, $p_end) diff --git a/airtime_mvc/application/models/SmilPlaylist.php b/airtime_mvc/application/models/SmilPlaylist.php deleted file mode 100644 index 52fc22d9e..000000000 --- a/airtime_mvc/application/models/SmilPlaylist.php +++ /dev/null @@ -1,312 +0,0 @@ -lock($gb, $subjid); - if (PEAR::isError($r)) { - return $r; - } - $r = $pl->setMetadata($lspl, 'string', 'playlist'); - if (PEAR::isError($r)) { - return $r; - } - $r = $pl->unlock($gb); - if (PEAR::isError($r)) { - return $r; - } - return $pl; - } - - - /** - * Import SMIL file to storage. - * - * @param GreenBox $gb - * @param string $data - * local path to SMIL file - * @param hasharray $gunids - * hash relation from filenames to gunids - * @param array $parr - * array of subjid, aPath, plid, rPath - * @return string - * XML of playlist in Airtime playlist format - */ - public static function convert2lspl(&$gb, $data, &$gunids, $parr) - { - extract($parr); - $tree = SmilPlaylist::parse($data); - if (PEAR::isError($tree)) { - return $tree; - } - if ($tree->name != 'smil') { - return PEAR::raiseError("SmilPlaylist::parse: smil tag expected"); - } - if (isset($tree->children[1])) { - return PEAR::raiseError(sprintf( - "SmilPlaylist::parse: unexpected tag %s in tag smil", - $tree->children[1]->name - )); - } - $res = SmilPlaylistBodyElement::convert2lspl( - $gb, $tree->children[0], &$gunids, $parr); - return $res; - } - -} // SmilPlaylist - - -/** - * @package Airtime - * @subpackage StorageServer - * @copyright 2010 Sourcefabric O.P.S. - * @license http://www.gnu.org/licenses/gpl.txt - */ -class SmilPlaylistBodyElement { - - public static function convert2lspl(&$gb, &$tree, &$gunids, $parr, $ind='') - { - extract($parr); - $ind2 = $ind.INDCH; - if ($tree->name != 'body') { - return PEAR::raiseError("SmilPlaylist::parse: body tag expected"); - } - if (isset($tree->children[1])) { - return PEAR::raiseError(sprintf( - "SmilPlaylist::parse: unexpected tag %s in tag body", - $tree->children[1]->name - )); - } - $res = SmilPlaylistParElement::convert2lspl( - $gb, $tree->children[0], &$gunids, $parr, $ind2); - if (PEAR::isError($res)) { - return $res; - } - $title = basename($rPath); - $playlength = '0'; - $res = "$ind\n". - "$ind\n". - "$ind2\n". - "$res". - "$ind\n"; - return $res; - } - -} // class SmilPlaylistBodyElement - - -/** - * @package Airtime - * @subpackage StorageServer - * @copyright 2010 Sourcefabric O.P.S. - * @license http://www.gnu.org/licenses/gpl.txt - */ -class SmilPlaylistParElement { - - public static function convert2lspl(&$gb, &$tree, &$gunids, $parr, $ind='') - { - extract($parr); - if ($tree->name != 'par') { - return PEAR::raiseError("SmilPlaylist::parse: par tag expected"); - } - $res = ''; - foreach ($tree->children as $i => $ch) { - $ch =& $tree->children[$i]; - $r = SmilPlaylistAudioElement::convert2lspl($gb, $ch, &$gunids, $parr, $ind.INDCH); - if (PEAR::isError($r)) { - return $r; - } - $res .= $r; - } - return $res; - } -} - - -/** - * @package Airtime - * @subpackage StorageServer - * @copyright 2010 Sourcefabric O.P.S. - * @license http://www.gnu.org/licenses/gpl.txt - */ -class SmilPlaylistAudioElement { - public static function convert2lspl(&$gb, &$tree, &$gunids, $parr, $ind='') - { - extract($parr); - $uri = $tree->attrs['src']->val; - $gunid = ( isset($gunids[basename($uri)]) ? $gunids[basename($uri)] : NULL); - $ind2 = $ind.INDCH; - if ($tree->name != 'audio') { - return PEAR::raiseError("SmilPlaylist::parse: audio tag expected"); - } - if (isset($tree->children[2])) { - return PEAR::raiseError(sprintf( - "SmilPlaylist::parse: unexpected tag %s in tag audio", - $tree->children[2]->name - )); - } - $res = ''; $fadeIn = 0; $fadeOut = 0; - foreach ($tree->children as $i => $ch) { - $ch =& $tree->children[$i]; - $r = SmilPlaylistAnimateElement::convert2lspl($gb, $ch, &$gunids, $parr, $ind2); - if (PEAR::isError($r)) { - return $r; - } - switch ($r['type']) { - case "fadeIn": $fadeIn = $r['val']; break; - case "fadeOut": $fadeOut = $r['val']; break; - } - } - if ($fadeIn > 0 || $fadeOut > 0) { - $fiGunid = Application_Model_StoredFile::CreateGunid(); - $fadeIn = Application_Model_Playlist::secondsToPlaylistTime($fadeIn); - $fadeOut = Application_Model_Playlist::secondsToPlaylistTime($fadeOut); - $fInfo = "$ind2\n"; - } else { - $fInfo = ''; - } - $plElGunid = Application_Model_StoredFile::CreateGunid(); - $acGunid = $gunid; - $type = 'audioClip'; - if (preg_match("|\.([a-zA-Z0-9]+)$|", $uri, $va)) { - switch (strtolower($ext = $va[1])) { - case "lspl": - case "xml": - case "smil": - case "m3u": - $type = 'playlist'; - $acId = $gb->bsImportPlaylistRaw($gunid, - $aPath, $uri, $ext, $gunids, $subjid); - if (PEAR::isError($acId)) { - return $r; - } - //break; - default: - $ac = Application_Model_StoredFile::RecallByGunid($gunid); - if (is_null($ac) || PEAR::isError($ac)) { - return $ac; - } - $r = $ac->md->getMetadataElement('dcterms:extent'); - if (PEAR::isError($r)) { - return $r; - } - $playlength = $r[0]['value']; - } - } - - $title = basename($tree->attrs['src']->val); - $offset = Application_Model_Playlist::secondsToPlaylistTime($tree->attrs['begin']->val); - $clipStart = Application_Model_Playlist::secondsToPlaylistTime($tree->attrs['clipStart']->val); - $clipEnd = Application_Model_Playlist::secondsToPlaylistTime($tree->attrs['clipEnd']->val); - $clipLength = Application_Model_Playlist::secondsToPlaylistTime($tree->attrs['clipLength']->val); - $res = "$ind\n". - "$ind2<$type id=\"$acGunid\" playlength=\"$playlength\" title=\"$title\"/>\n". - $fInfo. - "$ind\n"; - return $res; - } -} // class SmilPlaylistAudioElement - - -/** - * @package Airtime - * @subpackage StorageServer - * @copyright 2010 Sourcefabric O.P.S. - * @license http://www.gnu.org/licenses/gpl.txt - */ -class SmilPlaylistAnimateElement { - - public static function convert2lspl(&$gb, &$tree, &$gunids, $parr, $ind='') - { - extract($parr); - if ($tree->name != 'animate') { - return PEAR::raiseError("SmilPlaylist::parse: animate tag expected"); - } - if ($tree->attrs['attributeName']->val == 'soundLevel' && - $tree->attrs['from']->val == '0%' && - $tree->attrs['to']->val == '100%' && - $tree->attrs['calcMode']->val == 'linear' && - $tree->attrs['fill']->val == 'freeze' && - $tree->attrs['begin']->val == '0s' && - preg_match("|^([0-9.]+)s$|", $tree->attrs['end']->val, $va) - ) { - return array('type'=>'fadeIn', 'val'=>intval($va[1])); - } - if ($tree->attrs['attributeName']->val == 'soundLevel' && - $tree->attrs['from']->val == '100%' && - $tree->attrs['to']->val == '0%' && - $tree->attrs['calcMode']->val == 'linear' && - $tree->attrs['fill']->val == 'freeze' && - preg_match("|^([0-9.]+)s$|", $tree->attrs['begin']->val, $vaBegin) && - preg_match("|^([0-9.]+)s$|", $tree->attrs['end']->val, $vaEnd) - ) { - return array('type'=>'fadeOut', 'val'=>($vaEnd[1] - $vaBegin[1])); - } - return PEAR::raiseError( - "SmilPlaylistAnimateElement::convert2lspl: animate parameters too general" - ); - } -} // class SmilPlaylistAnimateElement - diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 6a0539637..a4484e666 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -1,5 +1,7 @@ format("H"); - $min = $dt->format("i"); - $sec = $dt->format("s"); - - $time = "PT{$hours}H{$min}M{$sec}S"; - - $p_interval = new DateInterval($time); - - $hours = $p_interval->format("%h"); - $mins = $p_interval->format("%i"); - - if ( $hours == 0) { - $runtime = $p_interval->format("%i:%S"); - } - else { - $runtime = $p_interval->format("%h:%I:%S"); - } - - return $runtime; - } - public static function searchFilesForPlaylistBuilder($datatables) { $displayColumns = array("id", "track_title", "artist_name", "album_title", "genre", "length", @@ -664,8 +638,8 @@ class Application_Model_StoredFile { $row['id'] = intval($row['id']); - //$length = new DateTime($row['length']); - //$row['length'] = self::formatDuration($length); + $formatter = new LengthFormatter($row['length']); + $row['length'] = $formatter->format(); // add checkbox row $row['checkbox'] = ""; diff --git a/airtime_mvc/application/models/formatters/LengthFormatter.php b/airtime_mvc/application/models/formatters/LengthFormatter.php new file mode 100644 index 000000000..4551e4680 --- /dev/null +++ b/airtime_mvc/application/models/formatters/LengthFormatter.php @@ -0,0 +1,56 @@ + 24 hours) + */ + public function __construct($length) + { + $this->_length = $length; + } + + public function format() { + + $pieces = explode(":", $this->_length); + + $seconds = round($pieces[2], 1); + $seconds = number_format($seconds, 1); + list($seconds, $milliStr) = explode(".", $seconds); + + if (intval($pieces[0]) !== 0) { + $hours = ltrim($pieces[0], "0"); + } + + $minutes = $pieces[1]; + //length is less than 1 hour + if (!isset($hours)) { + + if (intval($minutes) !== 0) { + $minutes = ltrim($minutes, "0"); + } + //length is less than 1 minute + else { + unset($minutes); + } + } + + if (isset($hours) && isset($minutes) && isset($seconds)) { + $time = sprintf("%d:%02d:%02d.%s", $hours, $minutes, $seconds, $milliStr); + } + else if (isset($minutes) && isset($seconds)) { + $time = sprintf("%d:%02d.%s", $minutes, $seconds, $milliStr); + } + else { + $time = sprintf("%d.%s", $seconds, $milliStr); + } + + return $time; + } + +} \ No newline at end of file diff --git a/airtime_mvc/application/models/index.php b/airtime_mvc/application/models/index.php deleted file mode 100644 index ce253b51f..000000000 --- a/airtime_mvc/application/models/index.php +++ /dev/null @@ -1,3 +0,0 @@ -pl->getName(); ?> -

pl->getLength(); ?>

+

length; ?>

diff --git a/airtime_mvc/application/views/scripts/schedule/show-content-dialog.phtml b/airtime_mvc/application/views/scripts/schedule/show-content-dialog.phtml index a48a41399..103796adc 100644 --- a/airtime_mvc/application/views/scripts/schedule/show-content-dialog.phtml +++ b/airtime_mvc/application/views/scripts/schedule/show-content-dialog.phtml @@ -12,13 +12,11 @@ showContent as $row): ?> " class=""> - setTimezone(new DateTimeZone(date_default_timezone_get())); - echo $dt->format("Y-m-d H:i:s") ?> + - + diff --git a/airtime_mvc/public/css/contextmenu.css b/airtime_mvc/public/css/contextmenu.css deleted file mode 100644 index 07af8909b..000000000 --- a/airtime_mvc/public/css/contextmenu.css +++ /dev/null @@ -1,39 +0,0 @@ -div.jjmenu { - - position:absolute; - background:#d2d2d2; - border-bottom:2px solid #5b5b5b; - border-right:1px solid #5b5b5b; - padding:0px; - z-index: 1011; - font-size:11px; -} - -div.jj_menu_item { - color:black; - border:1px solid #5b5b5b; - border-bottom:none; - background:#d2d2d2; - background: -moz-linear-gradient(center top , #d2d2d2 0pt, #bcbcbc 100%); - background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #d2d2d2), color-stop(100%, #bcbcbc)); - cursor:pointer; -} - -div.jj_menu_item span { - display:block; - padding:4px 10px; -} - -div.jj_menu_item_more span { - background:url(images/more.gif) right no-repeat; -} -div.jj_menu_item_more span { - padding-right:20px; -} - -div.jj_menu_item_hover { - background:#6e6e6e; - background: -moz-linear-gradient(center top , #868686 0pt, #6e6e6e 100%); - background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #868686), color-stop(100%, #6e6e6e)); - color:#FFF; -} diff --git a/airtime_mvc/public/css/media_library.css b/airtime_mvc/public/css/media_library.css index 925baa36a..20b60b4bc 100644 --- a/airtime_mvc/public/css/media_library.css +++ b/airtime_mvc/public/css/media_library.css @@ -75,3 +75,7 @@ .datatable_checkbox .DataTables_sort_wrapper { text-align: center; } + +.library_year { + text-align: center; +} diff --git a/airtime_mvc/public/css/styles.css b/airtime_mvc/public/css/styles.css index 2ac7289e3..afc5bc1c5 100644 --- a/airtime_mvc/public/css/styles.css +++ b/airtime_mvc/public/css/styles.css @@ -658,6 +658,11 @@ button.ColVis_Button.ColVis_ShowAll { margin: 0.5em 0.2em -0.5em 0.2em; } +.library_length { + text-align: right; + padding-right: 1em !important; +} + /*----END Data Table----*/ fieldset { diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index 275c915ec..d97b5574c 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -225,8 +225,8 @@ $(document).ready(function() { /* Creator */ {"sTitle": "Creator", "mDataProp": "artist_name", "sClass": "library_creator"}, /* Album */ {"sTitle": "Album", "mDataProp": "album_title", "sClass": "library_album"}, /* Genre */ {"sTitle": "Genre", "mDataProp": "genre", "sClass": "library_genre"}, - /* Year */ {"sTitle": "Year", "mDataProp": "year", "sClass": "library_year"}, - /* Length */ {"sTitle": "Length", "mDataProp": "length", "sClass": "library_length"}, + /* Year */ {"sTitle": "Year", "mDataProp": "year", "sClass": "library_year", "sWidth": "60px"}, + /* Length */ {"sTitle": "Length", "mDataProp": "length", "sClass": "library_length", "sWidth": "80px"}, /* Upload Time */ {"sTitle": "Uploaded", "mDataProp": "utime", "sClass": "library_upload_time"}, /* Last Modified */ {"sTitle": "Last Modified", "mDataProp": "mtime", "bVisible": false, "sClass": "library_modified_time"}, /* Track Number */ {"sTitle": "Track", "mDataProp": "track_number", "bSearchable": false, "bVisible": false, "sClass": "library_track"}, @@ -470,6 +470,16 @@ $(document).ready(function() { function processMenuItems(oItems) { + //define an add to playlist callback. + if (oItems.pl_add !== undefined) { + + callback = function() { + AIRTIME.playlist.fnAddItems([data.id], undefined, 'after'); + }; + + oItems.pl_add.callback = callback; + } + //define an edit callback. if (oItems.edit !== undefined) {