CC-2289:Differentiate between time and duration
- End date and time is added - duration field is readonly now and is autocalculated - now playing duration field format is changed( 0h 0m 0s ) - removed millisecond from start and end time in now playing
This commit is contained in:
parent
143e68bd56
commit
1dabbacca2
7 changed files with 207 additions and 32 deletions
|
@ -423,7 +423,9 @@ class ScheduleController extends Zend_Controller_Action
|
|||
|
||||
$formWhen->populate(array('add_show_start_date' => $show->getStartDate(),
|
||||
'add_show_start_time' => DateHelper::removeSecondsFromTime($show->getStartTime()),
|
||||
'add_show_duration' => $show->getDuration(),
|
||||
'add_show_end_date_no_repeat' => $show->getEndDate(),
|
||||
'add_show_end_time' => DateHelper::removeSecondsFromTime($show->getEndTime()),
|
||||
'add_show_duration' => $show->getDuration(true),
|
||||
'add_show_repeats' => $show->isRepeating() ? 1 : 0));
|
||||
|
||||
if ($show->isStartDateTimeInPast()){
|
||||
|
@ -541,6 +543,22 @@ class ScheduleController extends Zend_Controller_Action
|
|||
if($when) {
|
||||
$when = $formWhen->checkReliantFields($data, $startDateModified);
|
||||
}
|
||||
// format add_show_duration value to hh:mm so it can be compatible with
|
||||
// existing code
|
||||
$hPos = strpos($data["add_show_duration"], 'h');
|
||||
$mPos = strpos($data["add_show_duration"], 'm');
|
||||
|
||||
$hValue = 0;
|
||||
$mValue = 0;
|
||||
|
||||
if($hPos !== false){
|
||||
$hValue = trim(substr($data["add_show_duration"], 0, $hPos));
|
||||
}
|
||||
if($mPos !== false){
|
||||
$mValue = trim(substr($data["add_show_duration"], $hPos+1, -1 ));
|
||||
}
|
||||
|
||||
$data["add_show_duration"] = $hValue.":".$mValue;
|
||||
|
||||
if($data["add_show_repeats"]) {
|
||||
$repeats = $formRepeats->isValid($data);
|
||||
|
|
|
@ -11,7 +11,7 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
|||
|
||||
// Add start date element
|
||||
$this->addElement('text', 'add_show_start_date', array(
|
||||
'label' => 'Date Start:',
|
||||
'label' => 'Date/Time Start:',
|
||||
'class' => 'input_text',
|
||||
'required' => true,
|
||||
'value' => date("Y-m-d"),
|
||||
|
@ -23,11 +23,11 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
|||
));
|
||||
|
||||
// Add start time element
|
||||
$this->addElement('text', 'add_show_start_time', array(
|
||||
'label' => 'Start Time:',
|
||||
$startTime = $this->addElement('text', 'add_show_start_time', array(
|
||||
'decorators' => array('ViewHelper', array('HtmlTag', array('tag'=>'dd'))),
|
||||
'class' => 'input_text',
|
||||
'required' => true,
|
||||
'value' => '0:00',
|
||||
'value' => '00:00',
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
'NotEmpty',
|
||||
|
@ -36,19 +36,40 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
|||
)
|
||||
));
|
||||
|
||||
// Add end date element
|
||||
$this->addElement('text', 'add_show_end_date_no_repeat', array(
|
||||
'label' => 'Date/Time End:',
|
||||
'class' => 'input_text',
|
||||
'required' => true,
|
||||
'value' => date("Y-m-d"),
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('YYYY-MM-DD'))
|
||||
)
|
||||
));
|
||||
|
||||
// Add end time element
|
||||
$this->addElement('text', 'add_show_end_time', array(
|
||||
'decorators' => array('ViewHelper', array('HtmlTag', array('tag'=>'dd'))),
|
||||
'class' => 'input_text',
|
||||
'required' => true,
|
||||
'value' => '01:00',
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
'NotEmpty',
|
||||
array('date', false, array('HH:mm')),
|
||||
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))
|
||||
)
|
||||
|
||||
));
|
||||
|
||||
// Add duration element
|
||||
$this->addElement('text', 'add_show_duration', array(
|
||||
'label' => 'Duration:',
|
||||
'class' => 'input_text',
|
||||
'value' => '1:00',
|
||||
'required' => true,
|
||||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
'NotEmpty',
|
||||
array('regex', false,
|
||||
array('/^\d+:[0-5][0-9]$/',
|
||||
'messages' => 'enter a duration: HH:mm'))
|
||||
)
|
||||
'value' => '01h00m',
|
||||
'readonly' => true
|
||||
));
|
||||
|
||||
// Add repeats element
|
||||
|
@ -69,15 +90,19 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
|||
$now_epoch = strtotime($now_timestamp);
|
||||
$start_epoch = strtotime($start_timestamp);
|
||||
|
||||
|
||||
if ((($formData['add_show_id'] != -1) && $startDateModified) || ($formData['add_show_id'] == -1)){
|
||||
if($start_epoch < $now_epoch) {
|
||||
$this->getElement('add_show_start_time')->setErrors(array('Cannot create show in the past'));
|
||||
$this->getElement('add_show_start_date')->setErrors(array('Cannot create show in the past'));
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(strtotime("00:00") == strtotime($formData["add_show_duration"])) {
|
||||
$this->getElement('add_show_duration')->setErrors(array('Cannot have duration 00:00'));
|
||||
if( $formData["add_show_duration"] == "0m" ) {
|
||||
$this->getElement('add_show_duration')->setErrors(array('Cannot have duration 0m'));
|
||||
$valid = false;
|
||||
}elseif(strpos($formData["add_show_duration"], 'h') !== false && intval(substr($formData["add_show_duration"], 0, strpos($formData["add_show_duration"], 'h'))) > 23) {
|
||||
$this->getElement('add_show_duration')->setErrors(array('Cannot have duration > 24h'));
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,17 @@ class Application_Model_Nowplaying
|
|||
$type = "a";
|
||||
$type .= ($dbRow['item_ends'] > $timeNow && $dbRow['item_starts'] <= $timeNow) ? "c" : "";
|
||||
|
||||
$dataTablesRows[] = array($type, $dbRow['show_starts'], $dbRow['item_starts'], $dbRow['item_ends'],
|
||||
$dbRow['clip_length'], $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'],
|
||||
// remove millisecond from the time format
|
||||
$itemStart = explode('.', $dbRow['item_starts']);
|
||||
$itemEnd = explode('.', $dbRow['item_ends']);
|
||||
|
||||
//format duration
|
||||
$duration = explode('.', $dbRow['clip_length']);
|
||||
$duration = explode(':', $duration[0]);
|
||||
$duration = $duration[0].'h'.$duration[1].'m'.$duration[2].'s';
|
||||
|
||||
$dataTablesRows[] = array($type, $dbRow['show_starts'], $itemStart[0], $itemEnd[0],
|
||||
$duration, $dbRow['track_title'], $dbRow['artist_name'], $dbRow['album_title'],
|
||||
$dbRow['playlist_name'], $dbRow['show_name'], $status);
|
||||
}
|
||||
|
||||
|
|
|
@ -434,6 +434,45 @@ class Show {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end date of the current show.
|
||||
* Note that this is not the end date of repeated show
|
||||
*
|
||||
* @return string
|
||||
* The end date in the format YYYY-MM-DD
|
||||
*/
|
||||
public function getEndDate(){
|
||||
$startDate = $this->getStartDate();
|
||||
$startTime = $this->getStartTime();
|
||||
$duration = $this->getDuration();
|
||||
|
||||
$startDateTime = new DateTime($startDate.' '.$startTime);
|
||||
$duration = explode(":", $duration);
|
||||
|
||||
$endDate = $startDateTime->add(new DateInterval('PT'.$duration[0].'H'.$duration[1].'M'));
|
||||
|
||||
return $endDate->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end time of the current show.
|
||||
*
|
||||
* @return string
|
||||
* The start time in the format HH:MM:SS
|
||||
*/
|
||||
public function getEndTime(){
|
||||
$startDate = $this->getStartDate();
|
||||
$startTime = $this->getStartTime();
|
||||
$duration = $this->getDuration();
|
||||
|
||||
$startDateTime = new DateTime($startDate.' '.$startTime);
|
||||
$duration = explode(":", $duration);
|
||||
|
||||
$endDate = $startDateTime->add(new DateInterval('PT'.$duration[0].'H'.$duration[1].'M'));
|
||||
|
||||
return $endDate->format('H:i:s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate whether the starting point of the show is in the
|
||||
* past.
|
||||
|
@ -535,9 +574,14 @@ class Show {
|
|||
}
|
||||
}
|
||||
|
||||
public function getDuration(){
|
||||
public function getDuration($format=false){
|
||||
$showDay = CcShowDaysQuery::create()->filterByDbShowId($this->getId())->findOne();
|
||||
if(!$format){
|
||||
return $showDay->getDbDuration();
|
||||
}else{
|
||||
$info = explode(':',$showDay->getDbDuration());
|
||||
return ($info[0] != 0 ? intval($info[0]).'h'.' ' : '').($info[1] != 0 ? intval($info[1]).'m' : '');
|
||||
}
|
||||
}
|
||||
|
||||
public function getShowDays(){
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
margin: 0;
|
||||
padding: 4px 0;
|
||||
text-align: left;
|
||||
min-width:90px;
|
||||
min-width:100px;
|
||||
clear:left;
|
||||
}
|
||||
#schedule-add-show dt.big {
|
||||
|
@ -111,3 +111,12 @@ label.wrapp-label input[type="checkbox"] {
|
|||
min-width: 150px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#add_show_start_time {
|
||||
float: left;
|
||||
}
|
||||
|
||||
#add_show_duration {
|
||||
background: #AAAAAA;
|
||||
cursor: default;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ function startDpSelect(dateText, inst) {
|
|||
|
||||
$("#add_show_end_date").datepicker("option", "minDate", date);
|
||||
$('input[name^="add_show_rebroadcast_absolute_date"]').datepicker("option", "minDate", date);
|
||||
if (inst.input)
|
||||
inst.input.trigger('change');
|
||||
}
|
||||
|
||||
function endDpSelect(dateText, inst) {
|
||||
|
@ -22,6 +24,8 @@ function endDpSelect(dateText, inst) {
|
|||
date = new Date(time[0], time[1] - 1, time[2]);
|
||||
|
||||
$("#add_show_start_date").datepicker( "option", "maxDate", date);
|
||||
if (inst.input)
|
||||
inst.input.trigger('change');
|
||||
}
|
||||
|
||||
function createDateInput(el, onSelect) {
|
||||
|
@ -158,14 +162,15 @@ function setAddShowEvents() {
|
|||
form.find("#add_show_no_end").click(endDateVisibility);
|
||||
|
||||
createDateInput(form.find("#add_show_start_date"), startDpSelect);
|
||||
createDateInput(form.find("#add_show_end_date_no_repeat"), endDpSelect);
|
||||
createDateInput(form.find("#add_show_end_date"), endDpSelect);
|
||||
|
||||
form.find("#add_show_start_time").timepicker({
|
||||
amPmText: ['', '']
|
||||
});
|
||||
form.find("#add_show_duration").timepicker({
|
||||
amPmText: ['', ''],
|
||||
defaultTime: '01:00'
|
||||
defaultTime: '00:00'
|
||||
});
|
||||
form.find("#add_show_end_time").timepicker({
|
||||
amPmText: ['', '']
|
||||
});
|
||||
|
||||
form.find('input[name^="add_show_rebroadcast_date_absolute"]').datepicker({
|
||||
|
@ -312,6 +317,50 @@ function setAddShowEvents() {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
// auto puplate end date and time
|
||||
$('#add_show_start_time, #add_show_start_date, #add_show_end_date_no_repeat, #add_show_end_time').change(function(){
|
||||
var startDate = $('#add_show_start_date').val().split('-');
|
||||
var startDateTime = new Date(startDate[1]+' '+startDate[2]+','+startDate[0]+' '+$('#add_show_start_time').val());
|
||||
|
||||
var endDate = $('#add_show_end_date_no_repeat').val().split('-');
|
||||
var endDateTime = new Date(endDate[1]+' '+endDate[2]+','+endDate[0]+' '+$('#add_show_end_time').val());
|
||||
|
||||
// if changed start time is greater than end, set end time to start time + 1 hour
|
||||
if(startDateTime.getTime() > endDateTime.getTime()){
|
||||
endDateTime = new Date(startDateTime.getTime() + (1*60*60*1000));
|
||||
}
|
||||
|
||||
var endDate = endDateTime.getFullYear() + '-' + pad(endDateTime.getMonth()+1,2) + '-' + pad(endDateTime.getDate(),2);
|
||||
var endTime = pad(endDateTime.getHours(),2) + ':' + pad(endDateTime.getMinutes(),2);
|
||||
|
||||
$('#add_show_end_date_no_repeat').val(endDate);
|
||||
$('#add_show_end_time').val(endTime);
|
||||
|
||||
// calculate duration
|
||||
calculateDuration(endDateTime, startDateTime)
|
||||
})
|
||||
|
||||
function calculateDuration(endDateTime, startDateTime){
|
||||
var duration;
|
||||
var durationSeconds = (endDateTime.getTime() - startDateTime.getTime())/1000;
|
||||
if(durationSeconds != 0){
|
||||
var durationHour = parseInt(durationSeconds/3600);
|
||||
var durationMin = parseInt((durationSeconds%3600)/60);
|
||||
duration = (durationHour == 0 ? '' : durationHour+'h'+' ')+(durationMin == 0 ? '' : durationMin+'m');
|
||||
}else{
|
||||
duration = '0m';
|
||||
}
|
||||
$('#add_show_duration').val(duration);
|
||||
}
|
||||
function pad(number, length) {
|
||||
var str = '' + number;
|
||||
while (str.length < length) {
|
||||
str = '0' + str;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
function showErrorSections() {
|
||||
|
|
|
@ -110,10 +110,31 @@ function dayClick(date, allDay, jsEvent, view) {
|
|||
chosenTime = hours+":"+min;
|
||||
}
|
||||
|
||||
if(hours < 10){
|
||||
chosenTime = "0"+chosenTime;
|
||||
}
|
||||
|
||||
var endHour = hours + 1;
|
||||
var chosenEndTime;
|
||||
|
||||
if(min < 10){
|
||||
chosenEndTime = endHour+":0"+min;
|
||||
}
|
||||
else {
|
||||
chosenEndTime = endHour+":"+min;
|
||||
}
|
||||
|
||||
if(endHour < 10){
|
||||
chosenEndTime = "0"+chosenEndTime;
|
||||
}
|
||||
|
||||
$("#add_show_start_date").val(chosenDate);
|
||||
$("#add_show_end_date_no_repeat").val(chosenDate);
|
||||
$("#add_show_end_date").datepicker("option", "minDate", chosenDate);
|
||||
$("#add_show_end_date").val(chosenDate);
|
||||
$("#add_show_start_time").val(chosenTime);
|
||||
$("#add_show_end_time").val(chosenEndTime);
|
||||
$("#add_show_duration").val('1h');
|
||||
$("#schedule-show-when").show();
|
||||
|
||||
openAddShowForm();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue