Merge branch 'master' of dev.sourcefabric.org:airtime

This commit is contained in:
paul.baranowski 2011-03-06 11:05:23 -05:00
commit 3727195c54
548 changed files with 192982 additions and 161 deletions

View file

@ -21,7 +21,8 @@ $ccAcl->add(new Zend_Acl_Resource('library'))
->add(new Zend_Acl_Resource('nowplaying'))
->add(new Zend_Acl_Resource('search'))
->add(new Zend_Acl_Resource('dashboard'))
->add(new Zend_Acl_Resource('preference'));
->add(new Zend_Acl_Resource('preference'))
->add(new Zend_Acl_Resource('recorder'));
/** Creating permissions */
$ccAcl->allow('G', 'index')
@ -29,13 +30,13 @@ $ccAcl->allow('G', 'index')
->allow('G', 'error')
->allow('G', 'nowplaying')
->allow('G', 'api')
->allow('G', 'recorder')
->allow('G', 'schedule')
->allow('G', 'dashboard')
->allow('H', 'library')
->allow('H', 'search')
->allow('H', 'plupload')
->allow('H', 'playlist')
->allow('H', 'sideplaylist')
->allow('A', 'user')
->allow('A', 'preference');

View file

@ -0,0 +1,32 @@
<?php
class RecorderController extends Zend_Controller_Action
{
public function init()
{
$ajaxContext = $this->_helper->getHelper('contextSwitch');
$ajaxContext->addActionContext('get-show-schedule', 'json')
->initContext();
}
public function indexAction()
{
// action body
}
public function getShowScheduleAction()
{
//$from = $this->_getParam("from");
//$to = $this->_getParam("to");
$today_timestamp = date("Y-m-d H:i:s");
$this->view->shows = Show::getShows($today_timestamp, null, $excludeInstance=NULL, $onlyRecord=TRUE);
}
}

View file

@ -188,7 +188,7 @@ class ScheduleController extends Zend_Controller_Action
$this->view->showContent = $show->getShowContent();
$this->view->timeFilled = $show->getTimeScheduled();
$this->view->percentFilled = $show->getPercentScheduledInRange();
$this->view->percentFilled = $show->getPercentScheduled();
$this->view->chosen = $this->view->render('schedule/scheduled-content.phtml');
unset($this->view->showContent);
@ -237,7 +237,7 @@ class ScheduleController extends Zend_Controller_Action
$this->view->showContent = $show->getShowContent();
$this->view->timeFilled = $show->getTimeScheduled();
$this->view->percentFilled = $show->getPercentScheduledInRange();
$this->view->percentFilled = $show->getPercentScheduled();
$this->view->chosen = $this->view->render('schedule/scheduled-content.phtml');
unset($this->view->showContent);
}
@ -268,7 +268,7 @@ class ScheduleController extends Zend_Controller_Action
$this->view->timeFilled = $show->getTimeScheduled();
$this->view->showName = $show->getName();
$this->view->showLength = $show->getShowLength();
$this->view->percentFilled = $show->getPercentScheduledInRange();
$this->view->percentFilled = $show->getPercentScheduled();
$this->view->s_wday = $dateInfo_s['weekday'];
$this->view->s_month = $dateInfo_s['month'];

View file

@ -110,10 +110,11 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
$controller = strtolower($request->getControllerName());
if ($controller == 'api'){
$this->setRoleName("G");
} else if (!Zend_Auth::getInstance()->hasIdentity()){
if ($controller == 'api' || $controller == 'recorder'){
$this->setRoleName("G");
}
else if (!Zend_Auth::getInstance()->hasIdentity()){
if ($controller !== 'login') {

View file

@ -2,92 +2,91 @@
class Application_Model_Nowplaying
{
/*
public static function InsertBlankRow($i, $rows){
$startDateFull = $rows[$i-1][3];
$endDateFull = $rows[$i][2];
$startDate = explode(".", $startDateFull);
$endDate = explode(".", $endDateFull);
public static function FindBeginningOfShow($rows){
$numRows = count($rows);
$epochStartMS = strtotime($startDate[0])*1000;
$epochEndMS = strtotime($endDate[0])*1000;
$newCopy = array();
if (count($startDate) > 1)
$epochStartMS += $startDate[1];
if (count($endDate) > 1)
$epochEndMS += $endDate[1];
for ($i=0; $i<$numRows; $i++){
$currentRow = $rows[$i];
if ($i == 0 || ($i != 0 && $currentRow['instance_id'] != $rows[$i-1]['instance_id'])){
//$currentRow is first instance of a show.
$group = $currentRow;
$group['group'] = 'x';
$group['item_starts'] = $group['show_starts'];
$group['item_ends'] = $group['show_ends'];
$blankRow = array(array("b", $startDateFull, $startDateFull, $endDate, Application_Model_DateHelper::ConvertMSToHHMMSSmm($epochEndMS - $epochStartMS), "-", "-", "-", "-" , "-", "", ""));
array_splice($rows, $i, 0, $blankRow);
return $rows;
}
public static function FindGaps($rows){
$n = count($rows);
$blankRowIndices = array();
$arrayIndexOffset = 0;
if ($n < 2)
return $rows;
for ($i=1; $i<$n; $i++){
if ($rows[$i-1][3] != $rows[$i][2])
array_push($blankRowIndices, $i);
array_push($newCopy, $group);
}
array_push($newCopy, $currentRow);
}
for ($i=0, $n=count($blankRowIndices); $i<$n; $i++){
$rows = Application_Model_Nowplaying::InsertBlankRow($blankRowIndices[$i]+$arrayIndexOffset, $rows);
$arrayIndexOffset++;
}
return $rows;
return $newCopy;
}
*/
/*
public static function FindGapsBetweenShows($showsMap){
public static function FindGapAtEndOfShow($rows){
$numRows = count($rows);
$previousShow = null;
foreach($showsMap as $k => $show){
$currentShow = $showsMap[$k];
$newCopy = array();
if (!is_null($previousShow)){
$diff = strtotime($currentShow['starts']) - strtotime($previousShow['ends'])
if ($$diff != 0){
//array_splice($showsMap, $i, 0, $blankRow);
for ($i=0; $i<$numRows; $i++){
$currentRow = $rows[$i];
array_push($newCopy, $currentRow);
if ($i+1 == $numRows || ($i+1 !=$numRows && $currentRow['instance_id'] != $rows[$i+1]['instance_id'])){
//$row is the last instance in the show.
if ($currentRow['item_ends'] == ""){
//show is empty and has no scheduled items in it. Therefore
//the gap is the entire length of the show.
$currentRow['item_ends'] = $currentRow['show_starts'];
}
$diff = strtotime($currentRow['show_ends']) - strtotime($currentRow['item_ends']);
if ($diff > 0){
//gap at the end of show. Lets create a "gap" row
$gap = $currentRow;
$gap['gap'] = '';
$gap['item_starts'] = $diff;
array_push($newCopy, $gap);
}
}
$previousShow = $showsMap[$k];
}
return $showsMap;
return $newCopy;
}
*/
public static function FindGapAtEndOfShow($show, $rows){
$showStartTime = $show['starts'];
$showEndTime = $show['ends'];
if (count($rows) > 1){
$lastItem = $rows[count($rows)-1];
$lastItemEndTime = $lastItem['ends'];
} else {
$lastItemEndTime = $showStartTime;
public static function FilterRowsByDate($rows, $date, $startCutoff, $endCutoff){
$dateNow = new Application_Model_DateHelper;
$timeNow = $dateNow->getDate();
$data = array();
//iterate over each show, and calculate information for it.
$numItems = count($rows);
for ($i=0; $i<$numItems; $i++){
$item = $rows[$i];
if ((strtotime($item['item_ends']) > $date->getEpochTime() - $startCutoff
&& strtotime($item['item_starts']) < $date->getEpochTime() + $endCutoff) || array_key_exists("group", $item) || array_key_exists("gap", $item)){
if (array_key_exists("group", $item)){
$type = "g";
} else if (array_key_exists("gap", $item)){
$type = "b";
} else if (strtotime($item['item_ends']) < strtotime($timeNow)){
$type = "p";
} else if (strtotime($item['item_starts']) < strtotime($timeNow) && strtotime($timeNow) < strtotime($item['item_ends'])
&& strtotime($item['show_starts']) < strtotime($timeNow) && strtotime($timeNow) < strtotime($item['show_ends'])){
$type = "c";
} else {
$type = "n";
}
array_push($data, array($type, $item["item_starts"], $item["item_starts"], $item["item_ends"], $item["clip_length"], $item["track_title"], $item["artist_name"], $item["album_title"], $item["playlist_name"], $item["show_name"], $item["instance_id"]));
}
}
$diff = Application_Model_DateHelper::TimeDiff($lastItemEndTime, $showEndTime);
if ($diff <= 0){
//ok!
return null;
} else {
//There is a gap at the end of the show. Return blank row
return array("b", $diff, "-", "-", "-", "-", "-", "-", "-", "-", "-", "-");
}
return $data;
}
public static function GetDataGridData($viewType, $dateString){
@ -105,44 +104,19 @@ class Application_Model_Nowplaying
$timeNow = $date->getDate();
$startCutoff = $date->getNowDayStartDiff();
$endCutoff = $date->getNowDayEndDiff();
$endCutoff = $date->getNowDayEndDiff();
}
$showsMap = Show_DAL::GetShowsInRange($timeNow, $startCutoff, $endCutoff);
$rows = Show_DAL::GetShowsInRange($timeNow, $startCutoff, $endCutoff);
$rows = Application_Model_Nowplaying::FindBeginningOfShow($rows);
$rows = Application_Model_Nowplaying::FindGapAtEndOfShow($rows);
//$rows = FindGapsBetweenShows
$data = Application_Model_Nowplaying::FilterRowsByDate($rows, $date, $startCutoff, $endCutoff);
//iterate over each show, and calculate information for it.
foreach($showsMap as $k => $show){
$rows = Schedule::GetShowInstanceItems($k);
$gapRow = Application_Model_Nowplaying::FindGapAtEndOfShow($showsMap[$k], $rows);
foreach ($rows as $item){
//check if this item is in todays date range
if (strtotime($item['ends']) > $date->getEpochTime() - $startCutoff
&& strtotime($item['starts']) < $date->getEpochTime() + $endCutoff){
if ($item['ends'] < $timeNow){
$type = "p";
} else if ($item['starts'] < $timeNow && $timeNow < $item['ends']){
$type = "c";
} else {
$type = "n";
}
array_push($showsMap[$k]['items'], array($type, $item["starts"], $item["starts"], $item["ends"], $item["clip_length"], $item["track_title"], $item["artist_name"],
$item["album_title"], $item["name"], $item["show_name"], $item["instance_id"], $item["group_id"]));
}
}
if (!is_null($gapRow))
array_push($showsMap[$k]['items'], $gapRow);
}
//$showsMap = Application_Model_Nowplaying::FindGapsBetweenShows($showsMap);
$date = new Application_Model_DateHelper;
$timeNow = $date->getDate();
return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$showsMap);
return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data);
}
}

View file

@ -278,12 +278,11 @@ class Schedule {
return ($count == '0');
}
public static function getTimeUnScheduledInRange($s_datetime, $e_datetime) {
public static function getTimeUnScheduledInRange($instance_id, $s_datetime, $e_datetime) {
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]."
WHERE (starts >= '{$s_datetime}')
AND (ends <= '{$e_datetime}')";
$sql = "SELECT SUM(clip_length) FROM $CC_CONFIG[scheduleTable]"
." WHERE instance_id = $instance_id";
$time = $CC_DBC->GetOne($sql);
@ -313,6 +312,20 @@ class Schedule {
return $res;
}
public static function GetTotalShowTime($instance_id) {
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT SUM(clip_length) FROM $CC_CONFIG[scheduleTable]"
." WHERE instance_id = $instance_id";
$res = $CC_DBC->GetOne($sql);
if(is_null($res))
return 0;
return $res;
}
public static function getPercentScheduledInRange($s_datetime, $e_datetime) {
@ -337,6 +350,25 @@ class Schedule {
return $percent;
}
public static function GetPercentScheduled($instance_id, $s_datetime, $e_datetime){
$time = Schedule::GetTotalShowTime($instance_id);
$s_epoch = strtotime($s_datetime);
$e_epoch = strtotime($e_datetime);
$con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
$sql = "SELECT EXTRACT(EPOCH FROM INTERVAL '{$time}')";
$r = $con->query($sql);
$i_epoch = $r->fetchColumn(0);
$percent = ceil(($i_epoch / ($e_epoch - $s_epoch)) * 100);
if ($percent > 100)
$percent = 100;
return $percent;
}
/**
* Return TRUE if file is going to be played in the future.
@ -490,7 +522,8 @@ class Schedule {
." WHERE st.playlist_id = pt.id"
." AND st.file_id = ft.id"
." AND st.instance_id = si.id"
." AND si.show_id = show.id";
." AND si.show_id = show.id"
." AND st.starts < si.ends";
if ($timePeriod < 0){
$sql .= " AND st.ends < TIMESTAMP '$timeStamp'"

View file

@ -175,15 +175,26 @@ class Show {
Show::populateShowUntilLastGeneratedDate($showId);
}
public static function getShows($start_timestamp, $end_timestamp, $excludeInstance=NULL) {
public static function getShows($start_timestamp, $end_timestamp, $excludeInstance=NULL, $onlyRecord=FALSE) {
global $CC_DBC;
$sql = "SELECT starts, ends, show_id, name, description, color, background_color, cc_show_instances.id AS instance_id
FROM cc_show_instances
LEFT JOIN cc_show ON cc_show.id = cc_show_instances.show_id
WHERE ((starts >= '{$start_timestamp}' AND starts < '{$end_timestamp}')
LEFT JOIN cc_show ON cc_show.id = cc_show_instances.show_id";
//only want shows that are starting at the time or later.
if($onlyRecord) {
$sql = $sql." WHERE (starts >= '{$start_timestamp}' AND starts < timestamp '{$start_timestamp}' + interval '2 hours')";
$sql = $sql." AND (record = TRUE)";
}
else {
$sql = $sql." WHERE ((starts >= '{$start_timestamp}' AND starts < '{$end_timestamp}')
OR (ends > '{$start_timestamp}' AND ends <= '{$end_timestamp}')
OR (starts <= '{$start_timestamp}' AND ends >= '{$end_timestamp}'))";
}
if(isset($excludeInstance)) {
foreach($excludeInstance as $instance) {
@ -196,7 +207,6 @@ class Show {
}
//echo $sql;
return $CC_DBC->GetAll($sql);
}
@ -446,6 +456,10 @@ class ShowInstance {
return $showInstance->getDbShowId();
}
public function getShowInstanceId() {
return $this->_instanceId;
}
public function getName() {
$show = CcShowQuery::create()->findPK($this->getShowId());
return $show->getDbName();
@ -625,11 +639,8 @@ class ShowInstance {
}
public function getTimeScheduled() {
$start_timestamp = $this->getShowStart();
$end_timestamp = $this->getShowEnd();
$time = Schedule::getTimeScheduledInRange($start_timestamp, $end_timestamp);
$instance_id = $this->getShowInstanceId();
$time = Schedule::GetTotalShowTime($instance_id);
return $time;
}
@ -638,8 +649,9 @@ class ShowInstance {
$start_timestamp = $this->getShowStart();
$end_timestamp = $this->getShowEnd();
$instance_id = $this->getShowInstanceId();
$time = Schedule::getTimeUnScheduledInRange($start_timestamp, $end_timestamp);
$time = Schedule::getTimeUnScheduledInRange($instance_id, $start_timestamp, $end_timestamp);
return $time;
}
@ -652,6 +664,14 @@ class ShowInstance {
return Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp);
}
public function getPercentScheduled(){
$start_timestamp = $this->getShowStart();
$end_timestamp = $this->getShowEnd();
$instance_id = $this->getShowInstanceId();
return Schedule::GetPercentScheduled($instance_id, $start_timestamp, $end_timestamp);
}
public function getShowLength(){
global $CC_DBC;
@ -760,32 +780,34 @@ class Show_DAL{
public static function GetShowsInRange($timeNow, $start, $end){
global $CC_CONFIG, $CC_DBC;
$sql = "SELECT *,"
." si.starts as start_timestamp,"
." si.ends as end_timestamp,"
." si.id as instance_id"
." FROM "
." $CC_CONFIG[showInstances] si,"
." $CC_CONFIG[showTable] s"
." WHERE si.show_id = s.id"
." AND ((si.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')"
$sql = "SELECT"
." si.starts as show_starts,"
." si.ends as show_ends,"
." st.starts as item_starts,"
." st.ends as item_ends,"
." st.clip_length as clip_length,"
." ft.track_title as track_title,"
." ft.artist_name as artist_name,"
." ft.album_title as album_title,"
." s.name as show_name,"
." si.id as instance_id,"
." pt.name as playlist_name"
." FROM $CC_CONFIG[showInstances] si"
." LEFT JOIN $CC_CONFIG[scheduleTable] st"
." ON st.instance_id = si.id"
." LEFT JOIN $CC_CONFIG[playListTable] pt"
." ON st.playlist_id = pt.id"
." LEFT JOIN $CC_CONFIG[filesTable] ft"
." ON st.file_id = ft.id"
." LEFT JOIN $CC_CONFIG[showTable] s"
." ON si.show_id = s.id"
." WHERE ((si.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')"
." OR (si.starts > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')"
." OR (si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds' AND si.ends > TIMESTAMP '$timeNow' + INTERVAL '$end seconds'))"
." ORDER BY si.starts";
." AND (st.starts < si.ends)"
." ORDER BY st.starts";
$rows = $CC_DBC->GetAll($sql);
$showsMap = array();
$rowsCount = count($rows);
for ($i=0; $i<$rowsCount; $i++){
$rows[$i]['items'] = array();
array_push($rows[$i]['items'],
array("s", $rows[$i]["starts"], $rows[$i]["starts"], $rows[$i]["ends"], "", "", "", "", "", $rows[$i]["name"], $rows[$i]["instance_id"], ""));
$showsMap[$rows[$i]['instance_id']] = $rows[$i];
}
return $showsMap;
return $CC_DBC->GetAll($sql);
}
}

View file

@ -1655,7 +1655,7 @@ class StoredFile {
$fromTable = "cc_playlist AS pl LEFT JOIN cc_playlisttimes AS plt USING(id) LEFT JOIN cc_subjs AS sub ON pl.editedby = sub.id";
$datatables["optWhere"][] = "plt.length <= INTERVAL '{$p_length}'";
$datatables["optWhere"][] = "INTERVAL '{$p_length}' > INTERVAL '00:00:00'";
$datatables["optWhere"][] = "plt.length > INTERVAL '00:00:00'";
return StoredFile::searchFiles($fromTable, $datatables);

View file

@ -0,0 +1,22 @@
<?php
require_once 'soundcloud-api/Services/Soundcloud.php';
class Airtime_View_Helper_SoundCloudLink extends Zend_View_Helper_Abstract
{
public function soundCloudLink()
{
$request = Zend_Controller_Front::getInstance()->getRequest();
$host = $request->getHttpHost();
$controller = $request->getControllerName();
$action = $request->getActionName();
$redirectUrl = "http://{$host}/{$controller}/{$action}";
$soundcloud = new Services_Soundcloud('2CLCxcSXYzx7QhhPVHN4A', 'pZ7beWmF06epXLHVUP1ufOg2oEnIt9XhE8l8xt0bBs', $redirectUrl);
$authorizeUrl = $soundcloud->getAuthorizeUrl();
return $authorizeUrl;
}
}

View file

@ -0,0 +1 @@
<br /><br /><center>View script for controller <b>AirtimeRecorder</b> and script/action name <b>index</b></center>

View file

@ -0,0 +1 @@
<br /><br /><center>View script for controller <b>Recorder</b> and script/action name <b>getShowSchedule</b></center>

View file

@ -0,0 +1 @@
<br /><br /><center>View script for controller <b>Recorder</b> and script/action name <b>index</b></center>

View file

@ -28,6 +28,7 @@
<div id="show_progressbar"></div>
<span id="show_length" class="time"><?php echo $this->showLength; ?></span>
</div>
<div id="show_time_warning"></div>
</div>
</div>
</div>