Merge branch 'CC-3174' into devel

This commit is contained in:
Naomi Aro 2012-02-24 15:07:38 +01:00
commit 0446fcfb25
14 changed files with 129 additions and 438 deletions

View File

@ -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()) {

View File

@ -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) {

View File

@ -1,5 +1,7 @@
<?php
require_once 'formatters/LengthFormatter.php';
/**
*
* @package Airtime
@ -158,9 +160,15 @@ class Application_Model_Playlist {
$clipSec = Application_Model_Playlist::playlistTimeToSeconds($files[$i]['cliplength']);
//$files[$i]['cliplength'] = Application_Model_Playlist::secondsToPlaylistTime($clipSec);
$offset += $clipSec;
$files[$i]['offset'] = Application_Model_Playlist::secondsToPlaylistTime($offset);
$offset_cliplength = Application_Model_Playlist::secondsToPlaylistTime($offset);
//format the length for UI.
$formatter = new LengthFormatter($files[$i]['cliplength']);
$files[$i]['cliplength'] = $formatter->format();
$formatter = new LengthFormatter($offset_cliplength);
$files[$i]['offset'] = $formatter->format();
$i++;
}

View File

@ -1,5 +1,7 @@
<?php
require_once 'formatters/LengthFormatter.php';
class Application_Model_ShowInstance {
private $_instanceId;
@ -599,9 +601,14 @@ class Application_Model_ShowInstance {
{
$time = $this->_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)

View File

@ -1,312 +0,0 @@
<?
define('INDCH', ' ');
require_once("XmlParser.php");
/**
* SmilPlaylist class
*
* @package Airtime
* @subpackage StorageServer
* @copyright 2010 Sourcefabric O.P.S.
* @license http://www.gnu.org/licenses/gpl.txt
*/
class SmilPlaylist {
/**
* Parse SMIL file or string
*
* @param string $data
* local path to SMIL file or SMIL string
* @param string $loc
* location: 'file'|'string'
* @return array
* reference, parse result tree (or PEAR::error)
*/
private static function &parse($data='', $loc='file')
{
return XmlParser::parse($data, $loc);
}
/**
* Import SMIL file to storage
*
* @param GreenBox $gb
* reference to GreenBox object
* @param string $aPath
* absolute path part of imported file (e.g. /home/user/airtime)
* @param string $rPath
* relative path/filename part of imported file
* (e.g. playlists/playlist_1.smil)
* @param array $gunids
* hash relation from filenames to gunids
* @param string $plid
* playlist gunid
* @param int $subjid
* local subject (user) id (id of user doing the import)
* @return Playlist
*/
public static function &import(&$gb, $aPath, $rPath, &$gunids, $plid, $subjid=NULL)
{
$parr = compact('subjid', 'aPath', 'plid', 'rPath');
$path = realpath("$aPath/$rPath");
if (FALSE === $path) {
return PEAR::raiseError(
"SmilPlaylist::import: file doesn't exist ($aPath/$rPath)"
);
}
$lspl = SmilPlaylist::convert2lspl($gb, $path, $gunids, $parr);
if (PEAR::isError($lspl)) {
return $lspl;
}
require_once("Playlist.php");
$pl =& Application_Model_Playlist::create($gb, $plid, "imported_SMIL");
if (PEAR::isError($pl)) {
return $pl;
}
$r = $pl->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<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n".
"$ind<playlist id=\"$plid\" playlength=\"$playlength\" title=\"$title\">\n".
"$ind2<metadata/>\n".
"$res".
"$ind</playlist>\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<fadeInfo id=\"$fiGunid\" fadeIn=\"$fadeIn\" fadeOut=\"$fadeOut\"/>\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<playlistElement id=\"$plElGunid\" relativeOffset=\"$offset\" clipStart=\"$clipStart\" clipEnd=\"$clipEnd\" clipLength=\"$clipLength\">\n".
"$ind2<$type id=\"$acGunid\" playlength=\"$playlength\" title=\"$title\"/>\n".
$fInfo.
"$ind</playlistElement>\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

View File

@ -1,5 +1,7 @@
<?php
require_once 'formatters/LengthFormatter.php';
/**
* Application_Model_StoredFile class
*
@ -551,34 +553,6 @@ class Application_Model_StoredFile {
return $res;
}
/*
* @param DateInterval $p_interval
*
* @return string $runtime
*/
private static function formatDuration($dt) {
$hours = $dt->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'] = "<input type='checkbox' name='cb_".$row['id']."'>";

View File

@ -0,0 +1,56 @@
<?php
class LengthFormatter {
/**
* @string length
*/
private $_length;
/*
* @param string $length formatted H:i:s.u (can be > 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;
}
}

View File

@ -1,3 +0,0 @@
<?php
header ("location: html/");
exit;

View File

@ -14,7 +14,7 @@
<a id="playlist_name_display"><?php echo $this->pl->getName(); ?></a>
<input type="text" maxlength="255" size="40" class="element_hidden" id="playlist_name_input" />
</h3>
<h4 id="spl_length"><?php echo $this->pl->getLength(); ?></h4>
<h4 id="spl_length"><?php echo $this->length; ?></h4>
</div>
<fieldset class="toggle closed" id="fieldset-metadate_change">

View File

@ -12,13 +12,11 @@
<?php $i=0; ?>
<?php foreach($this->showContent as $row): ?>
<tr id="au_<?php echo $row["file_id"] ?>" class="<?php if($i&1){echo "even";}else{echo "odd";}?>">
<td><?php $dt = new DateTime($row["starts"], new DateTimeZone("UTC"));
$dt->setTimezone(new DateTimeZone(date_default_timezone_get()));
echo $dt->format("Y-m-d H:i:s") ?></td>
<td><?php echo $row["starts"] ?></td>
<td><?php echo $row["track_title"] ?></td>
<td><?php echo $row["artist_name"] ?></td>
<td><?php echo $row["album_title"] ?></td>
<td><?php echo $row["clip_length"] ?></td>
<td class="library_length"><?php echo $row["clip_length"] ?></td>
<td><?php echo $row["genre"] ?></td>
</tr>
<?php $i=$i+1; ?>

View File

@ -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;
}

View File

@ -75,3 +75,7 @@
.datatable_checkbox .DataTables_sort_wrapper {
text-align: center;
}
.library_year {
text-align: center;
}

View File

@ -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 {

View File

@ -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) {