diff --git a/application/Bootstrap.php b/application/Bootstrap.php index 277bd9cab..511ab92e3 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -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; diff --git a/application/controllers/ApiController.php b/application/controllers/ApiController.php index 1b0e8ac51..4c6e344d2 100644 --- a/application/controllers/ApiController.php +++ b/application/controllers/ApiController.php @@ -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), diff --git a/application/controllers/ScheduleController.php b/application/controllers/ScheduleController.php index f713dc8cd..bbbf5e05f 100644 --- a/application/controllers/ScheduleController.php +++ b/application/controllers/ScheduleController.php @@ -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'); diff --git a/application/forms/AddShowAbsoluteRebroadcastDates.php b/application/forms/AddShowAbsoluteRebroadcastDates.php index 7d173df2a..bb3c79125 100644 --- a/application/forms/AddShowAbsoluteRebroadcastDates.php +++ b/application/forms/AddShowAbsoluteRebroadcastDates.php @@ -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; } } diff --git a/application/forms/AddShowRebroadcastDates.php b/application/forms/AddShowRebroadcastDates.php index 22e28a1a3..e51bcf570 100644 --- a/application/forms/AddShowRebroadcastDates.php +++ b/application/forms/AddShowRebroadcastDates.php @@ -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; } } diff --git a/application/models/DateHelper.php b/application/models/DateHelper.php index d0f56f647..97b7d9ae9 100644 --- a/application/models/DateHelper.php +++ b/application/models/DateHelper.php @@ -1,6 +1,6 @@ _timestamp); } diff --git a/application/models/Nowplaying.php b/application/models/Nowplaying.php index 7536f1044..6df81c310 100644 --- a/application/models/Nowplaying.php +++ b/application/models/Nowplaying.php @@ -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); } } diff --git a/application/models/Schedule.php b/application/models/Schedule.php index 0fb1468e0..4f2b4cd8d 100644 --- a/application/models/Schedule.php +++ b/application/models/Schedule.php @@ -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"]); diff --git a/application/models/Shows.php b/application/models/Shows.php index 6be170dd9..9cf1123c0 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -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(); } diff --git a/application/views/scripts/form/add-show-rebroadcast-absolute.phtml b/application/views/scripts/form/add-show-rebroadcast-absolute.phtml index d235a6ae9..ae0977bc9 100644 --- a/application/views/scripts/form/add-show-rebroadcast-absolute.phtml +++ b/application/views/scripts/form/add-show-rebroadcast-absolute.phtml @@ -5,18 +5,24 @@
diff --git a/application/views/scripts/form/add-show-rebroadcast.phtml b/application/views/scripts/form/add-show-rebroadcast.phtml index 44ae45b0c..e3cf4962f 100644 --- a/application/views/scripts/form/add-show-rebroadcast.phtml +++ b/application/views/scripts/form/add-show-rebroadcast.phtml @@ -4,30 +4,40 @@
- + + + Add +
diff --git a/application/views/scripts/schedule/edit-show.phtml b/application/views/scripts/schedule/edit-show.phtml index 03bf357a5..bf01724e3 100644 --- a/application/views/scripts/schedule/edit-show.phtml +++ b/application/views/scripts/schedule/edit-show.phtml @@ -1,2 +1 @@ -entries; +//left empty on purpose diff --git a/application/views/scripts/schedule/get-form.phtml b/application/views/scripts/schedule/get-form.phtml new file mode 100644 index 000000000..bf01724e3 --- /dev/null +++ b/application/views/scripts/schedule/get-form.phtml @@ -0,0 +1 @@ +//left empty on purpose diff --git a/install/include/AirtimeInstall.php b/install/include/AirtimeInstall.php index 847fc2a45..c31db8e1e 100644 --- a/install/include/AirtimeInstall.php +++ b/install/include/AirtimeInstall.php @@ -1,7 +1,8 @@ getMessage().PHP_EOL; echo $CC_DBC->getUserInfo().PHP_EOL; diff --git a/public/js/airtime/schedule/add-show.js b/public/js/airtime/schedule/add-show.js index b2449a608..2bc224686 100644 --- a/public/js/airtime/schedule/add-show.js +++ b/public/js/airtime/schedule/add-show.js @@ -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; } diff --git a/public/js/airtime/schedule/full-calendar-functions.js b/public/js/airtime/schedule/full-calendar-functions.js index dadb46839..1bb3d50ea 100644 --- a/public/js/airtime/schedule/full-calendar-functions.js +++ b/public/js/airtime/schedule/full-calendar-functions.js @@ -25,21 +25,26 @@ function makeAddShowButton(){ .append('Show') .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(); } diff --git a/public/js/playlist/nowplayingdatagrid.js b/public/js/playlist/nowplayingdatagrid.js index 33e077a19..cbb25c1e4 100644 --- a/public/js/playlist/nowplayingdatagrid.js +++ b/public/js/playlist/nowplayingdatagrid.js @@ -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; diff --git a/public/js/playlist/playlist.js b/public/js/playlist/playlist.js index a72e94dc2..eff1dfc42 100644 --- a/public/js/playlist/playlist.js +++ b/public/js/playlist/playlist.js @@ -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"); diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index aada900ff..224d256ee 100755 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -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 """ diff --git a/python_apps/pypo/pypopush.py b/python_apps/pypo/pypopush.py index af207651a..573770694 100755 --- a/python_apps/pypo/pypopush.py +++ b/python_apps/pypo/pypopush.py @@ -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)