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 'Users.php';
require_once 'RabbitMq.php';
require_once 'DateHelper.php';
require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php';
global $CC_CONFIG, $CC_DBC;

View File

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

View File

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

View File

@ -5,190 +5,48 @@ class Application_Form_AddShowAbsoluteRebroadcastDates extends Zend_Form_SubForm
public function init()
{
//$this->setDisableLoadDefaultDecorators(true);
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/add-show-rebroadcast-absolute.phtml'))
));
// Add start date element
$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'
)
));
for($i=1; $i<=10; $i++) {
// Add start time element
$this->addElement('text', 'add_show_rebroadcast_absolute_time_1', 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_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_date_absolute_$i");
$text->setAttrib('class', 'input_text');
$text->addFilter('StringTrim');
$text->addValidator('date', false, array('YYYY-MM-DD'));
$text->setRequired(false);
$text->setDecorators(array('ViewHelper'));
$this->addElement($text);
$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) {
$valid = true;
for($i=1; $i<=5; $i++) {
$day = $formData['add_show_rebroadcast_absolute_date_'.$i];
for($i=1; $i<=10; $i++) {
if($day == "") {
$day = $formData['add_show_rebroadcast_date_absolute_'.$i];
if(trim($day) == "") {
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_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[1]M"));
$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);
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;
}
}
}
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'))
));
$relativeDates = array();
$relativeDates[""] = "";
for($i=0; $i <=30; $i++) {
$relativeDates["$i days"] = "+$i days";
for($i=0; $i<=30; $i++) {
$relativeDates["$i days"] = "+$i days";
}
//Add date select
$this->addElement('select', 'add_show_rebroadcast_date_1', array(
'required' => false,
'class' => ' input_select',
'multiOptions' => $relativeDates,
'decorators' => array(
'ViewHelper'
)
));
for($i=1; $i<=10; $i++) {
// Add start time element
$this->addElement('text', 'add_show_rebroadcast_time_1', 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'
)
));
$select = new Zend_Form_Element_Select("add_show_rebroadcast_date_$i");
$select->setAttrib('class', 'input_select');
$select->setMultiOptions($relativeDates);
$select->setRequired(false);
$select->setDecorators(array('ViewHelper'));
$this->addElement($select);
//Add date select
$this->addElement('select', 'add_show_rebroadcast_date_2', array(
'required' => false,
'class' => ' input_select',
'multiOptions' => $relativeDates,
'decorators' => array(
'ViewHelper'
)
));
// 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'
)
));
$text = new Zend_Form_Element_Text("add_show_rebroadcast_time_$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) {
@ -147,12 +40,18 @@ class Application_Form_AddShowRebroadcastDates extends Zend_Form_SubForm
$valid = true;
for($i=1; $i<=5; $i++) {
$days = $formData['add_show_rebroadcast_date_'.$i];
if($days == "") {
if(trim($days) == "") {
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);
$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[1]M"));
$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 = new DateTime($rebroad_start);
$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"));
$valid = false;
}
}
}
return $valid;
}
}

View File

@ -1,6 +1,6 @@
<?php
class Application_Model_DateHelper
class DateHelper
{
private $_timestamp;
@ -13,7 +13,7 @@ class Application_Model_DateHelper
* Get time of object construction in the format
* YYYY-MM-DD HH:mm:ss
*/
function getDate()
function getTimestamp()
{
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){
$dateNow = new Application_Model_DateHelper;
$timeNow = $dateNow->getDate();
$dateNow = new DateHelper;
$timeNow = $dateNow->getTimestamp();
$data = array();
//iterate over each show, and calculate information for it.
@ -117,16 +117,16 @@ class Application_Model_Nowplaying
public static function GetDataGridData($viewType, $dateString){
if ($viewType == "now"){
$date = new Application_Model_DateHelper;
$timeNow = $date->getDate();
$date = new DateHelper;
$timeNow = $date->getTimestamp();
$startCutoff = 60;
$endCutoff = 86400; //60*60*24 - seconds in a day
} else {
$date = new Application_Model_DateHelper;
$date = new DateHelper;
$time = $date->getTime();
$date->setDate($dateString." ".$time);
$timeNow = $date->getDate();
$timeNow = $date->getTimestamp();
$startCutoff = $date->getNowDayStartDiff();
$endCutoff = $date->getNowDayEndDiff();
@ -139,8 +139,8 @@ class Application_Model_Nowplaying
//$rows = FindGapsBetweenShows()
$data = Application_Model_Nowplaying::FilterRowsByDate($rows, $date, $startCutoff, $endCutoff);
$date = new Application_Model_DateHelper;
$timeNow = $date->getDate();
$date = new DateHelper;
$timeNow = $date->getTimestamp();
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.starts) AS starts,"
." 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"
." LEFT JOIN $CC_CONFIG[playListTable] as pt"
." ON st.playlist_id = pt.id"
@ -359,8 +361,8 @@ class Schedule {
global $CC_CONFIG;
$date = new Application_Model_DateHelper;
$timeNow = $date->getDate();
$date = new DateHelper;
$timeNow = $date->getTimestamp();
return array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"),
"previous"=>Schedule::GetScheduledItemData($timeNow, -1, $prev, "24 hours"),
@ -608,10 +610,8 @@ class Schedule {
$data = Schedule::GetItems($range_start, $range_end, true);
$playlists = array();
if (is_array($data))
{
foreach ($data as $dx)
{
if (is_array($data)){
foreach ($data as $dx){
$start = $dx['start'];
//chop off subseconds
@ -628,6 +628,8 @@ class Schedule {
$playlists[$pkey]['played'] = '0';
$playlists[$pkey]['schedule_id'] = $dx['group_id'];
$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]['id'] = $dx['group_id'];
$playlists[$pkey]['start'] = Schedule::AirtimeTimeToPypoTime($dx["start"]);

View File

@ -136,9 +136,13 @@ class Show {
$uncheckedDaysImploded = implode(",", $p_uncheckedDays);
$showId = $this->getId();
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$sql = "DELETE FROM cc_show_instances"
." WHERE EXTRACT(DOW FROM starts) IN ($uncheckedDaysImploded)"
." AND starts > current_timestamp "
." AND starts > TIMESTAMP '$timestamp'"
." AND show_id = $showId";
$CC_DBC->query($sql);
@ -177,6 +181,14 @@ class Show {
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()
{
global $CC_DBC;
@ -199,6 +211,14 @@ class Show {
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()
{
global $CC_DBC;
@ -272,42 +292,76 @@ class Show {
return $endDate;
}
}
/**
* Deletes all future instances of the current show object
* from the show_instances table.
*
*/
public function deleteAllInstances(){
global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$showId = $this->getId();
$sql = "DELETE FROM cc_show_instances "
."WHERE starts > current_timestamp "
."AND show_id = $showId";
$sql = "DELETE FROM cc_show_instances"
." WHERE starts > TIMESTAMP '$timestamp'"
." AND show_id = $showId";
$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){
global $CC_DBC;
$showId = $this->getId();
$sql = "DELETE FROM cc_show_instances "
."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;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$showId = $this->getId();
$sql = "DELETE FROM cc_show_instances "
."WHERE date(starts) < DATE '$p_date' "
."AND starts > current_timestamp "
."AND show_id = $showId";
." WHERE date(starts) > DATE '$p_date'"
." AND starts > TIMESTAMP '$timestamp'"
." 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);
}
/**
* Get the start date of the current show.
*
* @return string
* The start date in the format YYYY-MM-DD
*/
public function getStartDate(){
global $CC_DBC;
@ -323,7 +377,13 @@ class Show {
return $firstDate;
}
}
/**
* Get the start time of the current show.
*
* @return string
* The start time in the format HH:MM:SS
*/
public function getStartTime(){
global $CC_DBC;
@ -339,14 +399,23 @@ class Show {
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(){
global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$showId = $this->getId();
$sql = "SELECT id from cc_show_instances "
$sql = "SELECT id from cc_show_instances"
." WHERE show_id = $showId"
." AND starts > current_timestamp";
." AND starts > TIMESTAMP '$timestamp'";
$rows = $CC_DBC->GetAll($sql);
@ -361,6 +430,9 @@ class Show {
//need to update cc_show_instances, cc_show_days
global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$sql = "UPDATE cc_show_days "
."SET duration = '$p_data[add_show_duration]' "
@ -370,7 +442,7 @@ class Show {
$sql = "UPDATE cc_show_instances "
."SET ends = starts + INTERVAL '$p_data[add_show_duration]' "
."WHERE show_id = $p_data[add_show_id] "
."AND starts > current_timestamp";
."AND starts > TIMESTAMP '$timestamp'";
$CC_DBC->query($sql);
}
@ -379,6 +451,9 @@ class Show {
//need to update cc_schedule, cc_show_instances, cc_show_days
global $CC_DBC;
$date = new DateHelper;
$timestamp = $date->getTimestamp();
$sql = "UPDATE cc_show_days "
."SET start_time = TIME '$p_data[add_show_start_time]', "
@ -399,7 +474,7 @@ class Show {
."SET starts = starts + INTERVAL '$diff sec', "
."ends = ends + INTERVAL '$diff sec' "
."WHERE show_id = $p_data[add_show_id] "
."AND starts > current_timestamp";
."AND starts > TIMESTAMP '$timestamp'";
$CC_DBC->query($sql);
$showInstanceIds = $this->getAllFutureInstanceIds();
@ -656,7 +731,7 @@ class Show {
//adding rows to cc_show_rebroadcast
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]) {
$showRebroad = new CcShowRebroadcast();
@ -668,16 +743,16 @@ class Show {
}
} 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]) {
$sql = "SELECT date '{$data['add_show_rebroadcast_absolute_date_'.$i]}' - date '{$data['add_show_start_date']}' ";
if ($data['add_show_rebroadcast_date_absolute_'.$i]) {
$sql = "SELECT date '{$data['add_show_rebroadcast_date_absolute_'.$i]}' - date '{$data['add_show_start_date']}' ";
$r = $con->query($sql);
$offset_days = $r->fetchColumn(0);
$showRebroad = new CcShowRebroadcast();
$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->save();
}

View File

@ -5,18 +5,24 @@
</dt>
<dd id="add_show_rebroadcast_day-element" class="block-display clearfix">
<ul class="formrow-repeat">
<?php for($i=1; $i<=5; $i++): ?>
<li>
<?php echo $this->element->getElement('add_show_rebroadcast_absolute_date_'.$i) ?>
<?php for($i=1; $i<=10; $i++): ?>
<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_date_absolute_'.$i) ?>
<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>
<?php if(($this->element->getElement('add_show_rebroadcast_absolute_date_'.$i)->hasErrors())
|| ($this->element->getElement('add_show_rebroadcast_absolute_time_'.$i)->hasErrors())) : ?>
<?php if(($this->element->getElement('add_show_rebroadcast_date_absolute_'.$i)->hasErrors())
|| ($this->element->getElement('add_show_rebroadcast_time_absolute_'.$i)->hasErrors())) : ?>
<ul class='errors'>
<?php $errors = array_merge(
$this->element->getElement('add_show_rebroadcast_absolute_date_'.$i)->getMessages(),
$this->element->getElement('add_show_rebroadcast_absolute_time_'.$i)->getMessages()
$this->element->getElement('add_show_rebroadcast_date_absolute_'.$i)->getMessages(),
$this->element->getElement('add_show_rebroadcast_time_absolute_'.$i)->getMessages()
);
?>
@ -27,6 +33,10 @@
<?php endif; ?>
<?php endfor; ?>
</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>
</dl>
</fieldset>

View File

@ -4,30 +4,40 @@
<label for="add_show_rebroadcast_repeat_day" class="optional">Repeat Days:</label>
</dt>
<dd id="add_show_rebroadcast_repeat_day-element" class="block-display clearfix">
<ul class="formrow-repeat">
<?php for($i=1; $i<=5; $i++): ?>
<li>
<?php echo $this->element->getElement('add_show_rebroadcast_date_'.$i) ?>
<span class="inline-text">@</span>
<?php echo $this->element->getElement('add_show_rebroadcast_time_'.$i) ?>
</li>
<ul class="formrow-repeat">
<?php for($i=1; $i<=10; $i++): ?>
<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) ?>
<span class="inline-text">@</span>
<?php echo $this->element->getElement('add_show_rebroadcast_time_'.$i) ?>
<?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())
|| ($this->element->getElement('add_show_rebroadcast_time_'.$i)->hasErrors())) : ?>
<ul class='errors'>
<?php $errors = array_merge(
$this->element->getElement('add_show_rebroadcast_date_'.$i)->getMessages(),
$this->element->getElement('add_show_rebroadcast_time_'.$i)->getMessages()
);
?>
<?php if(($this->element->getElement('add_show_rebroadcast_date_'.$i)->hasErrors())
|| ($this->element->getElement('add_show_rebroadcast_time_'.$i)->hasErrors())) : ?>
<ul class='errors'>
<?php $errors = array_merge(
$this->element->getElement('add_show_rebroadcast_date_'.$i)->getMessages(),
$this->element->getElement('add_show_rebroadcast_time_'.$i)->getMessages()
);
?>
<?php foreach($errors as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endfor; ?>
</ul>
<?php foreach($errors as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endfor; ?>
</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>
</dl>
</fieldset>

View File

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

View File

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

View File

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

View File

@ -150,14 +150,55 @@ function setAddShowEvents() {
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(),
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: ['', ''],
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({
source: findHosts,
@ -166,7 +207,7 @@ function setAddShowEvents() {
});
form.find("#schedule-show-style input").ColorPicker({
onChange: function (hsb, hex, rgb, el) {
onChange: function (hsb, hex, rgb, el) {
$(el).val(hex);
},
onSubmit: function(hsb, hex, rgb, el) {
@ -186,9 +227,18 @@ function setAddShowEvents() {
var y = $("#schedule_calendar").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();
$.get("/Schedule/get-form", {format:"json"}, function(json){
$("#add-show-form")
.empty()
.append(json.form);
setAddShowEvents();
});
makeAddShowButton();
});
@ -197,7 +247,8 @@ function setAddShowEvents() {
var addShowButton = $(this);
if (!addShowButton.hasClass("disabled")){
addShowButton.addClass("disabled");
} else {
}
else {
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>')
.find('span.fc-button:last > a')
.click(function(){
openAddShowForm();
var span = $(this).parent();
$(span).prev().remove();
$(span).remove();
openAddShowForm();
removeAddShowButton();
});
}
function beginEditShow(data){
//alert (data.entries);
function removeAddShowButton(){
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")
.empty()
.append(data.newForm);
removeAddShowButton();
setAddShowEvents();
openAddShowForm();
}

View File

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

View File

@ -85,7 +85,7 @@ function updateProgressBarValue(){
songPercentDone = 0;
currentSong = new Array();
} 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");
else
$('#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):
logger = logging.getLogger('fetch')
self.schedule = schedule_data["playlists"]
playlists = schedule_data["playlists"]
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
try:
playlists = self.prepare_playlists()
liquidsoap_playlists = self.prepare_playlists(playlists)
except Exception, e: logger.error("%s", e)
# Send the data to pypo-push
scheduled_data = dict()
scheduled_data['playlists'] = playlists
scheduled_data['schedule'] = self.schedule
scheduled_data['liquidsoap_playlists'] = liquidsoap_playlists
scheduled_data['schedule'] = playlists
scheduled_data['stream_metadata'] = schedule_data["stream_metadata"]
self.queue.put(scheduled_data)
@ -141,23 +141,22 @@ class PypoFetch(Thread):
and stored in a playlist folder.
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')
schedule = self.schedule
playlists = dict()
liquidsoap_playlists = dict()
# Dont do anything if schedule is empty
if not schedule:
# Dont do anything if playlists is empty
if not playlists:
logger.debug("Schedule is empty.")
return playlists
return liquidsoap_playlists
scheduleKeys = sorted(schedule.iterkeys())
scheduleKeys = sorted(playlists.iterkeys())
try:
for pkey in scheduleKeys:
logger.info("Playlist starting at %s", pkey)
playlist = schedule[pkey]
playlist = playlists[pkey]
# create playlist directory
try:
@ -181,10 +180,10 @@ class PypoFetch(Thread):
elif int(playlist['subtype']) > 0 and int(playlist['subtype']) < 5:
ls_playlist = self.handle_media_file(playlist, pkey)
playlists[pkey] = ls_playlist
liquidsoap_playlists[pkey] = ls_playlist
except Exception, 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_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):
self.export_source = export_source
self.cache_dir = config["cache_dir"] + self.export_source + '/'
@ -67,14 +71,13 @@ class PypoPush(Thread):
scheduled_data = self.queue.get()
logger.debug("Received data from pypo-fetch")
self.schedule = scheduled_data['schedule']
self.playlists = scheduled_data['playlists']
self.playlists = scheduled_data['liquidsoap_playlists']
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
playlists = self.playlists
logger.debug('schedule %s' % json.dumps(schedule))
logger.debug('playlists %s' % json.dumps(playlists))
currently_on_air = False
if schedule:
@ -92,9 +95,7 @@ class PypoPush(Thread):
for pkey in schedule:
plstart = pkey[0:19]
start = schedule[pkey]['start']
end = schedule[pkey]['end']
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):
@ -120,21 +121,23 @@ class PypoPush(Thread):
# Call API to update schedule states
logger.debug("Doing callback to server to update 'played' status.")
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
else:
pass
#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.write('source.skip\n')
tn.write('exit\n')
tn.read_all()
self.liquidsoap_state_play = False
def push_liquidsoap(self, pkey, schedule, playlists):
logger = logging.getLogger('push')
@ -185,6 +188,8 @@ class PypoPush(Thread):
tn.write("exit\n")
logger.debug(tn.read_all())
self.liquidsoap_state_play = True
status = 1
except Exception, e:
logger.error('%s', e)