Merge branch 'devel' of dev.sourcefabric.org:airtime into devel
This commit is contained in:
commit
5b65b56b93
|
@ -18,12 +18,9 @@ $ccAcl->add(new Zend_Acl_Resource('library'))
|
|||
->add(new Zend_Acl_Resource('plupload'))
|
||||
->add(new Zend_Acl_Resource('schedule'))
|
||||
->add(new Zend_Acl_Resource('api'))
|
||||
->add(new Zend_Acl_Resource('nowplaying'))
|
||||
->add(new Zend_Acl_Resource('systemstatus'))
|
||||
->add(new Zend_Acl_Resource('search'))
|
||||
->add(new Zend_Acl_Resource('dashboard'))
|
||||
->add(new Zend_Acl_Resource('preference'))
|
||||
->add(new Zend_Acl_Resource('recorder'))
|
||||
->add(new Zend_Acl_Resource('showbuilder'))
|
||||
->add(new Zend_Acl_Resource('auth'))
|
||||
->add(new Zend_Acl_Resource('playouthistory'))
|
||||
|
@ -37,13 +34,11 @@ $ccAcl->allow('G', 'index')
|
|||
->allow('G', 'showbuilder')
|
||||
->allow('G', 'api')
|
||||
->allow('G', 'auth')
|
||||
->allow('G', 'recorder')
|
||||
->allow('G', 'schedule')
|
||||
->allow('G', 'dashboard')
|
||||
->allow('H', 'usersettings')
|
||||
->allow('H', 'plupload')
|
||||
->allow('H', 'library')
|
||||
->allow('H', 'search')
|
||||
->allow('H', 'playlist')
|
||||
->allow('A', 'playouthistory')
|
||||
->allow('A', 'user')
|
||||
|
|
|
@ -376,48 +376,6 @@ class ApiController extends Zend_Controller_Action
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public function notifyScheduleGroupPlayAction()
|
||||
{
|
||||
global $CC_CONFIG;
|
||||
|
||||
// disable the view and the layout
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
$api_key = $this->_getParam('api_key');
|
||||
if(!in_array($api_key, $CC_CONFIG["apiKey"]))
|
||||
{
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
print 'You are not allowed to access this resource.';
|
||||
exit;
|
||||
}
|
||||
|
||||
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||
|
||||
$schedule_group_id = $this->_getParam("schedule_id");
|
||||
if (is_numeric($schedule_group_id)) {
|
||||
$sg = new Application_Model_ScheduleGroup($schedule_group_id);
|
||||
if ($sg->exists()) {
|
||||
$result = $sg->notifyGroupStartPlay();
|
||||
if (!PEAR::isError($result)) {
|
||||
echo json_encode(array("status"=>1, "message"=>""));
|
||||
exit;
|
||||
} else {
|
||||
echo json_encode(array("status"=>0, "message"=>"DB Error:".$result->getMessage()));
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
echo json_encode(array("status"=>0, "message"=>"Schedule group does not exist: ".$schedule_group_id));
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
echo json_encode(array("status"=>0, "message"=>"Incorrect or non-numeric arguments given."));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public function recordedShowsAction()
|
||||
{
|
||||
global $CC_CONFIG;
|
||||
|
|
|
@ -772,10 +772,9 @@ class ScheduleController extends Zend_Controller_Action
|
|||
|
||||
public function cancelShowAction()
|
||||
{
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
$user = new Application_Model_User($userInfo->id);
|
||||
$user = Application_Model_User::GetCurrentUser();
|
||||
|
||||
if($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
|
||||
if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
|
||||
$showInstanceId = $this->_getParam('id');
|
||||
|
||||
try {
|
||||
|
|
|
@ -44,11 +44,8 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
|
||||
$this->view->headScript()->appendFile($this->view->baseUrl('/js/airtime/library/events/library_showbuilder.js?'.$CC_CONFIG['airtime_version']),'text/javascript');
|
||||
|
||||
$user = Application_Model_User::GetCurrentUser();
|
||||
|
||||
$user = Application_Model_User::GetCurrentUser();
|
||||
$refer_sses = new Zend_Session_Namespace('referrer');
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
$user = new Application_Model_User($userInfo->id);
|
||||
|
||||
if ($request->isPost()) {
|
||||
$form = new Application_Form_RegisterAirtime();
|
||||
|
@ -96,7 +93,7 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
//popup if previous page was login
|
||||
if ($refer_sses->referrer == 'login' && Application_Model_Nowplaying::ShouldShowPopUp()
|
||||
if ($refer_sses->referrer == 'login' && Application_Model_Preference::ShouldShowPopUp()
|
||||
&& !Application_Model_Preference::GetSupportFeedback() && $user->isAdmin()){
|
||||
|
||||
$form = new Application_Form_RegisterAirtime();
|
||||
|
@ -110,10 +107,9 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
}
|
||||
|
||||
//determine whether to remove/hide/display the library.
|
||||
$showLib = false;
|
||||
$user = Application_Model_User::GetCurrentUser();
|
||||
$showLib = false;
|
||||
if (!$user->isGuest()) {
|
||||
$hideLib = false;
|
||||
$disableLib = false;
|
||||
$data = Application_Model_Preference::GetValue("nowplaying_screen", true);
|
||||
if ($data != "") {
|
||||
$settings = unserialize($data);
|
||||
|
@ -124,9 +120,9 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
}
|
||||
}
|
||||
else {
|
||||
$hideLib = true;
|
||||
$disableLib = true;
|
||||
}
|
||||
$this->view->hideLib = $hideLib;
|
||||
$this->view->disableLib = $disableLib;
|
||||
$this->view->showLib = $showLib;
|
||||
|
||||
//populate date range form for show builder.
|
||||
|
@ -168,8 +164,7 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
$baseUrl = $request->getBaseUrl();
|
||||
$menu = array();
|
||||
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
$user = new Application_Model_User($userInfo->id);
|
||||
$user = Application_Model_User::GetCurrentUser();
|
||||
|
||||
$item = CcScheduleQuery::create()->findPK($id);
|
||||
$instance = $item->getCcShowInstances();
|
||||
|
@ -259,9 +254,6 @@ class ShowbuilderController extends Zend_Controller_Action
|
|||
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
|
||||
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
|
||||
|
||||
Logging::log("showbuilder starts {$startsDT->format("Y-m-d H:i:s")}");
|
||||
Logging::log("showbuilder ends {$endsDT->format("Y-m-d H:i:s")}");
|
||||
|
||||
$opts = array("myShows" => $my_shows, "showFilter" => $show_filter);
|
||||
$showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts);
|
||||
|
||||
|
|
|
@ -1,168 +0,0 @@
|
|||
<?php
|
||||
require_once('Subjects.php');
|
||||
|
||||
define('USE_ALIB_CLASSES', TRUE);
|
||||
define('ALIBERR_NOTLOGGED', 30);
|
||||
define('ALIBERR_NOTEXISTS', 31);
|
||||
|
||||
/**
|
||||
* Authentication/authorization class
|
||||
*
|
||||
* @package Airtime
|
||||
* @subpackage Alib
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
*/
|
||||
class Alib {
|
||||
/* ======================================================= public methods */
|
||||
|
||||
/* ----------------------------------------------- session/authentication */
|
||||
|
||||
/* -------------------------------------------------------- authorization */
|
||||
/**
|
||||
* Remove permission record
|
||||
*
|
||||
* @param int $permid
|
||||
* local permission id
|
||||
* @param int $subj
|
||||
* local user/group id
|
||||
* @param int $obj
|
||||
* local object id
|
||||
* @return boolean|PEAR_Error
|
||||
*/
|
||||
public static function RemovePerm($permid=NULL, $subj=NULL, $obj=NULL)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$ca = array();
|
||||
if ($permid) {
|
||||
$ca[] = "permid=$permid";
|
||||
}
|
||||
if ($subj) {
|
||||
$ca[] = "subj=$subj";
|
||||
}
|
||||
if ($obj) {
|
||||
$ca[] = "obj=$obj";
|
||||
}
|
||||
$cond = join(" AND ", $ca);
|
||||
if (!$cond) {
|
||||
return TRUE;
|
||||
}
|
||||
$sql = "DELETE FROM ".$CC_CONFIG['permTable']." WHERE $cond";
|
||||
return $CC_DBC->query($sql);
|
||||
} // fn removePerm
|
||||
|
||||
|
||||
/* ---------------------------------------------------------- object tree */
|
||||
|
||||
/* --------------------------------------------------------- users/groups */
|
||||
|
||||
/* ------------------------------------------------------------- sessions */
|
||||
/**
|
||||
* Get login from session id (token)
|
||||
*
|
||||
* @param string $sessid
|
||||
* @return string|PEAR_Error
|
||||
*/
|
||||
public static function GetSessLogin($sessid)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT login FROM ".$CC_CONFIG['sessTable']." WHERE sessid='$sessid'";
|
||||
$r = $CC_DBC->getOne($sql);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
if (is_null($r)){
|
||||
return PEAR::raiseError("Alib::GetSessLogin:".
|
||||
" invalid session id ($sessid)",
|
||||
ALIBERR_NOTEXISTS, PEAR_ERROR_RETURN);
|
||||
}
|
||||
return $r;
|
||||
} // fn GetSessLogin
|
||||
|
||||
|
||||
/**
|
||||
* Get user id from session id.
|
||||
*
|
||||
* @param string $p_sessid
|
||||
* @return int|PEAR_Error
|
||||
*/
|
||||
public static function GetSessUserId($p_sessid)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT userid FROM ".$CC_CONFIG['sessTable']." WHERE sessid='$p_sessid'";
|
||||
$r = $CC_DBC->getOne($sql);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
if (is_null($r)) {
|
||||
return PEAR::raiseError("Alib::getSessUserId:".
|
||||
" invalid session id ($p_sessid)",
|
||||
ALIBERR_NOTEXISTS, PEAR_ERROR_RETURN);
|
||||
}
|
||||
return $r;
|
||||
} // fn getSessUserId
|
||||
|
||||
|
||||
/* --------------------------------------------------------- info methods */
|
||||
/**
|
||||
* Get all permissions on object.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array|null|PEAR_Error
|
||||
*/
|
||||
public static function GetObjPerms($id)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT s.login, p.* FROM ".$CC_CONFIG['permTable']." p, ".$CC_CONFIG['subjTable']." s"
|
||||
." WHERE s.id=p.subj AND p.obj=$id";
|
||||
return $CC_DBC->getAll($sql);
|
||||
} // fn GetObjPerms
|
||||
|
||||
|
||||
/**
|
||||
* Get all permissions of subject.
|
||||
*
|
||||
* @param int $sid
|
||||
* @return array
|
||||
*/
|
||||
public static function GetSubjPerms($sid)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT *"
|
||||
." FROM ".$CC_CONFIG['permTable']
|
||||
." WHERE p.subj=$sid";
|
||||
$a1 = $CC_DBC->getAll($sql);
|
||||
return $a1;
|
||||
} // fn GetSubjPerms
|
||||
|
||||
|
||||
/* ------------------------ info methods related to application structure */
|
||||
/* (this part should be added/rewritten to allow defining/modifying/using
|
||||
* application structure)
|
||||
* (only very simple structure definition - in $CC_CONFIG - supported now)
|
||||
*/
|
||||
|
||||
/* ====================================================== private methods */
|
||||
|
||||
/**
|
||||
* Create new session id. Return the new session ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function _createSessid()
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
for ($c = 1; $c > 0; ){
|
||||
$sessid = md5(uniqid(rand()));
|
||||
$sql = "SELECT count(*) FROM ".$CC_CONFIG['sessTable']
|
||||
." WHERE sessid='$sessid'";
|
||||
$c = $CC_DBC->getOne($sql);
|
||||
if (PEAR::isError($c)) {
|
||||
return $c;
|
||||
}
|
||||
}
|
||||
return $sessid;
|
||||
} // fn _createSessid
|
||||
|
||||
|
||||
} // class Alib
|
|
@ -75,13 +75,11 @@ class Application_Model_Datatables {
|
|||
}
|
||||
|
||||
try {
|
||||
$r = $con->query($sqlTotalRows);
|
||||
Logging::log($sqlTotalRows);
|
||||
$r = $con->query($sqlTotalRows);
|
||||
$totalRows = $r->fetchColumn(0);
|
||||
|
||||
if (isset($sqlTotalDisplayRows)) {
|
||||
$r = $con->query($sqlTotalDisplayRows);
|
||||
Logging::log($sqlTotalDisplayRows);
|
||||
$r = $con->query($sqlTotalDisplayRows);
|
||||
$totalDisplayRows = $r->fetchColumn(0);
|
||||
}
|
||||
else {
|
||||
|
@ -93,11 +91,11 @@ class Application_Model_Datatables {
|
|||
$results = $r->fetchAll();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
Logging::log($e->getMessage());
|
||||
Logging::debug($e->getMessage());
|
||||
}
|
||||
|
||||
//display sql executed in airtime log for testing
|
||||
Logging::log($sql);
|
||||
//Logging::log($sql);
|
||||
|
||||
return array(
|
||||
"sEcho" => intval($data["sEcho"]),
|
||||
|
|
|
@ -1,194 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Application_Model_Nowplaying
|
||||
{
|
||||
|
||||
private static function CreateHeaderRow($p_showName, $p_showStart, $p_showEnd){
|
||||
return array("h", "", $p_showStart, $p_showEnd, $p_showName, "", "", "", "", "", "");
|
||||
}
|
||||
|
||||
private static function CreateDatatableRows($p_dbRows){
|
||||
$dataTablesRows = array();
|
||||
|
||||
$epochNow = time();
|
||||
|
||||
$lastRow = end($p_dbRows);
|
||||
|
||||
//Information about show is true for all rows in parameter so only check the last row's show
|
||||
//start and end times.
|
||||
if (isset($lastRow)){
|
||||
$showStartDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($lastRow['show_starts']);
|
||||
$showEndDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($lastRow['show_ends']);
|
||||
$showStarts = $showStartDateTime->format("Y-m-d H:i:s");
|
||||
$showEnds = $showEndDateTime->format("Y-m-d H:i:s");
|
||||
}
|
||||
|
||||
foreach ($p_dbRows as $dbRow) {
|
||||
|
||||
$itemStartDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($dbRow['item_starts']);
|
||||
$itemEndDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($dbRow['item_ends']);
|
||||
|
||||
$itemStarts = $itemStartDateTime->format("Y-m-d H:i:s");
|
||||
$itemEnds = $itemEndDateTime->format("Y-m-d H:i:s");
|
||||
|
||||
// Allow show to exceed 1 second per CC-3183
|
||||
$status = ($showEnds < $itemEnds) ? "x" : "";
|
||||
|
||||
$type = "a";
|
||||
$type .= ($itemStartDateTime->getTimestamp() <= $epochNow
|
||||
&& $epochNow < $itemEndDateTime->getTimestamp()
|
||||
&& $epochNow < $showEndDateTime->getTimestamp()) ? "c" : "";
|
||||
|
||||
// remove millisecond from the time format
|
||||
$itemStart = explode('.', $dbRow['item_starts']);
|
||||
$itemEnd = explode('.', $dbRow['item_ends']);
|
||||
|
||||
//format duration
|
||||
$duration = explode('.', $dbRow['clip_length']);
|
||||
$formatted = self::FormatDuration($duration[0]);
|
||||
$dataTablesRows[] = array($type, $itemStarts, $itemStarts, $itemEnds,
|
||||
$formatted, $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'],
|
||||
$dbRow['playlist_name'], $dbRow['show_name'], $status);
|
||||
}
|
||||
|
||||
//Modify the last entry in the data table to adjust its end time to be equal to the
|
||||
//shows end time if it exceeds it.
|
||||
$lastRow = end($dataTablesRows);
|
||||
if (isset($lastRow) && strtotime($showEnds) < strtotime($lastRow[3])){
|
||||
$dataTablesRows[sizeof($dataTablesRows)-1][3] = $showEnds;
|
||||
}
|
||||
return $dataTablesRows;
|
||||
}
|
||||
|
||||
private static function CreateGapRow($p_gapTime){
|
||||
return array("g", "", "", "", $p_gapTime, "", "", "", "", "", "");
|
||||
}
|
||||
|
||||
private static function CreateRecordingRow($p_showInstance){
|
||||
return array("r", "", "", "", $p_showInstance->getName(), "", "", "", "", "", "");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The purpose of this function is to return an array of scheduled
|
||||
* items. There are two parameters. $p_viewType can be either "now"
|
||||
* or "day". If "now", we show all scheduled items in the near future.
|
||||
*
|
||||
* If "day" we need to find what day was requested by the user, and return
|
||||
* scheduled items for that day.
|
||||
*
|
||||
* $p_dateString is only used when $p_viewType is "day" it is in the format
|
||||
* "2012-12-31". In this case it tells us which day to use.
|
||||
*/
|
||||
public static function GetDataGridData($p_viewType, $p_dateString){
|
||||
|
||||
if ($p_viewType == "now"){
|
||||
$start_dt = new DateTime("now", new DateTimeZone("UTC"));
|
||||
$end_dt = clone $start_dt;
|
||||
|
||||
$start_dt->sub(new DateInterval("PT60S"));
|
||||
$end_dt->add(new DateInterval("PT24H"));
|
||||
} else {
|
||||
//convert to UTC
|
||||
$utc_dt = Application_Model_DateHelper::ConvertToUtcDateTime($p_dateString);
|
||||
$start_dt = $utc_dt;
|
||||
|
||||
$end_dt = clone $utc_dt;
|
||||
$end_dt->add(new DateInterval("PT24H"));
|
||||
}
|
||||
|
||||
$starts = $start_dt->format("Y-m-d H:i:s");
|
||||
$ends = $end_dt->format("Y-m-d H:i:s");
|
||||
|
||||
$showIds = Application_Model_ShowInstance::GetShowsInstancesIdsInRange($starts, $ends);
|
||||
|
||||
//get all the pieces to be played between the start cut off and the end cut off.
|
||||
$scheduledItems = Application_Model_Schedule::getScheduleItemsInRange($starts, $ends);
|
||||
|
||||
$orderedScheduledItems;
|
||||
foreach ($scheduledItems as $scheduledItem){
|
||||
$orderedScheduledItems[$scheduledItem['instance_id']][] = $scheduledItem;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($showIds as $showId){
|
||||
$instanceId = $showId['id'];
|
||||
|
||||
//gets the show information
|
||||
$si = new Application_Model_ShowInstance($instanceId);
|
||||
|
||||
$showId = $si->getShowId();
|
||||
$show = new Application_Model_Show($showId);
|
||||
|
||||
$showStartDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($si->getShowInstanceStart());
|
||||
$showEndDateTime = Application_Model_DateHelper::ConvertToLocalDateTime($si->getShowInstanceEnd());
|
||||
|
||||
//append show header row
|
||||
$data[] = self::CreateHeaderRow($show->getName(), $showStartDateTime->format("Y-m-d H:i:s"), $showEndDateTime->format("Y-m-d H:i:s"));
|
||||
|
||||
$dataTablesRows = self::CreateDatatableRows($orderedScheduledItems[$instanceId]);
|
||||
|
||||
//append show audio item rows
|
||||
$data = array_merge($data, $dataTablesRows);
|
||||
|
||||
//append show gap time row
|
||||
$gapTime = self::FormatDuration($si->getShowEndGapTime(), true);
|
||||
if ($si->isRecorded())
|
||||
$data[] = self::CreateRecordingRow($si);
|
||||
else if ($gapTime > 0)
|
||||
$data[] = self::CreateGapRow($gapTime);
|
||||
}
|
||||
|
||||
$timeNow = gmdate("Y-m-d H:i:s");
|
||||
$rows = Application_Model_Show::GetCurrentShow($timeNow);
|
||||
Application_Model_Show::ConvertToLocalTimeZone($rows, array("starts", "ends", "start_timestamp", "end_timestamp"));
|
||||
return array("currentShow"=>$rows, "rows"=>$data);
|
||||
}
|
||||
|
||||
public static function ShouldShowPopUp(){
|
||||
$today = mktime(0, 0, 0, gmdate("m"), gmdate("d"), gmdate("Y"));
|
||||
$remindDate = Application_Model_Preference::GetRemindMeDate();
|
||||
if($remindDate == NULL || $today >= $remindDate){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* default $time format should be in format of 00:00:00
|
||||
* if $inSecond = true, then $time should be in seconds
|
||||
*/
|
||||
private static function FormatDuration($time, $inSecond=false){
|
||||
if($inSecond == false){
|
||||
$duration = explode(':', $time);
|
||||
}else{
|
||||
$duration = array();
|
||||
$duration[0] = intval(($time/3600)%24);
|
||||
$duration[1] = intval(($time/60)%60);
|
||||
$duration[2] = $time%60;
|
||||
}
|
||||
|
||||
if($duration[2] == 0){
|
||||
$duration[2] = '';
|
||||
}else{
|
||||
$duration[2] = intval($duration[2],10).'s';
|
||||
}
|
||||
|
||||
if($duration[1] == 0){
|
||||
if($duration[2] == ''){
|
||||
$duration[1] = '';
|
||||
}else{
|
||||
$duration[1] = intval($duration[1],10).'m ';
|
||||
}
|
||||
}else{
|
||||
$duration[1] = intval($duration[1],10).'m ';
|
||||
}
|
||||
|
||||
if($duration[0] == 0){
|
||||
$duration[0] = '';
|
||||
}else{
|
||||
$duration[0] = intval($duration[0],10).'h ';
|
||||
}
|
||||
|
||||
$out = $duration[0].$duration[1].$duration[2];
|
||||
return $out;
|
||||
}
|
||||
}
|
|
@ -773,5 +773,13 @@ class Application_Model_Preference
|
|||
return self::GetValue("live_dj_source_connection_url");
|
||||
}
|
||||
/* User specific preferences end */
|
||||
|
||||
public static function ShouldShowPopUp(){
|
||||
$today = mktime(0, 0, 0, gmdate("m"), gmdate("d"), gmdate("Y"));
|
||||
$remindDate = Application_Model_Preference::GetRemindMeDate();
|
||||
if($remindDate == NULL || $today >= $remindDate){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,401 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Preference storage class.
|
||||
*
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
* @see Application_Model_StoredFile
|
||||
*/
|
||||
/* ================== Prefs ================== */
|
||||
class Prefs {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/* ======================================================= public methods */
|
||||
/* ----------------------------------------------------- user preferences */
|
||||
/**
|
||||
* Read preference record by session id
|
||||
*
|
||||
* @param string $sessid
|
||||
* session id
|
||||
* @param string $key
|
||||
* preference key
|
||||
* @return string
|
||||
* preference value
|
||||
*/
|
||||
function loadPref($sessid, $key)
|
||||
{
|
||||
$subjid = Alib::GetSessUserId($sessid);
|
||||
if (PEAR::isError($subjid)) {
|
||||
return $subjid;
|
||||
}
|
||||
if (is_null($subjid)) {
|
||||
return PEAR::raiseError("Prefs::loadPref: invalid session id",
|
||||
GBERR_SESS);
|
||||
}
|
||||
$val = $this->readVal($subjid, $key);
|
||||
if (PEAR::isError($val)) {
|
||||
return $val;
|
||||
}
|
||||
if ($val === FALSE) {
|
||||
return PEAR::raiseError("Prefs::loadPref: invalid preference key",
|
||||
GBERR_PREF);
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save preference record by session id
|
||||
*
|
||||
* @param string $sessid
|
||||
* session id
|
||||
* @param string $key
|
||||
* preference key
|
||||
* @param string $value
|
||||
* preference value
|
||||
* @return boolean
|
||||
*/
|
||||
function savePref($sessid, $key, $value)
|
||||
{
|
||||
$subjid = Alib::GetSessUserId($sessid);
|
||||
if (PEAR::isError($subjid)) {
|
||||
return $subjid;
|
||||
}
|
||||
if (is_null($subjid)) {
|
||||
return PEAR::raiseError("Prefs::savePref: invalid session id", GBERR_SESS);
|
||||
}
|
||||
$r = $this->update($subjid, $key, $value);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
if ($r === FALSE) {
|
||||
$r = $this->insert($subjid, $key, $value);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete preference record by session id
|
||||
*
|
||||
* @param string $sessid
|
||||
* session id
|
||||
* @param string $key
|
||||
* preference key
|
||||
* @return boolean
|
||||
*/
|
||||
function delPref($sessid, $key)
|
||||
{
|
||||
$subjid = Alib::GetSessUserId($sessid);
|
||||
if (PEAR::isError($subjid)) {
|
||||
return $subjid;
|
||||
}
|
||||
if (is_null($subjid)) {
|
||||
return PEAR::raiseError("Prefs::delPref: invalid session id", GBERR_SESS);
|
||||
}
|
||||
$r = $this->delete($subjid, $key);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
if ($r === FALSE) {
|
||||
return PEAR::raiseError("Prefs::delPref: invalid preference key", GBERR_PREF);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* ---------------------------------------------------- group preferences */
|
||||
/**
|
||||
* Read group preference record
|
||||
*
|
||||
* @param string $group
|
||||
* group name
|
||||
* @param string $key
|
||||
* preference key
|
||||
* @param boolean $returnErrorIfKeyNotExists
|
||||
* If set to true and the key doesnt exist, return a PEAR error.
|
||||
* @return string
|
||||
* preference value
|
||||
*/
|
||||
function loadGroupPref($group, $key, $returnErrorIfKeyNotExists = true)
|
||||
{
|
||||
// if sessid is would be used here fix Transport::cronCallMethod !
|
||||
$subjid = Application_Model_Subjects::GetSubjId($group);
|
||||
if (PEAR::isError($subjid)) {
|
||||
return $subjid;
|
||||
}
|
||||
if (is_null($subjid)) {
|
||||
return PEAR::raiseError(
|
||||
"Prefs::loadGroupPref: invalid group name", ALIBERR_NOTGR);
|
||||
}
|
||||
$val = $this->readVal($subjid, $key);
|
||||
if (PEAR::isError($val)) {
|
||||
return $val;
|
||||
}
|
||||
if ($val === FALSE) {
|
||||
if ($returnErrorIfKeyNotExists) {
|
||||
return PEAR::raiseError(
|
||||
"Prefs::loadGroupPref: invalid preference key", GBERR_PREF);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save group preference record
|
||||
*
|
||||
* @param string $sessid
|
||||
* session id
|
||||
* @param string $group
|
||||
* group name
|
||||
* @param string $key
|
||||
* preference key
|
||||
* @param string $value
|
||||
* preference value
|
||||
* @return boolean
|
||||
*/
|
||||
function saveGroupPref($sessid, $group, $key, $value)
|
||||
{
|
||||
$uid = Alib::GetSessUserId($sessid);
|
||||
if (PEAR::isError($uid)) {
|
||||
return $uid;
|
||||
}
|
||||
if (is_null($uid)) {
|
||||
return PEAR::raiseError(
|
||||
"Prefs::saveGroupPref: invalid session id", GBERR_SESS);
|
||||
}
|
||||
$gid = Application_Model_Subjects::GetSubjId($group);
|
||||
if (PEAR::isError($gid)) {
|
||||
return $gid;
|
||||
}
|
||||
if (is_null($gid)) {
|
||||
return PEAR::raiseError(
|
||||
"Prefs::saveGroupPref: invalid group name", GBERR_SESS);
|
||||
}
|
||||
$memb = Application_Model_Subjects::IsMemberOf($uid, $gid);
|
||||
if (PEAR::isError($memb)) {
|
||||
return $memb;
|
||||
}
|
||||
if (!$memb) {
|
||||
return PEAR::raiseError(
|
||||
"Prefs::saveGroupPref: access denied", GBERR_DENY);
|
||||
}
|
||||
$r = $this->update($gid, $key, $value);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
if ($r === FALSE) {
|
||||
$r = $this->insert($gid, $key, $value);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete group preference record
|
||||
*
|
||||
* @param string $sessid
|
||||
* session id
|
||||
* @param string $group
|
||||
* group name
|
||||
* @param string $key
|
||||
* preference key
|
||||
* @return boolean
|
||||
*/
|
||||
function delGroupPref($sessid, $group, $key)
|
||||
{
|
||||
$uid = Alib::GetSessUserId($sessid);
|
||||
if (PEAR::isError($uid)) {
|
||||
return $uid;
|
||||
}
|
||||
if (is_null($uid)) {
|
||||
return PEAR::raiseError(
|
||||
"Prefs::delGroupPref: invalid session id", GBERR_SESS);
|
||||
}
|
||||
$gid = Application_Model_Subjects::GetSubjId($group);
|
||||
if (PEAR::isError($gid)) {
|
||||
return $gid;
|
||||
}
|
||||
if (is_null($gid)) {
|
||||
return PEAR::raiseError(
|
||||
"Prefs::delGroupPref: invalid group name", GBERR_SESS);
|
||||
}
|
||||
$memb = Application_Model_Subjects::IsMemberOf($uid, $gid);
|
||||
if (PEAR::isError($memb)) {
|
||||
return $memb;
|
||||
}
|
||||
if (!$memb) {
|
||||
return PEAR::raiseError(
|
||||
"Prefs::delGroupPref: access denied", GBERR_DENY);
|
||||
}
|
||||
$r = $this->delete($gid, $key);
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
if ($r === FALSE) {
|
||||
return PEAR::raiseError(
|
||||
"Prefs::delGroupPref: invalid preference key", GBERR_PREF);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* ==================================================== low level methods */
|
||||
/**
|
||||
* Insert of new preference record
|
||||
*
|
||||
* @param int $subjid
|
||||
* local user/group id
|
||||
* @param string $keystr
|
||||
* preference key
|
||||
* @param string $valstr
|
||||
* preference value
|
||||
* @return int
|
||||
* local user id
|
||||
*/
|
||||
public static function Insert($subjid, $keystr, $valstr='')
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$id = $CC_DBC->nextId($CC_CONFIG['prefSequence']);
|
||||
if (PEAR::isError($id)) {
|
||||
return $id;
|
||||
}
|
||||
$r = $CC_DBC->query("
|
||||
INSERT INTO ".$CC_CONFIG['prefTable']."
|
||||
(id, subjid, keystr, valstr)
|
||||
VALUES
|
||||
($id, $subjid, '$keystr', '$valstr')
|
||||
");
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read value of preference record
|
||||
*
|
||||
* @param int $subjid
|
||||
* local user/group id
|
||||
* @param string $keystr
|
||||
* preference key
|
||||
* @return string
|
||||
* preference value
|
||||
*/
|
||||
function readVal($subjid, $keystr)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$val = $CC_DBC->getOne("
|
||||
SELECT valstr FROM ".$CC_CONFIG['prefTable']."
|
||||
WHERE subjid=$subjid AND keystr='$keystr'
|
||||
");
|
||||
if (PEAR::isError($val)) {
|
||||
return $val;
|
||||
}
|
||||
if (is_null($val)) {
|
||||
return FALSE;
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read all keys of subject's preferences
|
||||
*
|
||||
* @param int $subjid
|
||||
* local user/group id
|
||||
* @return array
|
||||
* preference keys
|
||||
*/
|
||||
function readKeys($subjid)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$res = $CC_DBC->getAll("
|
||||
SELECT keystr FROM ".$CC_CONFIG['prefTable']."
|
||||
WHERE subjid=$subjid
|
||||
");
|
||||
if (PEAR::isError($res)) {
|
||||
return $res;
|
||||
}
|
||||
if (is_null($res)) {
|
||||
return FALSE;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update value of preference record
|
||||
*
|
||||
* @param int $subjid
|
||||
* local user/group id
|
||||
* @param string $keystr
|
||||
* preference key
|
||||
* @param string $newvalstr
|
||||
* new preference value
|
||||
* @return boolean
|
||||
*/
|
||||
function update($subjid, $keystr, $newvalstr='')
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$r = $CC_DBC->query("
|
||||
UPDATE ".$CC_CONFIG['prefTable']." SET
|
||||
valstr='$newvalstr'
|
||||
WHERE subjid=$subjid AND keystr='$keystr'
|
||||
");
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
if ($CC_DBC->affectedRows() < 1) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete preference record
|
||||
*
|
||||
* @param int $subjid
|
||||
* local user/group id
|
||||
* @param string $keystr
|
||||
* preference key
|
||||
* @return boolean
|
||||
*/
|
||||
function delete($subjid, $keystr)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$r = $CC_DBC->query("
|
||||
DELETE FROM ".$CC_CONFIG['prefTable']."
|
||||
WHERE subjid=$subjid AND keystr='$keystr'
|
||||
");
|
||||
if (PEAR::isError($r)) {
|
||||
return $r;
|
||||
}
|
||||
if ($CC_DBC->affectedRows() < 1) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
} // class Prefs
|
||||
|
|
@ -2,31 +2,6 @@
|
|||
|
||||
class Application_Model_Schedule {
|
||||
|
||||
/**
|
||||
* Return true if there is nothing in the schedule for the given start time
|
||||
* up to the length of time after that.
|
||||
*
|
||||
* @param string $p_datetime
|
||||
* In the format YYYY-MM-DD HH:MM:SS.mmmmmm
|
||||
* @param string $p_length
|
||||
* In the format HH:MM:SS.mmmmmm
|
||||
* @return boolean|PEAR_Error
|
||||
*/
|
||||
public static function isScheduleEmptyInRange($p_datetime, $p_length) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
if (empty($p_length)) {
|
||||
return new PEAR_Error("Application_Model_Schedule::isSchedulerEmptyInRange: param p_length is empty.");
|
||||
}
|
||||
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG["scheduleTable"]
|
||||
." WHERE (starts >= '$p_datetime') "
|
||||
." AND (ends <= (TIMESTAMP '$p_datetime' + INTERVAL '$p_length'))";
|
||||
//$_SESSION["debug"] = $sql;
|
||||
//echo $sql;
|
||||
$count = $CC_DBC->GetOne($sql);
|
||||
//var_dump($count);
|
||||
return ($count == '0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return TRUE if file is going to be played in the future.
|
||||
*
|
||||
|
@ -238,110 +213,6 @@ class Application_Model_Schedule {
|
|||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an SQL Query for accessing scheduled item information from
|
||||
* the database.
|
||||
*
|
||||
* @param int $timeNow
|
||||
* @param int $timePeriod
|
||||
* @param int $count
|
||||
* @param String $interval
|
||||
* @return date
|
||||
*
|
||||
* $timeNow is the the currentTime in the format "Y-m-d H:i:s".
|
||||
* For example: 2011-02-02 22:00:54
|
||||
*
|
||||
* $timePeriod can be either negative, zero or positive. This is used
|
||||
* to indicate whether we want items from the past, present or future.
|
||||
*
|
||||
* $count indicates how many results we want to limit ourselves to.
|
||||
*
|
||||
* $interval is used to indicate how far into the past or future we
|
||||
* want to search the database. For example "5 days", "18 hours", "60 minutes",
|
||||
* "30 seconds" etc.
|
||||
*/
|
||||
public static function GetScheduledItemData($timeStamp, $timePeriod=0, $count = 0, $interval="0 hours")
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT DISTINCT"
|
||||
." pt.name,"
|
||||
." ft.track_title,"
|
||||
." ft.artist_name,"
|
||||
." ft.album_title,"
|
||||
." st.starts,"
|
||||
." st.ends,"
|
||||
." st.clip_length,"
|
||||
." st.media_item_played,"
|
||||
." st.group_id,"
|
||||
." show.name as show_name,"
|
||||
." st.instance_id"
|
||||
." FROM $CC_CONFIG[scheduleTable] st"
|
||||
." LEFT JOIN $CC_CONFIG[filesTable] ft"
|
||||
." ON st.file_id = ft.id"
|
||||
." LEFT JOIN $CC_CONFIG[playListTable] pt"
|
||||
." ON st.playlist_id = pt.id"
|
||||
." LEFT JOIN $CC_CONFIG[showInstances] si"
|
||||
." ON st.instance_id = si.id"
|
||||
." LEFT JOIN $CC_CONFIG[showTable] show"
|
||||
." ON si.show_id = show.id"
|
||||
." WHERE st.starts < si.ends";
|
||||
|
||||
if ($timePeriod < 0){
|
||||
$sql .= " AND st.ends < TIMESTAMP '$timeStamp'"
|
||||
." AND st.ends > (TIMESTAMP '$timeStamp' - INTERVAL '$interval')"
|
||||
." ORDER BY st.starts DESC"
|
||||
." LIMIT $count";
|
||||
} else if ($timePeriod == 0){
|
||||
$sql .= " AND st.starts <= TIMESTAMP '$timeStamp'"
|
||||
." AND st.ends >= TIMESTAMP '$timeStamp'";
|
||||
} else if ($timePeriod > 0){
|
||||
$sql .= " AND st.starts > TIMESTAMP '$timeStamp'"
|
||||
." AND st.starts < (TIMESTAMP '$timeStamp' + INTERVAL '$interval')"
|
||||
." ORDER BY st.starts"
|
||||
." LIMIT $count";
|
||||
}
|
||||
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
|
||||
public static function getScheduleItemsInRange($starts, $ends)
|
||||
{
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
|
||||
$sql = "SELECT"
|
||||
." si.starts as show_starts,"
|
||||
." si.ends as show_ends,"
|
||||
." si.rebroadcast as rebroadcast,"
|
||||
." 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 '$starts' AND si.ends > TIMESTAMP '$starts')"
|
||||
." OR (si.starts > TIMESTAMP '$starts' AND si.ends < TIMESTAMP '$ends')"
|
||||
." OR (si.starts < TIMESTAMP '$ends' AND si.ends > TIMESTAMP '$ends'))"
|
||||
." AND (st.starts < si.ends)"
|
||||
." ORDER BY si.id, si.starts, st.starts";
|
||||
|
||||
return $CC_DBC->GetAll($sql);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* @param DateTime $p_startDateTime
|
||||
|
@ -390,25 +261,6 @@ class Application_Model_Schedule {
|
|||
|
||||
$sql .= " ORDER BY si.starts, sched.starts;";
|
||||
|
||||
Logging::log($sql);
|
||||
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function GetShowInstanceItems($instance_id)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT DISTINCT pt.name, ft.track_title, ft.artist_name, ft.album_title, st.starts, st.ends, st.clip_length, st.media_item_played, st.group_id, show.name as show_name, st.instance_id"
|
||||
." FROM $CC_CONFIG[scheduleTable] st, $CC_CONFIG[filesTable] ft, $CC_CONFIG[playListTable] pt, $CC_CONFIG[showInstances] si, $CC_CONFIG[showTable] show"
|
||||
." 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 instance_id = $instance_id"
|
||||
." ORDER BY st.starts";
|
||||
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
return $rows;
|
||||
}
|
||||
|
|
|
@ -1,216 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Application_Model_ScheduleGroup {
|
||||
|
||||
private $groupId;
|
||||
|
||||
public function __construct($p_groupId = null) {
|
||||
$this->groupId = $p_groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the schedule group exists in the DB.
|
||||
* @return boolean
|
||||
*/
|
||||
public function exists() {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT COUNT(*) FROM ".$CC_CONFIG['scheduleTable']
|
||||
." WHERE group_id=".$this->groupId;
|
||||
$result = $CC_DBC->GetOne($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
return $result;
|
||||
}
|
||||
return $result != "0";
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a music clip or playlist to the schedule.
|
||||
*
|
||||
* @param int $p_showInstance
|
||||
* ID of the show.
|
||||
* @param $p_datetime
|
||||
* In the format YYYY-MM-DD HH:MM:SS.mmmmmm
|
||||
* @param $p_audioFileId
|
||||
* (optional, either this or $p_playlistId must be set) DB ID of the audio file
|
||||
* @param $p_playlistId
|
||||
* (optional, either this of $p_audioFileId must be set) DB ID of the playlist
|
||||
* @param $p_options
|
||||
* Does nothing at the moment.
|
||||
*
|
||||
* @return int|PEAR_Error
|
||||
* Return PEAR_Error if the item could not be added.
|
||||
* Error code 555 is a scheduling conflict.
|
||||
*/
|
||||
public function add($p_showInstance, $p_datetime, $p_audioFileId = null, $p_playlistId = null, $p_options = null) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
if (!is_null($p_audioFileId)) {
|
||||
// Schedule a single audio track
|
||||
|
||||
// Load existing track
|
||||
$track = Application_Model_StoredFile::Recall($p_audioFileId);
|
||||
if (is_null($track)) {
|
||||
return new PEAR_Error("Could not find audio track.");
|
||||
}
|
||||
|
||||
// Check if there are any conflicts with existing entries
|
||||
$metadata = $track->getMetadata();
|
||||
$length = $metadata['MDATA_KEY_DURATION'];
|
||||
if (empty($length)) {
|
||||
return new PEAR_Error("Length is empty.");
|
||||
}
|
||||
// Insert into the table
|
||||
$this->groupId = $CC_DBC->GetOne("SELECT nextval('schedule_group_id_seq')");
|
||||
|
||||
$sql = "INSERT INTO ".$CC_CONFIG["scheduleTable"]
|
||||
." (instance_id, starts, ends, clip_length, group_id, file_id, cue_out)"
|
||||
." VALUES ($p_showInstance, TIMESTAMP '$p_datetime', "
|
||||
." (TIMESTAMP '$p_datetime' + INTERVAL '$length'),"
|
||||
." '$length',"
|
||||
." {$this->groupId}, $p_audioFileId, '$length')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
//var_dump($sql);
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
elseif (!is_null($p_playlistId)){
|
||||
// Schedule a whole playlist
|
||||
|
||||
// Load existing playlist
|
||||
$playlist = Application_Model_Playlist::Recall($p_playlistId);
|
||||
if (is_null($playlist)) {
|
||||
return new PEAR_Error("Could not find playlist.");
|
||||
}
|
||||
|
||||
// Check if there are any conflicts with existing entries
|
||||
$length = trim($playlist->getLength());
|
||||
//var_dump($length);
|
||||
if (empty($length)) {
|
||||
return new PEAR_Error("Length is empty.");
|
||||
}
|
||||
|
||||
// Insert all items into the schedule
|
||||
$this->groupId = $CC_DBC->GetOne("SELECT nextval('schedule_group_id_seq')");
|
||||
$itemStartTime = $p_datetime;
|
||||
|
||||
$plItems = $playlist->getContents();
|
||||
//var_dump($plItems);
|
||||
foreach ($plItems as $row) {
|
||||
$trackLength = $row["cliplength"];
|
||||
//var_dump($trackLength);
|
||||
$sql = "INSERT INTO ".$CC_CONFIG["scheduleTable"]
|
||||
." (instance_id, playlist_id, starts, ends, group_id, file_id,"
|
||||
." clip_length, cue_in, cue_out, fade_in, fade_out)"
|
||||
." VALUES ($p_showInstance, $p_playlistId, TIMESTAMP '$itemStartTime', "
|
||||
." (TIMESTAMP '$itemStartTime' + INTERVAL '$trackLength'),"
|
||||
." '{$this->groupId}', '{$row['file_id']}', '$trackLength', '{$row['cuein']}',"
|
||||
." '{$row['cueout']}', '{$row['fadein']}','{$row['fadeout']}')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
//var_dump($sql);
|
||||
return $result;
|
||||
}
|
||||
$itemStartTime = $CC_DBC->getOne("SELECT TIMESTAMP '$itemStartTime' + INTERVAL '$trackLength'");
|
||||
}
|
||||
}
|
||||
|
||||
Application_Model_RabbitMq::PushSchedule();
|
||||
return $this->groupId;
|
||||
}
|
||||
|
||||
public function addFileAfter($show_instance, $p_groupId, $p_audioFileId) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
// Get the end time for the given entry
|
||||
$sql = "SELECT MAX(ends) FROM ".$CC_CONFIG["scheduleTable"]
|
||||
." WHERE group_id=$p_groupId";
|
||||
$startTime = $CC_DBC->GetOne($sql);
|
||||
return $this->add($show_instance, $startTime, $p_audioFileId);
|
||||
}
|
||||
|
||||
public function addPlaylistAfter($show_instance, $p_groupId, $p_playlistId) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
// Get the end time for the given entry
|
||||
$sql = "SELECT MAX(ends) FROM ".$CC_CONFIG["scheduleTable"]
|
||||
." WHERE group_id=$p_groupId";
|
||||
|
||||
$startTime = $CC_DBC->GetOne($sql);
|
||||
return $this->add($show_instance, $startTime, null, $p_playlistId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the group from the schedule.
|
||||
* Note: does not check if it is in the past, you can remove anything.
|
||||
*
|
||||
* @return boolean
|
||||
* TRUE on success, false if there is no group ID defined.
|
||||
*/
|
||||
public function remove() {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
if (is_null($this->groupId) || !is_numeric($this->groupId)) {
|
||||
return false;
|
||||
}
|
||||
$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"]
|
||||
." WHERE group_id = ".$this->groupId;
|
||||
//echo $sql;
|
||||
$retVal = $CC_DBC->query($sql);
|
||||
Application_Model_RabbitMq::PushSchedule();
|
||||
return $retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of items in this group.
|
||||
* @return string
|
||||
*/
|
||||
public function count() {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT COUNT(*) FROM {$CC_CONFIG['scheduleTable']}"
|
||||
." WHERE group_id={$this->groupId}";
|
||||
return $CC_DBC->GetOne($sql);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the list of items in this group as a 2D array.
|
||||
* @return array
|
||||
*/
|
||||
public function getItems() {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "SELECT "
|
||||
." st.id,"
|
||||
." st.file_id,"
|
||||
." st.cue_in,"
|
||||
." st.cue_out,"
|
||||
." st.clip_length,"
|
||||
." st.fade_in,"
|
||||
." st.fade_out,"
|
||||
." st.starts,"
|
||||
." st.ends"
|
||||
." FROM $CC_CONFIG[scheduleTable] as st"
|
||||
." LEFT JOIN $CC_CONFIG[showInstances] as si"
|
||||
." ON st.instance_id = si.id"
|
||||
." WHERE st.group_id=$this->groupId"
|
||||
." AND st.starts < si.ends"
|
||||
." ORDER BY st.starts";
|
||||
return $CC_DBC->GetAll($sql);
|
||||
}
|
||||
|
||||
public function notifyGroupStartPlay() {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "UPDATE ".$CC_CONFIG['scheduleTable']
|
||||
." SET schedule_group_played=TRUE"
|
||||
." WHERE group_id=".$this->groupId;
|
||||
$retVal = $CC_DBC->query($sql);
|
||||
return $retVal;
|
||||
}
|
||||
|
||||
public function notifyMediaItemStartPlay($p_fileId) {
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
$sql = "UPDATE ".$CC_CONFIG['scheduleTable']
|
||||
." SET media_item_played=TRUE"
|
||||
." WHERE group_id=".$this->groupId
|
||||
." AND file_id=".pg_escape_string($p_fileId);
|
||||
$retVal = $CC_DBC->query($sql);
|
||||
return $retVal;
|
||||
}
|
||||
}
|
|
@ -13,13 +13,17 @@ class Application_Model_Scheduler {
|
|||
"sched_id" => null,
|
||||
);
|
||||
|
||||
private $epochNow;
|
||||
private $nowDT;
|
||||
private $user;
|
||||
|
||||
public function __construct($id = null) {
|
||||
|
||||
$this->con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
|
||||
$this->nowDT = new DateTime("now", new DateTimeZone("UTC"));
|
||||
|
||||
$this->epochNow = floatval(microtime(true));
|
||||
$this->nowDT = DateTime::createFromFormat("U.u", $this->epochNow, new DateTimeZone("UTC"));
|
||||
|
||||
$this->user = Application_Model_User::GetCurrentUser();
|
||||
}
|
||||
|
||||
|
@ -30,7 +34,7 @@ class Application_Model_Scheduler {
|
|||
*/
|
||||
private function validateRequest($items) {
|
||||
|
||||
$nowEpoch = intval($this->nowDT->format("U"));
|
||||
$nowEpoch = floatval($this->nowDT->format("U.u"));
|
||||
|
||||
for ($i = 0; $i < count($items); $i++) {
|
||||
$id = $items[$i]["id"];
|
||||
|
@ -83,7 +87,7 @@ class Application_Model_Scheduler {
|
|||
throw new Exception("You are not allowed to schedule show {$show->getDbName()}.");
|
||||
}
|
||||
|
||||
$showEndEpoch = intval($instance->getDbEnds("U"));
|
||||
$showEndEpoch = floatval($instance->getDbEnds("U.u"));
|
||||
|
||||
if ($showEndEpoch < $nowEpoch) {
|
||||
throw new OutDatedScheduleException("The show {$show->getDbName()} is over and cannot be scheduled.");
|
||||
|
@ -169,7 +173,7 @@ class Application_Model_Scheduler {
|
|||
*
|
||||
* @return DateTime endDT in UTC
|
||||
*/
|
||||
private static function findEndTime($p_startDT, $p_duration) {
|
||||
private function findEndTime($p_startDT, $p_duration) {
|
||||
|
||||
$startEpoch = $p_startDT->format("U.u");
|
||||
$durationSeconds = Application_Model_Playlist::playlistTimeToSeconds($p_duration);
|
||||
|
@ -178,22 +182,14 @@ class Application_Model_Scheduler {
|
|||
//DateTime::createFromFormat("U.u") will have a problem if there is no decimal in the resulting number.
|
||||
$endEpoch = bcadd($startEpoch , (string) $durationSeconds, 6);
|
||||
|
||||
Logging::log("start DateTime created {$p_startDT->format("Y-m-d H:i:s.u")}");
|
||||
Logging::log("start epoch is {$startEpoch}");
|
||||
Logging::log("duration in seconds is {$durationSeconds}");
|
||||
Logging::log("end epoch is {$endEpoch}");
|
||||
|
||||
$dt = DateTime::createFromFormat("U.u", $endEpoch, new DateTimeZone("UTC"));
|
||||
|
||||
Logging::log("end DateTime created {$dt->format("Y-m-d H:i:s.u")}");
|
||||
|
||||
return $dt;
|
||||
}
|
||||
|
||||
private function findNextStartTime($DT, $instance) {
|
||||
|
||||
$sEpoch = intval($DT->format("U"));
|
||||
$nowEpoch = intval($this->nowDT->format("U"));
|
||||
$sEpoch = floatval($DT->format("U.u"));
|
||||
$nowEpoch = $this->epochNow;
|
||||
|
||||
//check for if the show has started.
|
||||
if ($nowEpoch > $sEpoch) {
|
||||
|
@ -273,7 +269,7 @@ class Application_Model_Scheduler {
|
|||
|
||||
foreach($schedFiles as $file) {
|
||||
|
||||
$endTimeDT = self::findEndTime($nextStartDT, $file['cliplength']);
|
||||
$endTimeDT = $this->findEndTime($nextStartDT, $file['cliplength']);
|
||||
|
||||
//item existed previously and is being moved.
|
||||
//need to keep same id for resources if we want REST.
|
||||
|
@ -303,7 +299,7 @@ class Application_Model_Scheduler {
|
|||
//recalculate the start/end times after the inserted items.
|
||||
foreach ($followingSchedItems as $item) {
|
||||
|
||||
$endTimeDT = self::findEndTime($nextStartDT, $item->getDbClipLength());
|
||||
$endTimeDT = $this->findEndTime($nextStartDT, $item->getDbClipLength());
|
||||
|
||||
$item->setDbStarts($nextStartDT);
|
||||
$item->setDbEnds($endTimeDT);
|
||||
|
@ -448,17 +444,26 @@ class Application_Model_Scheduler {
|
|||
$instance = $removedItem->getCcShowInstances($this->con);
|
||||
|
||||
//check to truncate the currently playing item instead of deleting it.
|
||||
if ($removedItem->isCurrentItem()) {
|
||||
$now = new DateTime("now", new DateTimeZone("UTC"));
|
||||
if ($removedItem->isCurrentItem($this->epochNow)) {
|
||||
|
||||
$nEpoch = floatval($now->format('U.u'));
|
||||
$nEpoch = $this->epochNow;
|
||||
$sEpoch = floatval($removedItem->getDbStarts('U.u'));
|
||||
$length = $nEpoch - $sEpoch;
|
||||
$cliplength = Application_Model_Playlist::secondsToPlaylistTime($length);
|
||||
|
||||
$removedItem->setDbClipLength($cliplength);
|
||||
$removedItem->setDbEnds($now);
|
||||
$removedItem->save($this->con);
|
||||
$cueinSec = Application_Model_Playlist::playlistTimeToSeconds($removedItem->getDbCueIn());
|
||||
$cueOutSec = $cueinSec + $length;
|
||||
$cueout = Application_Model_Playlist::secondsToPlaylistTime($length);
|
||||
|
||||
Logging::log('$nEpoch: '. $nEpoch);
|
||||
Logging::log('$sEpoch: '. $sEpoch);
|
||||
Logging::log('$length: '. $length);
|
||||
Logging::log('$cliplength: '. $cliplength);
|
||||
|
||||
$removedItem->setDbCueOut($cueout)
|
||||
->setDbClipLength($cliplength)
|
||||
->setDbEnds($now)
|
||||
->save($this->con);
|
||||
}
|
||||
else {
|
||||
$removedItem->delete($this->con);
|
||||
|
@ -529,9 +534,7 @@ class Application_Model_Scheduler {
|
|||
|
||||
foreach ($schedule as $item) {
|
||||
|
||||
Logging::log("adjusting item #".$item->getDbId());
|
||||
|
||||
$itemEndDT = self::findEndTime($itemStartDT, $item->getDbClipLength());
|
||||
$itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength());
|
||||
|
||||
$item->setDbStarts($itemStartDT);
|
||||
$item->setDbEnds($itemEndDT);
|
||||
|
|
|
@ -346,18 +346,6 @@ class Application_Model_ShowInstance {
|
|||
Application_Model_RabbitMq::PushSchedule();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the group ID for this show.
|
||||
*
|
||||
*/
|
||||
private function getLastGroupId()
|
||||
{
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT group_id FROM cc_schedule WHERE instance_id = '{$this->_instanceId}' ORDER BY ends DESC LIMIT 1";
|
||||
$res = $CC_DBC->GetOne($sql);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a playlist as the last item of the current show.
|
||||
*
|
||||
|
@ -406,29 +394,6 @@ class Application_Model_ShowInstance {
|
|||
}
|
||||
}
|
||||
|
||||
public function removeGroupFromShow($group_id)
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
$sql = "SELECT MAX(ends) as end_timestamp, (MAX(ends) - MIN(starts)) as length
|
||||
FROM cc_schedule
|
||||
WHERE group_id = '{$group_id}'";
|
||||
|
||||
$groupBoundry = $CC_DBC->GetRow($sql);
|
||||
|
||||
$group = CcScheduleQuery::create()
|
||||
->filterByDbGroupId($group_id)
|
||||
->delete();
|
||||
|
||||
$sql = "UPDATE cc_schedule
|
||||
SET starts = (starts - INTERVAL '{$groupBoundry["length"]}'), ends = (ends - INTERVAL '{$groupBoundry["length"]}')
|
||||
WHERE starts >= '{$groupBoundry["end_timestamp"]}' AND instance_id = {$this->_instanceId}";
|
||||
|
||||
$CC_DBC->query($sql);
|
||||
Application_Model_RabbitMq::PushSchedule();
|
||||
$this->updateScheduledTime();
|
||||
}
|
||||
|
||||
public function clearShow()
|
||||
{
|
||||
CcScheduleQuery::create()
|
||||
|
@ -646,11 +611,6 @@ class Application_Model_ShowInstance {
|
|||
return $interval->format("%h:%I:%S");
|
||||
}
|
||||
|
||||
public function searchPlaylistsForShow($datatables)
|
||||
{
|
||||
return Application_Model_StoredFile::searchPlaylistsForSchedule($datatables);
|
||||
}
|
||||
|
||||
public function getShowListContent()
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
@ -677,64 +637,6 @@ class Application_Model_ShowInstance {
|
|||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public static function GetShowsInstancesIdsInRange($p_start, $p_end)
|
||||
{
|
||||
global $CC_DBC;
|
||||
|
||||
$sql = "SELECT id FROM cc_show_instances AS si "
|
||||
."WHERE modified_instance != TRUE AND ("
|
||||
."(si.starts < TIMESTAMP '$p_start'"
|
||||
."AND si.ends > TIMESTAMP '$p_start') "
|
||||
."OR (si.starts > TIMESTAMP '$p_start' "
|
||||
."AND si.ends < TIMESTAMP '$p_end') "
|
||||
."OR (si.starts < TIMESTAMP '$p_end' "
|
||||
."AND si.ends > TIMESTAMP '$p_end') "
|
||||
.") "
|
||||
." ORDER BY si.starts";
|
||||
|
||||
Logging::debug($sql);
|
||||
|
||||
$rows = $CC_DBC->GetAll($sql);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function getScheduleItemsInRange($timeNow, $start, $end)
|
||||
{
|
||||
global $CC_DBC, $CC_CONFIG;
|
||||
|
||||
$instanceId = $this->_instanceId;
|
||||
|
||||
$sql = "SELECT"
|
||||
." si.starts as show_starts,"
|
||||
." si.ends as show_ends,"
|
||||
." si.rebroadcast as rebroadcast,"
|
||||
." 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"
|
||||
." FROM {$CC_CONFIG['showInstances']} si"
|
||||
." LEFT JOIN {$CC_CONFIG['scheduleTable']} st"
|
||||
." ON st.instance_id = si.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'))"
|
||||
." AND (st.starts < si.ends)"
|
||||
." AND si.id = $instanceId"
|
||||
." ORDER BY si.starts, st.starts";
|
||||
|
||||
Logging::log($sql);
|
||||
|
||||
return $CC_DBC->GetAll($sql);
|
||||
}
|
||||
|
||||
public function getLastAudioItemEnd(){
|
||||
global $CC_DBC;
|
||||
|
|
|
@ -1,398 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
*/
|
||||
require_once "XML/Util.php";
|
||||
|
||||
/* ================================================================== Element */
|
||||
|
||||
/**
|
||||
* Object representation of one XML element
|
||||
*
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
* @see MetaData
|
||||
*/
|
||||
class XmlElement {
|
||||
/**
|
||||
* Namespace prefix
|
||||
* @var string
|
||||
*/
|
||||
public $ns;
|
||||
|
||||
/**
|
||||
* Element name
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Attributes
|
||||
* @var array
|
||||
*/
|
||||
public $attrs = array();
|
||||
|
||||
/**
|
||||
* Namespace definitions
|
||||
* @var array
|
||||
*/
|
||||
public $nSpaces = array();
|
||||
|
||||
/**
|
||||
* Child nodes
|
||||
* @var array
|
||||
*/
|
||||
public $children = array();
|
||||
|
||||
/**
|
||||
* Text content of element
|
||||
* @var string
|
||||
*/
|
||||
public $content = '';
|
||||
|
||||
|
||||
/**
|
||||
* @param string $fullname
|
||||
* Fully qualified name of element
|
||||
* @param array $attrs
|
||||
* hash of attributes
|
||||
* @param array $nSpaces
|
||||
* hash of namespace definitions
|
||||
* @param array $children
|
||||
* hash of child nodes
|
||||
*/
|
||||
public function __construct($fullname, $attrs, $nSpaces=array(), $children=array())
|
||||
{
|
||||
$a = XML_Util::splitQualifiedName($fullname);
|
||||
$this->ns = $a['namespace'];
|
||||
$this->name = $a['localPart'];
|
||||
$this->attrs = $attrs;
|
||||
$this->nSpaces = $nSpaces;
|
||||
$this->children = $children;
|
||||
}
|
||||
} // class XmlElement
|
||||
|
||||
|
||||
/* ================================================================ Attribute */
|
||||
/**
|
||||
* Object representation of one XML attribute
|
||||
*
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
* @see MetaData
|
||||
*/
|
||||
class XmlAttrib {
|
||||
/**
|
||||
* Namespace prefix
|
||||
* @var string
|
||||
*/
|
||||
public $ns;
|
||||
|
||||
/**
|
||||
* Attribute name
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Attribute value
|
||||
* @var string
|
||||
*/
|
||||
public $val;
|
||||
|
||||
/**
|
||||
* @param string $atns
|
||||
* namespace prefix
|
||||
* @param string $atnm
|
||||
* attribute name
|
||||
* @param string $atv
|
||||
* attribute value
|
||||
*/
|
||||
public function __construct($atns, $atnm, $atv)
|
||||
{
|
||||
$this->ns = $atns;
|
||||
$this->name = $atnm;
|
||||
$this->val = $atv;
|
||||
}
|
||||
} // fn XmlAttrib
|
||||
|
||||
|
||||
/* =================================================================== Parser */
|
||||
/**
|
||||
* XML parser object encapsulation
|
||||
*
|
||||
* @package Airtime
|
||||
* @subpackage StorageServer
|
||||
* @copyright 2010 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
* @see MetaData
|
||||
*/
|
||||
class XmlParser {
|
||||
/**
|
||||
* Tree of nodes
|
||||
* @var array
|
||||
*/
|
||||
private $tree = NULL;
|
||||
|
||||
/**
|
||||
* Parse stack
|
||||
* @var array
|
||||
*/
|
||||
private $stack = array();
|
||||
|
||||
/**
|
||||
* Error structure
|
||||
* @var array
|
||||
*/
|
||||
private $err = array(FALSE, '');
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* XML string to be parsed
|
||||
*/
|
||||
public function __construct($data){
|
||||
$xml_parser = xml_parser_create('UTF-8');
|
||||
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, FALSE);
|
||||
xml_set_object($xml_parser, $this);
|
||||
xml_set_element_handler($xml_parser, "startTag", "endTag");
|
||||
xml_set_character_data_handler($xml_parser, 'characterData');
|
||||
$res = xml_parse($xml_parser, $data, TRUE);
|
||||
if (!$res) {
|
||||
$this->err = array(TRUE,
|
||||
sprintf("XML error: %s at line %d\n",
|
||||
xml_error_string(xml_get_error_code($xml_parser)),
|
||||
xml_get_current_line_number($xml_parser)
|
||||
)
|
||||
);
|
||||
// var_dump($data);
|
||||
}
|
||||
xml_parser_free($xml_parser);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse XML file or string
|
||||
*
|
||||
* @param string $data
|
||||
* local path to XML file or XML string
|
||||
* @param string $loc
|
||||
* location: 'file'|'string'
|
||||
* @return array
|
||||
* reference, parse result tree (or PEAR::error)
|
||||
*/
|
||||
function &parse($data='', $loc='file')
|
||||
{
|
||||
switch ($loc) {
|
||||
case "file":
|
||||
if (!is_file($data)) {
|
||||
return PEAR::raiseError(
|
||||
"XmlParser::parse: file not found ($data)"
|
||||
);
|
||||
}
|
||||
if (!is_readable($data)) {
|
||||
return PEAR::raiseError(
|
||||
"XmlParser::parse: can't read file ($data)"
|
||||
);
|
||||
}
|
||||
$data = file_get_contents($data);
|
||||
case "string":
|
||||
$parser = new XmlParser($data);
|
||||
if ($parser->isError()) {
|
||||
return PEAR::raiseError(
|
||||
"XmlParser::parse: ".$parser->getError()
|
||||
);
|
||||
}
|
||||
$tree = $parser->getTree();
|
||||
break;
|
||||
default:
|
||||
return PEAR::raiseError(
|
||||
"XmlParser::parse: unsupported source location ($loc)"
|
||||
);
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start tag handler
|
||||
*
|
||||
* @param resource $parser
|
||||
* reference to parser resource
|
||||
* @param string $fullname
|
||||
* element name
|
||||
* @param array $attrs
|
||||
* array of attributes
|
||||
* @return none
|
||||
*/
|
||||
function startTag($parser, $fullname, $attrs) {
|
||||
$nSpaces = array();
|
||||
foreach ($attrs as $atn => $atv) {
|
||||
$a = XML_Util::splitQualifiedName($atn);
|
||||
$atns = $a['namespace'];
|
||||
$atnm = $a['localPart'];
|
||||
unset($attrs[$atn]);
|
||||
if ($atns == 'xmlns') {
|
||||
$nSpaces[$atnm] = $atv;
|
||||
} else if ($atns == NULL && $atnm == 'xmlns') {
|
||||
$nSpaces[''] = $atv;
|
||||
} else {
|
||||
$attrs[$atn] = new XmlAttrib($atns, $atnm, $atv);
|
||||
}
|
||||
}
|
||||
$el = new XmlElement($fullname, $attrs, $nSpaces);
|
||||
array_push($this->stack, $el);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* End tag handler
|
||||
*
|
||||
* @param resource $parser
|
||||
* reference to parser resource
|
||||
* @param string $fullname
|
||||
* element name
|
||||
* @return none
|
||||
*/
|
||||
function endTag($parser, $fullname) {
|
||||
$cnt = count($this->stack);
|
||||
if ($cnt > 1) {
|
||||
$this->stack[$cnt-2]->children[] = $this->stack[$cnt-1];
|
||||
$lastEl = array_pop($this->stack);
|
||||
} else {
|
||||
$this->tree = $this->stack[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Character data handler
|
||||
*
|
||||
* @param resource $parser
|
||||
* reference to parser resource
|
||||
* @param string $data
|
||||
* @return none
|
||||
*/
|
||||
function characterData($parser, $data) {
|
||||
$cnt = count($this->stack);
|
||||
if (trim($data)!='') {
|
||||
$this->stack[$cnt-1]->content .= $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default handler
|
||||
*
|
||||
* @param resource $parser
|
||||
* reference to parser resource
|
||||
* @param string $data
|
||||
* @return none
|
||||
*/
|
||||
function defaultHandler($parser, $data)
|
||||
{
|
||||
$cnt = count($this->stack);
|
||||
//if(substr($data, 0, 1) == "&" && substr($data, -1, 1) == ";"){
|
||||
// $this->stack[$cnt-1]->content .= trim($data);
|
||||
//}else{
|
||||
$this->stack[$cnt-1]->content .= "*** $data ***";
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return result tree
|
||||
*
|
||||
* @return array
|
||||
* tree structure
|
||||
*/
|
||||
function getTree()
|
||||
{
|
||||
return $this->tree;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return error string
|
||||
*
|
||||
* @return boolean
|
||||
* whether error occured
|
||||
*/
|
||||
function isError()
|
||||
{
|
||||
return $this->err[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return error string
|
||||
*
|
||||
* @return string
|
||||
* error message
|
||||
*/
|
||||
function getError()
|
||||
{
|
||||
return $this->err[1];
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------- auxiliary methos for serialization */
|
||||
/**
|
||||
* Serialize metadata of one file
|
||||
*
|
||||
* @return string, serialized XML
|
||||
*/
|
||||
function serialize()
|
||||
{
|
||||
$res = '<?xml version="1.0" encoding="utf-8"?>';
|
||||
$res .= $this->serializeEl($this->tree);
|
||||
$res .= "\n";
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serialize one metadata element
|
||||
*
|
||||
* @param el object, element object
|
||||
* @param lvl int, level for indentation
|
||||
* @return string, serialized XML
|
||||
*/
|
||||
function serializeEl($el, $lvl=0)
|
||||
{
|
||||
$ind = str_repeat(" ", $lvl);
|
||||
$elNs = $el->ns;
|
||||
$elName = $el->name;
|
||||
$attrs = XML_Util::attributesToString($el->attrs);
|
||||
$fullName = ($elNs=='' ? '' : "$elNs:")."$elName";
|
||||
$res = "\n{$ind}<{$fullName}{$attrs}>";
|
||||
$haveCh = (count($el->children)>0);
|
||||
foreach ($el->children as $ch) {
|
||||
$res .= $this->serializeEl($ch, $lvl+1);
|
||||
}
|
||||
$res .= XML_Util::replaceEntities("{$el->content}");
|
||||
if ($haveCh) {
|
||||
$res .= "\n{$ind}";
|
||||
}
|
||||
$res .= "</{$fullName}>";
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------- debug methods */
|
||||
/**
|
||||
* Debug dump of tree
|
||||
*
|
||||
* @return hash, tree structure
|
||||
*/
|
||||
function dump()
|
||||
{
|
||||
var_dump($this->tree);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -224,11 +224,14 @@ class CcSchedule extends BaseCcSchedule {
|
|||
return $this;
|
||||
} // setDbEnds()
|
||||
|
||||
public function isCurrentItem() {
|
||||
public function isCurrentItem($epochNow = null) {
|
||||
|
||||
$epochNow = time();
|
||||
$epochStart = intval($this->getDbStarts('U'));
|
||||
$epochEnd = intval($this->getDbEnds('U'));
|
||||
if (is_null($epochNow)) {
|
||||
$epochNow = microtime(true);
|
||||
}
|
||||
|
||||
$epochStart = floatval($this->getDbStarts('U.u'));
|
||||
$epochEnd = floatval($this->getDbEnds('U.u'));
|
||||
|
||||
if ($epochStart < $epochNow && $epochEnd > $epochNow) {
|
||||
return true;
|
||||
|
|
|
@ -1,136 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE options [
|
||||
<!ELEMENT options (option*) >
|
||||
<!ELEMENT option (label+) >
|
||||
<!ELEMENT label (#PCDATA) >
|
||||
<!ATTLIST option id CDATA #REQUIRED >
|
||||
<!ATTLIST label xml:lang CDATA #IMPLIED >
|
||||
]>
|
||||
<options>
|
||||
<option id="Blues"><label>Blues</label></option>
|
||||
<option id="Classic Rock"><label>Classic Rock</label></option>
|
||||
<option id="Country"><label>Country</label></option>
|
||||
<option id="Dance"><label>Dance</label></option>
|
||||
<option id="Disco"><label>Disco</label></option>
|
||||
<option id="Funk"><label>Funk</label></option>
|
||||
<option id="Grunge"><label>Grunge</label></option>
|
||||
<option id="Hip-Hop"><label>Hip-Hop</label></option>
|
||||
<option id="Jazz"><label>Jazz</label></option>
|
||||
<option id="Metal"><label>Metal</label></option>
|
||||
<option id="New Age"><label>New Age</label></option>
|
||||
<option id="Oldies"><label>Oldies</label></option>
|
||||
<option id="Other"><label>Other</label></option>
|
||||
<option id="Pop"><label>Pop</label></option>
|
||||
<option id="R&B"><label>R&B</label></option>
|
||||
<option id="Rap"><label>Rap</label></option>
|
||||
<option id="Reggae"><label>Reggae</label></option>
|
||||
<option id="Rock"><label>Rock</label></option>
|
||||
<option id="Techno"><label>Techno</label></option>
|
||||
<option id="Industrial"><label>Industrial</label></option>
|
||||
<option id="Alternative"><label>Alternative</label></option>
|
||||
<option id="Ska"><label>Ska</label></option>
|
||||
<option id="Death Metal"><label>Death Metal</label></option>
|
||||
<option id="Pranks"><label>Pranks</label></option>
|
||||
<option id="Soundtrack"><label>Soundtrack</label></option>
|
||||
<option id="Euro-Techno"><label>Euro-Techno</label></option>
|
||||
<option id="Ambient"><label>Ambient</label></option>
|
||||
<option id="Trip-Hop"><label>Trip-Hop</label></option>
|
||||
<option id="Vocal"><label>Vocal</label></option>
|
||||
<option id="Jazz+Funk"><label>Jazz+Funk</label></option>
|
||||
<option id="Fusion"><label>Fusion</label></option>
|
||||
<option id="Trance"><label>Trance</label></option>
|
||||
<option id="Classical"><label>Classical</label></option>
|
||||
<option id="Instrumental"><label>Instrumental</label></option>
|
||||
<option id="Acid"><label>Acid</label></option>
|
||||
<option id="House"><label>House</label></option>
|
||||
<option id="Game"><label>Game</label></option>
|
||||
<option id="Sound Clip"><label>Sound Clip</label></option>
|
||||
<option id="Gospel"><label>Gospel</label></option>
|
||||
<option id="Noise"><label>Noise</label></option>
|
||||
<option id="AlternRock"><label>AlternRock</label></option>
|
||||
<option id="Bass"><label>Bass</label></option>
|
||||
<option id="Soul"><label>Soul</label></option>
|
||||
<option id="Punk"><label>Punk</label></option>
|
||||
<option id="Space"><label>Space</label></option>
|
||||
<option id="Meditative"><label>Meditative</label></option>
|
||||
<option id="Instrumental Pop"><label>Instrumental Pop</label></option>
|
||||
<option id="Instrumental Rock"><label>Instrumental Rock</label></option>
|
||||
<option id="Ethnic"><label>Ethnic</label></option>
|
||||
<option id="Gothic"><label>Gothic</label></option>
|
||||
<option id="Darkwave"><label>Darkwave</label></option>
|
||||
<option id="Techno-Industrial"><label>Techno-Industrial</label></option>
|
||||
<option id="Electronic"><label>Electronic</label></option>
|
||||
<option id="Pop-Folk"><label>Pop-Folk</label></option>
|
||||
<option id="Eurodance"><label>Eurodance</label></option>
|
||||
<option id="Dream"><label>Dream</label></option>
|
||||
<option id="Southern Rock"><label>Southern Rock</label></option>
|
||||
<option id="Comedy"><label>Comedy</label></option>
|
||||
<option id="Cult"><label>Cult</label></option>
|
||||
<option id="Gangsta"><label>Gangsta</label></option>
|
||||
<option id="Top 40"><label>Top 40</label></option>
|
||||
<option id="Christian Rap"><label>Christian Rap</label></option>
|
||||
<option id="Pop/Funk"><label>Pop/Funk</label></option>
|
||||
<option id="Jungle"><label>Jungle</label></option>
|
||||
<option id="Native American"><label>Native American</label></option>
|
||||
<option id="Cabaret"><label>Cabaret</label></option>
|
||||
<option id="New Wave"><label>New Wave</label></option>
|
||||
<option id="Psychadelic"><label>Psychadelic</label></option>
|
||||
<option id="Rave"><label>Rave</label></option>
|
||||
<option id="Showtunes"><label>Showtunes</label></option>
|
||||
<option id="Trailer"><label>Trailer</label></option>
|
||||
<option id="Lo-Fi"><label>Lo-Fi</label></option>
|
||||
<option id="Tribal"><label>Tribal</label></option>
|
||||
<option id="Acid Punk"><label>Acid Punk</label></option>
|
||||
<option id="Acid Jazz"><label>Acid Jazz</label></option>
|
||||
<option id="Polka"><label>Polka</label></option>
|
||||
<option id="Retro"><label>Retro</label></option>
|
||||
<option id="Musical"><label>Musical</label></option>
|
||||
<option id="Rock & Roll"><label>Rock & Roll</label></option>
|
||||
<option id="Hard Rock"><label>Hard Rock</label></option>
|
||||
<option id="Folk"><label>Folk</label></option>
|
||||
<option id="Folk-Rock"><label>Folk-Rock</label></option>
|
||||
<option id="National Folk"><label>National Folk</label></option>
|
||||
<option id="Swing"><label>Swing</label></option>
|
||||
<option id="Fast Fusion"><label>Fast Fusion</label></option>
|
||||
<option id="Bebob"><label>Bebob</label></option>
|
||||
<option id="Latin"><label>Latin</label></option>
|
||||
<option id="Revival"><label>Revival</label></option>
|
||||
<option id="Celtic"><label>Celtic</label></option>
|
||||
<option id="Bluegrass"><label>Bluegrass</label></option>
|
||||
<option id="Avantgarde"><label>Avantgarde</label></option>
|
||||
<option id="Gothic Rock"><label>Gothic Rock</label></option>
|
||||
<option id="Progressive Rock"><label>Progressive Rock</label></option>
|
||||
<option id="Psychedelic Rock"><label>Psychedelic Rock</label></option>
|
||||
<option id="Symphonic Rock"><label>Symphonic Rock</label></option>
|
||||
<option id="Slow Rock"><label>Slow Rock</label></option>
|
||||
<option id="Big Band"><label>Big Band</label></option>
|
||||
<option id="Chorus"><label>Chorus</label></option>
|
||||
<option id="Easy Listening"><label>Easy Listening</label></option>
|
||||
<option id="Acoustic"><label>Acoustic</label></option>
|
||||
<option id="Humour"><label>Humour</label></option>
|
||||
<option id="Speech"><label>Speech</label></option>
|
||||
<option id="Chanson"><label>Chanson</label></option>
|
||||
<option id="Opera"><label>Opera</label></option>
|
||||
<option id="Chamber Music"><label>Chamber Music</label></option>
|
||||
<option id="Sonata"><label>Sonata</label></option>
|
||||
<option id="Symphony"><label>Symphony</label></option>
|
||||
<option id="Booty Bass"><label>Booty Bass</label></option>
|
||||
<option id="Primus"><label>Primus</label></option>
|
||||
<option id="Porn Groove"><label>Porn Groove</label></option>
|
||||
<option id="Satire"><label>Satire</label></option>
|
||||
<option id="Slow Jam"><label>Slow Jam</label></option>
|
||||
<option id="Club"><label>Club</label></option>
|
||||
<option id="Tango"><label>Tango</label></option>
|
||||
<option id="Samba"><label>Samba</label></option>
|
||||
<option id="Folklore"><label>Folklore</label></option>
|
||||
<option id="Ballad"><label>Ballad</label></option>
|
||||
<option id="Power Ballad"><label>Power Ballad</label></option>
|
||||
<option id="Rhythmic Soul"><label>Rhythmic Soul</label></option>
|
||||
<option id="Freestyle"><label>Freestyle</label></option>
|
||||
<option id="Duet"><label>Duet</label></option>
|
||||
<option id="Punk Rock"><label>Punk Rock</label></option>
|
||||
<option id="Drum Solo"><label>Drum Solo</label></option>
|
||||
<option id="A capella"><label>A capella</label></option>
|
||||
<option id="Euro-House"><label>Euro-House</label></option>
|
||||
<option id="Dance Hall"><label>Dance Hall</label></option>
|
||||
</options>
|
|
@ -1,4 +1,4 @@
|
|||
<?php if (!$this->hideLib): ?>
|
||||
<?php if (!$this->disableLib): ?>
|
||||
<div id="library_content" class="lib-content tabs ui-widget ui-widget-content block-shadow alpha-block padded"
|
||||
<?php if (!$this->showLib): ?>
|
||||
style="display:none"
|
||||
|
@ -9,7 +9,7 @@
|
|||
<?php endif; ?>
|
||||
|
||||
<div id="show_builder" class="sb-content ui-widget ui-widget-content block-shadow omega-block padded">
|
||||
<?php if (!$this->hideLib && !$this->showLib): ?>
|
||||
<?php if (!$this->disableLib && !$this->showLib): ?>
|
||||
<div id="sb_edit" class="ui-state-default" title="open the library to schedule files.">
|
||||
<span class="ui-icon ui-icon-arrowthick-1-nw"></span>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue