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

Conflicts:
	install/airtime-install.php
This commit is contained in:
Paul Baranowski 2011-04-14 15:07:12 -04:00
commit 514777e8d2
20 changed files with 391 additions and 439 deletions

View File

@ -21,6 +21,7 @@ require_once 'Schedule.php';
require_once 'Shows.php'; require_once 'Shows.php';
require_once 'Users.php'; require_once 'Users.php';
require_once 'RabbitMq.php'; require_once 'RabbitMq.php';
require_once 'DateHelper.php';
require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php'; require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php';
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;

View File

@ -112,8 +112,8 @@ class ApiController extends Zend_Controller_Action
$result = Schedule::GetPlayOrderRange(0, 1); $result = Schedule::GetPlayOrderRange(0, 1);
$date = new Application_Model_DateHelper; $date = new DateHelper;
$timeNow = $date->getDate(); $timeNow = $date->getTimestamp();
$result = array("env"=>APPLICATION_ENV, $result = array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"), "schedulerTime"=>gmdate("Y-m-d H:i:s"),
"currentShow"=>Show_DAL::GetCurrentShow($timeNow), "currentShow"=>Show_DAL::GetCurrentShow($timeNow),

View File

@ -25,6 +25,7 @@ class ScheduleController extends Zend_Controller_Action
->addActionContext('edit-show', 'json') ->addActionContext('edit-show', 'json')
->addActionContext('add-show', 'json') ->addActionContext('add-show', 'json')
->addActionContext('cancel-show', 'json') ->addActionContext('cancel-show', 'json')
->addActionContext('get-form', 'json')
->addActionContext('upload-to-sound-cloud', 'json') ->addActionContext('upload-to-sound-cloud', 'json')
->initContext(); ->initContext();
@ -48,8 +49,6 @@ class ScheduleController extends Zend_Controller_Action
$this->view->headLink()->appendStylesheet('/css/add-show.css'); $this->view->headLink()->appendStylesheet('/css/add-show.css');
$this->view->headLink()->appendStylesheet('/css/contextmenu.css'); $this->view->headLink()->appendStylesheet('/css/contextmenu.css');
$request = $this->getRequest();
$formWhat = new Application_Form_AddShowWhat(); $formWhat = new Application_Form_AddShowWhat();
$formWho = new Application_Form_AddShowWho(); $formWho = new Application_Form_AddShowWho();
$formWhen = new Application_Form_AddShowWhen(); $formWhen = new Application_Form_AddShowWhen();
@ -66,7 +65,6 @@ class ScheduleController extends Zend_Controller_Action
$formStyle->removeDecorator('DtDdWrapper'); $formStyle->removeDecorator('DtDdWrapper');
$formRecord->removeDecorator('DtDdWrapper'); $formRecord->removeDecorator('DtDdWrapper');
$this->view->what = $formWhat; $this->view->what = $formWhat;
$this->view->when = $formWhen; $this->view->when = $formWhen;
$this->view->repeats = $formRepeats; $this->view->repeats = $formRepeats;
@ -399,6 +397,12 @@ class ScheduleController extends Zend_Controller_Action
public function editShowAction() public function editShowAction()
{ {
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$user = new User($userInfo->id);
if(!$user->isAdmin()) {
return;
}
$showInstanceId = $this->_getParam('id'); $showInstanceId = $this->_getParam('id');
$formWhat = new Application_Form_AddShowWhat(); $formWhat = new Application_Form_AddShowWhat();
@ -474,8 +478,8 @@ class ScheduleController extends Zend_Controller_Action
$rebroadcastAbsoluteFormValues = array(); $rebroadcastAbsoluteFormValues = array();
$i = 1; $i = 1;
foreach ($rebroadcastsAbsolute as $rebroadcast){ foreach ($rebroadcastsAbsolute as $rebroadcast){
$rebroadcastAbsoluteFormValues["add_show_rebroadcast_absolute_date_$i"] = $rebroadcast['start_date']; $rebroadcastAbsoluteFormValues["add_show_rebroadcast_date_absolute_$i"] = $rebroadcast['start_date'];
$rebroadcastAbsoluteFormValues["add_show_rebroadcast_absolute_time_$i"] = Show::removeSecondsFromTime($rebroadcast['start_time']); $rebroadcastAbsoluteFormValues["add_show_rebroadcast_time_absolute_$i"] = Show::removeSecondsFromTime($rebroadcast['start_time']);
$i++; $i++;
} }
$formAbsoluteRebroadcast->populate($rebroadcastAbsoluteFormValues); $formAbsoluteRebroadcast->populate($rebroadcastAbsoluteFormValues);
@ -495,6 +499,38 @@ class ScheduleController extends Zend_Controller_Action
$this->view->entries = 5; $this->view->entries = 5;
} }
public function getFormAction(){
$formWhat = new Application_Form_AddShowWhat();
$formWho = new Application_Form_AddShowWho();
$formWhen = new Application_Form_AddShowWhen();
$formRepeats = new Application_Form_AddShowRepeats();
$formStyle = new Application_Form_AddShowStyle();
$formRecord = new Application_Form_AddShowRR();
$formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates();
$formRebroadcast = new Application_Form_AddShowRebroadcastDates();
$formWhat->removeDecorator('DtDdWrapper');
$formWho->removeDecorator('DtDdWrapper');
$formWhen->removeDecorator('DtDdWrapper');
$formRepeats->removeDecorator('DtDdWrapper');
$formStyle->removeDecorator('DtDdWrapper');
$formRecord->removeDecorator('DtDdWrapper');
$this->view->what = $formWhat;
$this->view->when = $formWhen;
$this->view->repeats = $formRepeats;
$this->view->who = $formWho;
$this->view->style = $formStyle;
$this->view->rr = $formRecord;
$this->view->absoluteRebroadcast = $formAbsoluteRebroadcast;
$this->view->rebroadcast = $formRebroadcast;
$this->view->addNewShow = true;
$formWhat->populate(array('add_show_id' => '-1'));
$this->view->form = $this->view->render('schedule/add-show-form.phtml');
}
public function addShowAction() public function addShowAction()
{ {
$js = $this->_getParam('data'); $js = $this->_getParam('data');

View File

@ -5,190 +5,48 @@ class Application_Form_AddShowAbsoluteRebroadcastDates extends Zend_Form_SubForm
public function init() public function init()
{ {
//$this->setDisableLoadDefaultDecorators(true);
$this->setDecorators(array( $this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/add-show-rebroadcast-absolute.phtml')) array('ViewScript', array('viewScript' => 'form/add-show-rebroadcast-absolute.phtml'))
)); ));
// Add start date element for($i=1; $i<=10; $i++) {
$this->addElement('text', 'add_show_rebroadcast_absolute_date_1', array(
'label' => 'Rebroadcast Date:',
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
'NotEmpty',
array('date', false, array('YYYY-MM-DD'))
),
'decorators' => array(
'ViewHelper'
)
));
$text = new Zend_Form_Element_Text("add_show_rebroadcast_date_absolute_$i");
// Add start time element $text->setAttrib('class', 'input_text');
$this->addElement('text', 'add_show_rebroadcast_absolute_time_1', array( $text->addFilter('StringTrim');
'label' => 'Rebroadcast Time:', $text->addValidator('date', false, array('YYYY-MM-DD'));
'class' => 'input_text', $text->setRequired(false);
'required' => false, $text->setDecorators(array('ViewHelper'));
'value' => '', $this->addElement($text);
'filters' => array('StringTrim'),
'validators' => array(
array('date', false, array('HH:mm')),
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))
),
'decorators' => array(
'ViewHelper'
)
));
// Add start date element
$this->addElement('text', 'add_show_rebroadcast_absolute_date_2', array(
'label' => 'Rebroadcast Date:',
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
'NotEmpty',
array('date', false, array('YYYY-MM-DD'))
),
'decorators' => array(
'ViewHelper'
)
));
// Add start time element
$this->addElement('text', 'add_show_rebroadcast_absolute_time_2', array(
'label' => 'Rebroadcast Time:',
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
array('date', false, array('HH:mm')),
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))
),
'decorators' => array(
'ViewHelper'
)
));
// Add start date element
$this->addElement('text', 'add_show_rebroadcast_absolute_date_3', array(
'label' => 'Rebroadcast Date:',
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
'NotEmpty',
array('date', false, array('YYYY-MM-DD'))
),
'decorators' => array(
'ViewHelper'
)
));
// Add start time element
$this->addElement('text', 'add_show_rebroadcast_absolute_time_3', array(
'label' => 'Rebroadcast Time:',
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
array('date', false, array('HH:mm')),
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))
),
'decorators' => array(
'ViewHelper'
)
));
// Add start date element
$this->addElement('text', 'add_show_rebroadcast_absolute_date_4', array(
'label' => 'Rebroadcast Date:',
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
'NotEmpty',
array('date', false, array('YYYY-MM-DD'))
),
'decorators' => array(
'ViewHelper'
)
));
// Add start time element
$this->addElement('text', 'add_show_rebroadcast_absolute_time_4', array(
'label' => 'Rebroadcast Time:',
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
array('date', false, array('HH:mm')),
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))
),
'decorators' => array(
'ViewHelper'
)
));
// Add start date element
$this->addElement('text', 'add_show_rebroadcast_absolute_date_5', array(
'label' => 'Rebroadcast Date:',
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
'NotEmpty',
array('date', false, array('YYYY-MM-DD'))
),
'decorators' => array(
'ViewHelper'
)
));
// Add start time element
$this->addElement('text', 'add_show_rebroadcast_absolute_time_5', array(
'label' => 'Rebroadcast Time:',
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
array('date', false, array('HH:mm')),
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))
),
'decorators' => array(
'ViewHelper'
)
));
$text = new Zend_Form_Element_Text("add_show_rebroadcast_time_absolute_$i");
$text->setAttrib('class', 'input_text');
$text->addFilter('StringTrim');
$text->addValidator('date', false, array('HH:mm'));
$text->addValidator('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'));
$text->setRequired(false);
$text->setDecorators(array('ViewHelper'));
$this->addElement($text);
}
} }
public function checkReliantFields($formData) { public function checkReliantFields($formData) {
$valid = true; $valid = true;
for($i=1; $i<=5; $i++) { for($i=1; $i<=10; $i++) {
$day = $formData['add_show_rebroadcast_absolute_date_'.$i];
if($day == "") { $day = $formData['add_show_rebroadcast_date_absolute_'.$i];
if(trim($day) == "") {
continue; continue;
} }
$time = $formData['add_show_rebroadcast_time_absolute_'.$i];
if (trim($time) == ""){
$this->getElement('add_show_rebroadcast_time_absolute_'.$i)->setErrors(array("Time must be specified"));
$valid = false;
}
$show_start_time = $formData['add_show_start_date']."".$formData['add_show_start_time']; $show_start_time = $formData['add_show_start_date']."".$formData['add_show_start_time'];
$show_end = new DateTime($show_start_time); $show_end = new DateTime($show_start_time);
@ -199,16 +57,16 @@ class Application_Form_AddShowAbsoluteRebroadcastDates extends Zend_Form_SubForm
$show_end->add(new DateInterval("PT$duration[0]H")); $show_end->add(new DateInterval("PT$duration[0]H"));
$show_end->add(new DateInterval("PT$duration[1]M")); $show_end->add(new DateInterval("PT$duration[1]M"));
$show_end->add(new DateInterval("PT1H"));//min time to wait until a rebroadcast $show_end->add(new DateInterval("PT1H"));//min time to wait until a rebroadcast
$rebroad_start = $day."".$formData['add_show_rebroadcast_absolute_time_'.$i]; $rebroad_start = $day."".$formData['add_show_rebroadcast_time_absolute_'.$i];
$rebroad_start = new DateTime($rebroad_start); $rebroad_start = new DateTime($rebroad_start);
if($rebroad_start < $show_end) { if($rebroad_start < $show_end) {
$this->getElement('add_show_rebroadcast_absolute_time_'.$i)->setErrors(array("Must wait at least 1 hour to rebroadcast")); $this->getElement('add_show_rebroadcast_time_absolute_'.$i)->setErrors(array("Must wait at least 1 hour to rebroadcast"));
$valid = false; $valid = false;
} }
} }
return $valid; return $valid;
} }
} }

View File

@ -9,137 +9,30 @@ class Application_Form_AddShowRebroadcastDates extends Zend_Form_SubForm
array('ViewScript', array('viewScript' => 'form/add-show-rebroadcast.phtml')) array('ViewScript', array('viewScript' => 'form/add-show-rebroadcast.phtml'))
)); ));
$relativeDates = array(); $relativeDates = array();
$relativeDates[""] = ""; $relativeDates[""] = "";
for($i=0; $i <=30; $i++) { for($i=0; $i<=30; $i++) {
$relativeDates["$i days"] = "+$i days"; $relativeDates["$i days"] = "+$i days";
} }
//Add date select for($i=1; $i<=10; $i++) {
$this->addElement('select', 'add_show_rebroadcast_date_1', array(
'required' => false,
'class' => ' input_select',
'multiOptions' => $relativeDates,
'decorators' => array(
'ViewHelper'
)
));
// Add start time element $select = new Zend_Form_Element_Select("add_show_rebroadcast_date_$i");
$this->addElement('text', 'add_show_rebroadcast_time_1', array( $select->setAttrib('class', 'input_select');
'class' => 'input_text', $select->setMultiOptions($relativeDates);
'required' => false, $select->setRequired(false);
'value' => '', $select->setDecorators(array('ViewHelper'));
'filters' => array('StringTrim'), $this->addElement($select);
'validators' => array(
array('date', false, array('HH:mm')),
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))
),
'decorators' => array(
'ViewHelper'
)
));
//Add date select $text = new Zend_Form_Element_Text("add_show_rebroadcast_time_$i");
$this->addElement('select', 'add_show_rebroadcast_date_2', array( $text->setAttrib('class', 'input_text');
'required' => false, $text->addFilter('StringTrim');
'class' => ' input_select', $text->addValidator('date', false, array('HH:mm'));
'multiOptions' => $relativeDates, $text->addValidator('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'));
'decorators' => array( $text->setRequired(false);
'ViewHelper' $text->setDecorators(array('ViewHelper'));
) $this->addElement($text);
)); }
// Add start time element
$this->addElement('text', 'add_show_rebroadcast_time_2', array(
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
array('date', false, array('HH:mm')),
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))
),
'decorators' => array(
'ViewHelper'
)
));
//Add date select
$this->addElement('select', 'add_show_rebroadcast_date_3', array(
'required' => false,
'class' => ' input_select',
'multiOptions' => $relativeDates,
'decorators' => array(
'ViewHelper'
)
));
// Add start time element
$this->addElement('text', 'add_show_rebroadcast_time_3', array(
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
array('date', false, array('HH:mm')),
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))
),
'decorators' => array(
'ViewHelper'
)
));
//Add date select
$this->addElement('select', 'add_show_rebroadcast_date_4', array(
'required' => false,
'class' => ' input_select',
'multiOptions' => $relativeDates,
'decorators' => array(
'ViewHelper'
)
));
// Add start time element
$this->addElement('text', 'add_show_rebroadcast_time_4', array(
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
array('date', false, array('HH:mm')),
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))
),
'decorators' => array(
'ViewHelper'
)
));
//Add date select
$this->addElement('select', 'add_show_rebroadcast_date_5', array(
'required' => false,
'class' => ' input_select',
'multiOptions' => $relativeDates,
'decorators' => array(
'ViewHelper'
)
));
// Add start time element
$this->addElement('text', 'add_show_rebroadcast_time_5', array(
'class' => 'input_text',
'required' => false,
'value' => '',
'filters' => array('StringTrim'),
'validators' => array(
array('date', false, array('HH:mm')),
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))
),
'decorators' => array(
'ViewHelper'
)
));
} }
public function checkReliantFields($formData) { public function checkReliantFields($formData) {
@ -147,12 +40,18 @@ class Application_Form_AddShowRebroadcastDates extends Zend_Form_SubForm
$valid = true; $valid = true;
for($i=1; $i<=5; $i++) { for($i=1; $i<=5; $i++) {
$days = $formData['add_show_rebroadcast_date_'.$i]; $days = $formData['add_show_rebroadcast_date_'.$i];
if($days == "") { if(trim($days) == "") {
continue; continue;
} }
$time = $formData['add_show_rebroadcast_time_'.$i];
if (trim($time) == ""){
$this->getElement('add_show_rebroadcast_time_'.$i)->setErrors(array("Time must be specified"));
$valid = false;
}
$days = explode(" ", $days); $days = explode(" ", $days);
$day = $days[0]; $day = $days[0];
@ -166,7 +65,7 @@ class Application_Form_AddShowRebroadcastDates extends Zend_Form_SubForm
$show_end->add(new DateInterval("PT$duration[0]H")); $show_end->add(new DateInterval("PT$duration[0]H"));
$show_end->add(new DateInterval("PT$duration[1]M")); $show_end->add(new DateInterval("PT$duration[1]M"));
$show_end->add(new DateInterval("PT1H"));//min time to wait until a rebroadcast $show_end->add(new DateInterval("PT1H"));//min time to wait until a rebroadcast
$rebroad_start = $formData['add_show_start_date']."".$formData['add_show_rebroadcast_time_'.$i]; $rebroad_start = $formData['add_show_start_date']."".$formData['add_show_rebroadcast_time_'.$i];
$rebroad_start = new DateTime($rebroad_start); $rebroad_start = new DateTime($rebroad_start);
$rebroad_start->add(new DateInterval("P".$day."D")); $rebroad_start->add(new DateInterval("P".$day."D"));
@ -175,8 +74,8 @@ class Application_Form_AddShowRebroadcastDates extends Zend_Form_SubForm
$this->getElement('add_show_rebroadcast_time_'.$i)->setErrors(array("Must wait at least 1 hour to rebroadcast")); $this->getElement('add_show_rebroadcast_time_'.$i)->setErrors(array("Must wait at least 1 hour to rebroadcast"));
$valid = false; $valid = false;
} }
} }
return $valid; return $valid;
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
class Application_Model_DateHelper class DateHelper
{ {
private $_timestamp; private $_timestamp;
@ -13,7 +13,7 @@ class Application_Model_DateHelper
* Get time of object construction in the format * Get time of object construction in the format
* YYYY-MM-DD HH:mm:ss * YYYY-MM-DD HH:mm:ss
*/ */
function getDate() function getTimestamp()
{ {
return date("Y-m-d H:i:s", $this->_timestamp); return date("Y-m-d H:i:s", $this->_timestamp);
} }

View File

@ -57,8 +57,8 @@ class Application_Model_Nowplaying
} }
public static function FilterRowsByDate($rows, $date, $startCutoff, $endCutoff){ public static function FilterRowsByDate($rows, $date, $startCutoff, $endCutoff){
$dateNow = new Application_Model_DateHelper; $dateNow = new DateHelper;
$timeNow = $dateNow->getDate(); $timeNow = $dateNow->getTimestamp();
$data = array(); $data = array();
//iterate over each show, and calculate information for it. //iterate over each show, and calculate information for it.
@ -117,16 +117,16 @@ class Application_Model_Nowplaying
public static function GetDataGridData($viewType, $dateString){ public static function GetDataGridData($viewType, $dateString){
if ($viewType == "now"){ if ($viewType == "now"){
$date = new Application_Model_DateHelper; $date = new DateHelper;
$timeNow = $date->getDate(); $timeNow = $date->getTimestamp();
$startCutoff = 60; $startCutoff = 60;
$endCutoff = 86400; //60*60*24 - seconds in a day $endCutoff = 86400; //60*60*24 - seconds in a day
} else { } else {
$date = new Application_Model_DateHelper; $date = new DateHelper;
$time = $date->getTime(); $time = $date->getTime();
$date->setDate($dateString." ".$time); $date->setDate($dateString." ".$time);
$timeNow = $date->getDate(); $timeNow = $date->getTimestamp();
$startCutoff = $date->getNowDayStartDiff(); $startCutoff = $date->getNowDayStartDiff();
$endCutoff = $date->getNowDayEndDiff(); $endCutoff = $date->getNowDayEndDiff();
@ -139,8 +139,8 @@ class Application_Model_Nowplaying
//$rows = FindGapsBetweenShows() //$rows = FindGapsBetweenShows()
$data = Application_Model_Nowplaying::FilterRowsByDate($rows, $date, $startCutoff, $endCutoff); $data = Application_Model_Nowplaying::FilterRowsByDate($rows, $date, $startCutoff, $endCutoff);
$date = new Application_Model_DateHelper; $date = new DateHelper;
$timeNow = $date->getDate(); $timeNow = $date->getTimestamp();
return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data); return array("currentShow"=>Show_DAL::GetCurrentShow($timeNow), "rows"=>$data);
} }
} }

View File

@ -314,7 +314,9 @@ class Schedule {
." MIN(st.playlist_id) AS playlist_id," ." MIN(st.playlist_id) AS playlist_id,"
." MIN(st.starts) AS starts," ." MIN(st.starts) AS starts,"
." MAX(st.ends) AS ends," ." MAX(st.ends) AS ends,"
." MIN(sh.name) AS show_name" ." MIN(sh.name) AS show_name,"
." MIN(si.starts) AS show_start,"
." MAX(si.ends) AS show_end"
." FROM $CC_CONFIG[scheduleTable] as st" ." FROM $CC_CONFIG[scheduleTable] as st"
." LEFT JOIN $CC_CONFIG[playListTable] as pt" ." LEFT JOIN $CC_CONFIG[playListTable] as pt"
." ON st.playlist_id = pt.id" ." ON st.playlist_id = pt.id"
@ -359,8 +361,8 @@ class Schedule {
global $CC_CONFIG; global $CC_CONFIG;
$date = new Application_Model_DateHelper; $date = new DateHelper;
$timeNow = $date->getDate(); $timeNow = $date->getTimestamp();
return array("env"=>APPLICATION_ENV, return array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"), "schedulerTime"=>gmdate("Y-m-d H:i:s"),
"previous"=>Schedule::GetScheduledItemData($timeNow, -1, $prev, "24 hours"), "previous"=>Schedule::GetScheduledItemData($timeNow, -1, $prev, "24 hours"),
@ -608,10 +610,8 @@ class Schedule {
$data = Schedule::GetItems($range_start, $range_end, true); $data = Schedule::GetItems($range_start, $range_end, true);
$playlists = array(); $playlists = array();
if (is_array($data)) if (is_array($data)){
{ foreach ($data as $dx){
foreach ($data as $dx)
{
$start = $dx['start']; $start = $dx['start'];
//chop off subseconds //chop off subseconds
@ -628,6 +628,8 @@ class Schedule {
$playlists[$pkey]['played'] = '0'; $playlists[$pkey]['played'] = '0';
$playlists[$pkey]['schedule_id'] = $dx['group_id']; $playlists[$pkey]['schedule_id'] = $dx['group_id'];
$playlists[$pkey]['show_name'] = $dx['show_name']; $playlists[$pkey]['show_name'] = $dx['show_name'];
$playlists[$pkey]['show_start'] = Schedule::AirtimeTimeToPypoTime($dx['show_start']);
$playlists[$pkey]['show_end'] = Schedule::AirtimeTimeToPypoTime($dx['show_end']);
$playlists[$pkey]['user_id'] = 0; $playlists[$pkey]['user_id'] = 0;
$playlists[$pkey]['id'] = $dx['group_id']; $playlists[$pkey]['id'] = $dx['group_id'];
$playlists[$pkey]['start'] = Schedule::AirtimeTimeToPypoTime($dx["start"]); $playlists[$pkey]['start'] = Schedule::AirtimeTimeToPypoTime($dx["start"]);

View File

@ -136,9 +136,13 @@ class Show {
$uncheckedDaysImploded = implode(",", $p_uncheckedDays); $uncheckedDaysImploded = implode(",", $p_uncheckedDays);
$showId = $this->getId(); $showId = $this->getId();
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$sql = "DELETE FROM cc_show_instances" $sql = "DELETE FROM cc_show_instances"
." WHERE EXTRACT(DOW FROM starts) IN ($uncheckedDaysImploded)" ." WHERE EXTRACT(DOW FROM starts) IN ($uncheckedDaysImploded)"
." AND starts > current_timestamp " ." AND starts > TIMESTAMP '$timestamp'"
." AND show_id = $showId"; ." AND show_id = $showId";
$CC_DBC->query($sql); $CC_DBC->query($sql);
@ -177,6 +181,14 @@ class Show {
return !is_null($showInstancesRow); return !is_null($showInstancesRow);
} }
/**
* Get start time and absolute start date for a recorded
* shows rebroadcasts. For example start date format would be
* YYYY-MM-DD and time would HH:MM
*
* @return array
* array of associate arrays containing "start_date" and "start_time"
*/
public function getRebroadcastsAbsolute() public function getRebroadcastsAbsolute()
{ {
global $CC_DBC; global $CC_DBC;
@ -199,6 +211,14 @@ class Show {
return $CC_DBC->GetAll($sql); return $CC_DBC->GetAll($sql);
} }
/**
* Get start time and relative start date for a recorded
* shows rebroadcasts. For example start date format would be
* "x days" and time would HH:MM:SS
*
* @return array
* array of associate arrays containing "day_offset" and "start_time"
*/
public function getRebroadcastsRelative() public function getRebroadcastsRelative()
{ {
global $CC_DBC; global $CC_DBC;
@ -272,42 +292,76 @@ class Show {
return $endDate; return $endDate;
} }
} }
/**
* Deletes all future instances of the current show object
* from the show_instances table.
*
*/
public function deleteAllInstances(){ public function deleteAllInstances(){
global $CC_DBC; global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$showId = $this->getId(); $showId = $this->getId();
$sql = "DELETE FROM cc_show_instances " $sql = "DELETE FROM cc_show_instances"
."WHERE starts > current_timestamp " ." WHERE starts > TIMESTAMP '$timestamp'"
."AND show_id = $showId"; ." AND show_id = $showId";
$CC_DBC->query($sql); $CC_DBC->query($sql);
} }
/**
* Deletes all show instances of current show after a
* certain date.
*
* @param string $p_date
* The date which to delete after
*/
public function removeAllInstancesAfterDate($p_date){ public function removeAllInstancesAfterDate($p_date){
global $CC_DBC; global $CC_DBC;
$showId = $this->getId(); $date = new DateHelper;
$sql = "DELETE FROM cc_show_instances " $timestamp = $date->getTimestamp();
."WHERE date(starts) > DATE '$p_date' "
."AND starts > current_timestamp "
."AND show_id = $showId";
$CC_DBC->query($sql);
}
public function removeAllInstancesBeforeDate($p_date){
global $CC_DBC;
$showId = $this->getId(); $showId = $this->getId();
$sql = "DELETE FROM cc_show_instances " $sql = "DELETE FROM cc_show_instances "
."WHERE date(starts) < DATE '$p_date' " ." WHERE date(starts) > DATE '$p_date'"
."AND starts > current_timestamp " ." AND starts > TIMESTAMP '$timestamp'"
."AND show_id = $showId"; ." AND show_id = $showId";
$CC_DBC->query($sql);
}
/**
* Deletes all show instances of current show before a
* certain date.
*
* @param string $p_date
* The date which to delete before
*/
public function removeAllInstancesBeforeDate($p_date){
global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$showId = $this->getId();
$sql = "DELETE FROM cc_show_instances "
." WHERE date(starts) < DATE '$p_date'"
." AND starts > TIMESTAMP '$timestamp'"
." AND show_id = $showId";
$CC_DBC->query($sql); $CC_DBC->query($sql);
} }
/**
* Get the start date of the current show.
*
* @return string
* The start date in the format YYYY-MM-DD
*/
public function getStartDate(){ public function getStartDate(){
global $CC_DBC; global $CC_DBC;
@ -323,7 +377,13 @@ class Show {
return $firstDate; return $firstDate;
} }
} }
/**
* Get the start time of the current show.
*
* @return string
* The start time in the format HH:MM:SS
*/
public function getStartTime(){ public function getStartTime(){
global $CC_DBC; global $CC_DBC;
@ -339,14 +399,23 @@ class Show {
return $startTime; return $startTime;
} }
} }
/**
* Get the ID's of future instance of the current show.
*
* @return array
* A simple array containing all future instance ID's
*/
public function getAllFutureInstanceIds(){ public function getAllFutureInstanceIds(){
global $CC_DBC; global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$showId = $this->getId(); $showId = $this->getId();
$sql = "SELECT id from cc_show_instances " $sql = "SELECT id from cc_show_instances"
." WHERE show_id = $showId" ." WHERE show_id = $showId"
." AND starts > current_timestamp"; ." AND starts > TIMESTAMP '$timestamp'";
$rows = $CC_DBC->GetAll($sql); $rows = $CC_DBC->GetAll($sql);
@ -361,6 +430,9 @@ class Show {
//need to update cc_show_instances, cc_show_days //need to update cc_show_instances, cc_show_days
global $CC_DBC; global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$sql = "UPDATE cc_show_days " $sql = "UPDATE cc_show_days "
."SET duration = '$p_data[add_show_duration]' " ."SET duration = '$p_data[add_show_duration]' "
@ -370,7 +442,7 @@ class Show {
$sql = "UPDATE cc_show_instances " $sql = "UPDATE cc_show_instances "
."SET ends = starts + INTERVAL '$p_data[add_show_duration]' " ."SET ends = starts + INTERVAL '$p_data[add_show_duration]' "
."WHERE show_id = $p_data[add_show_id] " ."WHERE show_id = $p_data[add_show_id] "
."AND starts > current_timestamp"; ."AND starts > TIMESTAMP '$timestamp'";
$CC_DBC->query($sql); $CC_DBC->query($sql);
} }
@ -379,6 +451,9 @@ class Show {
//need to update cc_schedule, cc_show_instances, cc_show_days //need to update cc_schedule, cc_show_instances, cc_show_days
global $CC_DBC; global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$sql = "UPDATE cc_show_days " $sql = "UPDATE cc_show_days "
."SET start_time = TIME '$p_data[add_show_start_time]', " ."SET start_time = TIME '$p_data[add_show_start_time]', "
@ -399,7 +474,7 @@ class Show {
."SET starts = starts + INTERVAL '$diff sec', " ."SET starts = starts + INTERVAL '$diff sec', "
."ends = ends + INTERVAL '$diff sec' " ."ends = ends + INTERVAL '$diff sec' "
."WHERE show_id = $p_data[add_show_id] " ."WHERE show_id = $p_data[add_show_id] "
."AND starts > current_timestamp"; ."AND starts > TIMESTAMP '$timestamp'";
$CC_DBC->query($sql); $CC_DBC->query($sql);
$showInstanceIds = $this->getAllFutureInstanceIds(); $showInstanceIds = $this->getAllFutureInstanceIds();
@ -656,7 +731,7 @@ class Show {
//adding rows to cc_show_rebroadcast //adding rows to cc_show_rebroadcast
if ($isRecorded && $data['add_show_rebroadcast'] && $repeatType != -1) { if ($isRecorded && $data['add_show_rebroadcast'] && $repeatType != -1) {
for ($i=1; $i<=5; $i++) { for ($i=1; $i<=10; $i++) {
if ($data['add_show_rebroadcast_date_'.$i]) { if ($data['add_show_rebroadcast_date_'.$i]) {
$showRebroad = new CcShowRebroadcast(); $showRebroad = new CcShowRebroadcast();
@ -668,16 +743,16 @@ class Show {
} }
} else if ($isRecorded && $data['add_show_rebroadcast'] && $repeatType == -1){ } else if ($isRecorded && $data['add_show_rebroadcast'] && $repeatType == -1){
for ($i=1; $i<=5; $i++) { for ($i=1; $i<=10; $i++) {
if ($data['add_show_rebroadcast_absolute_date_'.$i]) { if ($data['add_show_rebroadcast_date_absolute_'.$i]) {
$sql = "SELECT date '{$data['add_show_rebroadcast_absolute_date_'.$i]}' - date '{$data['add_show_start_date']}' "; $sql = "SELECT date '{$data['add_show_rebroadcast_date_absolute_'.$i]}' - date '{$data['add_show_start_date']}' ";
$r = $con->query($sql); $r = $con->query($sql);
$offset_days = $r->fetchColumn(0); $offset_days = $r->fetchColumn(0);
$showRebroad = new CcShowRebroadcast(); $showRebroad = new CcShowRebroadcast();
$showRebroad->setDbDayOffset($offset_days." days"); $showRebroad->setDbDayOffset($offset_days." days");
$showRebroad->setDbStartTime($data['add_show_rebroadcast_absolute_time_'.$i]); $showRebroad->setDbStartTime($data['add_show_rebroadcast_time_absolute_'.$i]);
$showRebroad->setDbShowId($showId); $showRebroad->setDbShowId($showId);
$showRebroad->save(); $showRebroad->save();
} }

View File

@ -5,18 +5,24 @@
</dt> </dt>
<dd id="add_show_rebroadcast_day-element" class="block-display clearfix"> <dd id="add_show_rebroadcast_day-element" class="block-display clearfix">
<ul class="formrow-repeat"> <ul class="formrow-repeat">
<?php for($i=1; $i<=5; $i++): ?> <?php for($i=1; $i<=10; $i++): ?>
<li> <li <?php if(($i > 1) && ($this->element->getElement('add_show_rebroadcast_date_absolute_'.$i)->getValue() == "")){echo 'style=display:none';} ?>>
<?php echo $this->element->getElement('add_show_rebroadcast_absolute_date_'.$i) ?> <?php echo $this->element->getElement('add_show_rebroadcast_date_absolute_'.$i) ?>
<span class="inline-text">@</span> <span class="inline-text">@</span>
<?php echo $this->element->getElement('add_show_rebroadcast_absolute_time_'.$i) ?> <?php echo $this->element->getElement('add_show_rebroadcast_time_absolute_'.$i) ?>
<?php if($i > 1): ?>
<a class="ui-button ui-button-icon-only ui-widget ui-state-default" id="remove_rebroadcast_absolute_<?php echo $i ?>">
<span class="ui-icon ui-icon-closethick"></span>
<span class="ui-button-text">Remove</span>
</a>
<?php endif; ?>
</li> </li>
<?php if(($this->element->getElement('add_show_rebroadcast_absolute_date_'.$i)->hasErrors()) <?php if(($this->element->getElement('add_show_rebroadcast_date_absolute_'.$i)->hasErrors())
|| ($this->element->getElement('add_show_rebroadcast_absolute_time_'.$i)->hasErrors())) : ?> || ($this->element->getElement('add_show_rebroadcast_time_absolute_'.$i)->hasErrors())) : ?>
<ul class='errors'> <ul class='errors'>
<?php $errors = array_merge( <?php $errors = array_merge(
$this->element->getElement('add_show_rebroadcast_absolute_date_'.$i)->getMessages(), $this->element->getElement('add_show_rebroadcast_date_absolute_'.$i)->getMessages(),
$this->element->getElement('add_show_rebroadcast_absolute_time_'.$i)->getMessages() $this->element->getElement('add_show_rebroadcast_time_absolute_'.$i)->getMessages()
); );
?> ?>
@ -27,6 +33,10 @@
<?php endif; ?> <?php endif; ?>
<?php endfor; ?> <?php endfor; ?>
</ul> </ul>
<a class="ui-button ui-button-icon-only ui-widget ui-state-default add_absolute_rebroadcast_day">
<span class="ui-icon ui-icon-plusthick"></span>
<span class="ui-button-text">Add</span>
</a>
</dd> </dd>
</dl> </dl>
</fieldset> </fieldset>

View File

@ -4,30 +4,40 @@
<label for="add_show_rebroadcast_repeat_day" class="optional">Repeat Days:</label> <label for="add_show_rebroadcast_repeat_day" class="optional">Repeat Days:</label>
</dt> </dt>
<dd id="add_show_rebroadcast_repeat_day-element" class="block-display clearfix"> <dd id="add_show_rebroadcast_repeat_day-element" class="block-display clearfix">
<ul class="formrow-repeat"> <ul class="formrow-repeat">
<?php for($i=1; $i<=5; $i++): ?> <?php for($i=1; $i<=10; $i++): ?>
<li> <li <?php if(($i > 1) && (is_null($this->element->getElement('add_show_rebroadcast_date_'.$i)->getValue()))){echo 'style=display:none';} ?>>
<?php echo $this->element->getElement('add_show_rebroadcast_date_'.$i) ?> <?php echo $this->element->getElement('add_show_rebroadcast_date_'.$i) ?>
<span class="inline-text">@</span> <span class="inline-text">@</span>
<?php echo $this->element->getElement('add_show_rebroadcast_time_'.$i) ?> <?php echo $this->element->getElement('add_show_rebroadcast_time_'.$i) ?>
</li> <?php if($i > 1): ?>
<a class="ui-button ui-button-icon-only ui-widget ui-state-default" id="remove_rebroadcast_<?php echo $i ?>">
<span class="ui-icon ui-icon-closethick"></span>
<span class="ui-button-text">Remove</span>
</a>
<?php endif; ?>
</li>
<?php if(($this->element->getElement('add_show_rebroadcast_date_'.$i)->hasErrors()) <?php if(($this->element->getElement('add_show_rebroadcast_date_'.$i)->hasErrors())
|| ($this->element->getElement('add_show_rebroadcast_time_'.$i)->hasErrors())) : ?> || ($this->element->getElement('add_show_rebroadcast_time_'.$i)->hasErrors())) : ?>
<ul class='errors'> <ul class='errors'>
<?php $errors = array_merge( <?php $errors = array_merge(
$this->element->getElement('add_show_rebroadcast_date_'.$i)->getMessages(), $this->element->getElement('add_show_rebroadcast_date_'.$i)->getMessages(),
$this->element->getElement('add_show_rebroadcast_time_'.$i)->getMessages() $this->element->getElement('add_show_rebroadcast_time_'.$i)->getMessages()
); );
?> ?>
<?php foreach($errors as $error): ?> <?php foreach($errors as $error): ?>
<li><?php echo $error; ?></li> <li><?php echo $error; ?></li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
<?php endif; ?> <?php endif; ?>
<?php endfor; ?> <?php endfor; ?>
</ul> </ul>
<a class="ui-button ui-button-icon-only ui-widget ui-state-default add_absolute_rebroadcast_day">
<span class="ui-icon ui-icon-plusthick"></span>
<span class="ui-button-text">Add</span>
</a>
</dd> </dd>
</dl> </dl>
</fieldset> </fieldset>

View File

@ -1,2 +1 @@
<?php //left empty on purpose
//$this->entries;

View File

@ -0,0 +1 @@
//left empty on purpose

View File

@ -1,7 +1,8 @@
<?php <?php
require_once(dirname(__FILE__).'/../../library/pear/DB.php'); //Pear classes.
require_once(dirname(__FILE__).'/../../application/configs/conf.php'); set_include_path(__DIR__.'/../../library/pear' . PATH_SEPARATOR . get_include_path());
require_once('DB.php');
class AirtimeInstall { class AirtimeInstall {
/** /**
@ -47,8 +48,8 @@ class AirtimeInstall {
static function DbConnect($p_exitOnError = true) static function DbConnect($p_exitOnError = true)
{ {
global $CC_DBC, $CC_CONFIG; global $CC_DBC, $CC_CONFIG;
$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE); $CC_DBC = DB::connect($CC_CONFIG['dsn'], FALSE);
if (PEAR::isError($CC_DBC)) { if (PEAR::isError($CC_DBC)) {
echo $CC_DBC->getMessage().PHP_EOL; echo $CC_DBC->getMessage().PHP_EOL;
echo $CC_DBC->getUserInfo().PHP_EOL; echo $CC_DBC->getUserInfo().PHP_EOL;

View File

@ -150,14 +150,55 @@ function setAddShowEvents() {
defaultTime: '01:00' defaultTime: '01:00'
}); });
form.find('input[name^="add_show_rebroadcast_absolute_date"]').datepicker({ form.find('input[name^="add_show_rebroadcast_date_absolute"]').datepicker({
minDate: new Date(), minDate: new Date(),
dateFormat: 'yy-mm-dd' dateFormat: 'yy-mm-dd'
}); });
form.find('input[name^="add_show_rebroadcast_absolute_time"], input[name^="add_show_rebroadcast_time"]').timepicker({ form.find('input[name^="add_show_rebroadcast_time"]').timepicker({
amPmText: ['', ''], amPmText: ['', ''],
defaultTime: '' defaultTime: ''
}); });
form.find(".add_absolute_rebroadcast_day").click(function(){
var li = $(this).prev().find("li:visible:last").next();
li.show();
li = li.next();
if(li.length === 0) {
$(this).hide();
}
});
form.find('a[id^="remove_rebroadcast"]').click(function(){
var list = $(this).parent().parent();
var li_num = $(this).parent().index();
var num = list.find("li").length;
var count = num - li_num;
var curr = $(this).parent();
var next = curr.next();
for(var i=0; i<=count; i++) {
var date = next.find('[name^="add_show_rebroadcast_date"]').val();
curr.find('[name^="add_show_rebroadcast_date"]').val(date);
var time = next.find('[name^="add_show_rebroadcast_time"]').val();
curr.find('[name^="add_show_rebroadcast_time"]').val(time);
curr = next;
next = curr.next();
}
list.find("li:visible:last")
.find('[name^="add_show_rebroadcast_date"]')
.val('')
.end()
.find('[name^="add_show_rebroadcast_time"]')
.val('')
.end()
.hide();
list.next().show();
});
form.find("#add_show_hosts_autocomplete").autocomplete({ form.find("#add_show_hosts_autocomplete").autocomplete({
source: findHosts, source: findHosts,
@ -166,7 +207,7 @@ function setAddShowEvents() {
}); });
form.find("#schedule-show-style input").ColorPicker({ form.find("#schedule-show-style input").ColorPicker({
onChange: function (hsb, hex, rgb, el) { onChange: function (hsb, hex, rgb, el) {
$(el).val(hex); $(el).val(hex);
}, },
onSubmit: function(hsb, hex, rgb, el) { onSubmit: function(hsb, hex, rgb, el) {
@ -186,9 +227,18 @@ function setAddShowEvents() {
var y = $("#schedule_calendar").width(); var y = $("#schedule_calendar").width();
var z = $("#schedule-add-show").width(); var z = $("#schedule-add-show").width();
$("#schedule_calendar").width(y+z+50);
$("#schedule_calendar").fullCalendar('render'); $("#schedule_calendar").width(y+z+50)
.fullCalendar('render');
$("#add-show-form").hide(); $("#add-show-form").hide();
$.get("/Schedule/get-form", {format:"json"}, function(json){
$("#add-show-form")
.empty()
.append(json.form);
setAddShowEvents();
});
makeAddShowButton(); makeAddShowButton();
}); });
@ -197,7 +247,8 @@ function setAddShowEvents() {
var addShowButton = $(this); var addShowButton = $(this);
if (!addShowButton.hasClass("disabled")){ if (!addShowButton.hasClass("disabled")){
addShowButton.addClass("disabled"); addShowButton.addClass("disabled");
} else { }
else {
return; return;
} }

View File

@ -25,21 +25,26 @@ function makeAddShowButton(){
.append('<span class="fc-button"><a href="#" class="add-button"><span class="add-icon"></span>Show</a></span>') .append('<span class="fc-button"><a href="#" class="add-button"><span class="add-icon"></span>Show</a></span>')
.find('span.fc-button:last > a') .find('span.fc-button:last > a')
.click(function(){ .click(function(){
openAddShowForm(); openAddShowForm();
removeAddShowButton();
var span = $(this).parent();
$(span).prev().remove();
$(span).remove();
}); });
} }
function beginEditShow(data){ function removeAddShowButton(){
//alert (data.entries); var aTag = $('.fc-header-left')
.find("span.fc-button:last > a");
var span = aTag.parent();
span.prev().remove();
span.remove();
}
function beginEditShow(data){
$("#add-show-form") $("#add-show-form")
.empty() .empty()
.append(data.newForm); .append(data.newForm);
removeAddShowButton();
setAddShowEvents(); setAddShowEvents();
openAddShowForm(); openAddShowForm();
} }

View File

@ -76,7 +76,7 @@ function getDateString(){
return (date0.getFullYear() + "-" + (parseInt(date0.getMonth())+1) + "-" + date0.getDate()); return (date0.getFullYear() + "-" + (parseInt(date0.getMonth())+1) + "-" + date0.getDate());
} }
function getAJAXURL(){ function getAjaxUrl(){
var url = "/Nowplaying/get-data-grid-data/format/json/view/"+viewType; var url = "/Nowplaying/get-data-grid-data/format/json/view/"+viewType;
if (viewType == "day"){ if (viewType == "day"){
@ -99,7 +99,7 @@ function updateDataTable(){
} }
function getData(){ function getData(){
$.ajax({ url: getAJAXURL(), dataType:"json", success:function(data){ $.ajax({ url: getAjaxUrl(), dataType:"json", success:function(data){
datagridData = data.entries; datagridData = data.entries;
if (datagridData.currentShow.length > 0) if (datagridData.currentShow.length > 0)
currentShowInstanceID = datagridData.currentShow[0].instance_id; currentShowInstanceID = datagridData.currentShow[0].instance_id;

View File

@ -85,7 +85,7 @@ function updateProgressBarValue(){
songPercentDone = 0; songPercentDone = 0;
currentSong = new Array(); currentSong = new Array();
} else { } else {
if (currentSong[0].media_item_played == "t") if (currentSong[0].media_item_played == "t" && currentShow.length > 0)
$('#on-air-info').attr("class", "on-air-info on"); $('#on-air-info').attr("class", "on-air-info on");
else else
$('#on-air-info').attr("class", "on-air-info off"); $('#on-air-info').attr("class", "on-air-info off");

View File

@ -101,7 +101,7 @@ class PypoFetch(Thread):
""" """
def process_schedule(self, schedule_data, export_source): def process_schedule(self, schedule_data, export_source):
logger = logging.getLogger('fetch') logger = logging.getLogger('fetch')
self.schedule = schedule_data["playlists"] playlists = schedule_data["playlists"]
self.check_matching_timezones(schedule_data["server_timezone"]) self.check_matching_timezones(schedule_data["server_timezone"])
@ -121,13 +121,13 @@ class PypoFetch(Thread):
# Download all the media and put playlists in liquidsoap format # Download all the media and put playlists in liquidsoap format
try: try:
playlists = self.prepare_playlists() liquidsoap_playlists = self.prepare_playlists(playlists)
except Exception, e: logger.error("%s", e) except Exception, e: logger.error("%s", e)
# Send the data to pypo-push # Send the data to pypo-push
scheduled_data = dict() scheduled_data = dict()
scheduled_data['playlists'] = playlists scheduled_data['liquidsoap_playlists'] = liquidsoap_playlists
scheduled_data['schedule'] = self.schedule scheduled_data['schedule'] = playlists
scheduled_data['stream_metadata'] = schedule_data["stream_metadata"] scheduled_data['stream_metadata'] = schedule_data["stream_metadata"]
self.queue.put(scheduled_data) self.queue.put(scheduled_data)
@ -141,23 +141,22 @@ class PypoFetch(Thread):
and stored in a playlist folder. and stored in a playlist folder.
file is e.g. 2010-06-23-15-00-00/17_cue_10.132-123.321.mp3 file is e.g. 2010-06-23-15-00-00/17_cue_10.132-123.321.mp3
""" """
def prepare_playlists(self): def prepare_playlists(self, playlists):
logger = logging.getLogger('fetch') logger = logging.getLogger('fetch')
schedule = self.schedule liquidsoap_playlists = dict()
playlists = dict()
# Dont do anything if schedule is empty # Dont do anything if playlists is empty
if not schedule: if not playlists:
logger.debug("Schedule is empty.") logger.debug("Schedule is empty.")
return playlists return liquidsoap_playlists
scheduleKeys = sorted(schedule.iterkeys()) scheduleKeys = sorted(playlists.iterkeys())
try: try:
for pkey in scheduleKeys: for pkey in scheduleKeys:
logger.info("Playlist starting at %s", pkey) logger.info("Playlist starting at %s", pkey)
playlist = schedule[pkey] playlist = playlists[pkey]
# create playlist directory # create playlist directory
try: try:
@ -181,10 +180,10 @@ class PypoFetch(Thread):
elif int(playlist['subtype']) > 0 and int(playlist['subtype']) < 5: elif int(playlist['subtype']) > 0 and int(playlist['subtype']) < 5:
ls_playlist = self.handle_media_file(playlist, pkey) ls_playlist = self.handle_media_file(playlist, pkey)
playlists[pkey] = ls_playlist liquidsoap_playlists[pkey] = ls_playlist
except Exception, e: except Exception, e:
logger.info("%s", e) logger.info("%s", e)
return playlists return liquidsoap_playlists
""" """

View File

@ -48,6 +48,10 @@ class PypoPush(Thread):
self.push_ahead = 10 self.push_ahead = 10
self.push_ahead2 = self.push_ahead -5 self.push_ahead2 = self.push_ahead -5
#toggle between "stop" and "play". Keeps track of the state of
#liquidsoap
self.liquidsoap_state_play = True
def set_export_source(self, export_source): def set_export_source(self, export_source):
self.export_source = export_source self.export_source = export_source
self.cache_dir = config["cache_dir"] + self.export_source + '/' self.cache_dir = config["cache_dir"] + self.export_source + '/'
@ -67,14 +71,13 @@ class PypoPush(Thread):
scheduled_data = self.queue.get() scheduled_data = self.queue.get()
logger.debug("Received data from pypo-fetch") logger.debug("Received data from pypo-fetch")
self.schedule = scheduled_data['schedule'] self.schedule = scheduled_data['schedule']
self.playlists = scheduled_data['playlists'] self.playlists = scheduled_data['liquidsoap_playlists']
self.stream_metadata = scheduled_data['stream_metadata'] self.stream_metadata = scheduled_data['stream_metadata']
logger.debug('schedule %s' % json.dumps(self.schedule))
logger.debug('playlists %s' % json.dumps(self.playlists))
schedule = self.schedule schedule = self.schedule
playlists = self.playlists playlists = self.playlists
logger.debug('schedule %s' % json.dumps(schedule))
logger.debug('playlists %s' % json.dumps(playlists))
currently_on_air = False currently_on_air = False
if schedule: if schedule:
@ -92,9 +95,7 @@ class PypoPush(Thread):
for pkey in schedule: for pkey in schedule:
plstart = pkey[0:19] plstart = pkey[0:19]
start = schedule[pkey]['start']
end = schedule[pkey]['end']
playedFlag = (pkey in playedItems) and playedItems[pkey].get("played", 0) playedFlag = (pkey in playedItems) and playedItems[pkey].get("played", 0)
if plstart == str_tcoming_s or (plstart < str_tcoming_s and plstart > str_tcoming2_s and not playedFlag): if plstart == str_tcoming_s or (plstart < str_tcoming_s and plstart > str_tcoming2_s and not playedFlag):
@ -120,21 +121,23 @@ class PypoPush(Thread):
# Call API to update schedule states # Call API to update schedule states
logger.debug("Doing callback to server to update 'played' status.") logger.debug("Doing callback to server to update 'played' status.")
self.api_client.notify_scheduled_item_start_playing(pkey, schedule) self.api_client.notify_scheduled_item_start_playing(pkey, schedule)
start = schedule[pkey]['start']
end = schedule[pkey]['end']
if start <= str_tnow_s and str_tnow_s < end: show_start = schedule[pkey]['show_start']
show_end = schedule[pkey]['show_end']
if show_start <= str_tnow_s and str_tnow_s < show_end:
currently_on_air = True currently_on_air = True
else: else:
pass pass
#logger.debug('Empty schedule') #logger.debug('Empty schedule')
if not currently_on_air: if not currently_on_air and self.liquidsoap_state_play:
logger.debug('Notifying Liquidsoap to stop playback.')
tn = telnetlib.Telnet(LS_HOST, LS_PORT) tn = telnetlib.Telnet(LS_HOST, LS_PORT)
tn.write('source.skip\n') tn.write('source.skip\n')
tn.write('exit\n') tn.write('exit\n')
tn.read_all() tn.read_all()
self.liquidsoap_state_play = False
def push_liquidsoap(self, pkey, schedule, playlists): def push_liquidsoap(self, pkey, schedule, playlists):
logger = logging.getLogger('push') logger = logging.getLogger('push')
@ -185,6 +188,8 @@ class PypoPush(Thread):
tn.write("exit\n") tn.write("exit\n")
logger.debug(tn.read_all()) logger.debug(tn.read_all())
self.liquidsoap_state_play = True
status = 1 status = 1
except Exception, e: except Exception, e:
logger.error('%s', e) logger.error('%s', e)