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:
james 2011-06-03 14:53:01 -04:00
parent 143e68bd56
commit 1dabbacca2
7 changed files with 207 additions and 32 deletions

View file

@ -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,7 +543,23 @@ 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);
if($repeats) {

View file

@ -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"),
@ -21,13 +21,13 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
array('date', false, array('YYYY-MM-DD'))
)
));
// 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 duration element
$this->addElement('text', 'add_show_duration', array(
'label' => 'Duration:',
// Add end date element
$this->addElement('text', 'add_show_end_date_no_repeat', array(
'label' => 'Date/Time End:',
'class' => 'input_text',
'value' => '1:00',
'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('regex', false,
array('/^\d+:[0-5][0-9]$/',
'messages' => 'enter a duration: HH:mm'))
)
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' => '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'));
$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_id'] != -1) && $startDateModified) || ($formData['add_show_id'] == -1)){
if($start_epoch < $now_epoch) {
$this->getElement('add_show_start_date')->setErrors(array('Cannot create show in the past'));
$valid = false;
}
}
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;
}

View file

@ -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);
}

View file

@ -433,6 +433,45 @@ class Show {
return $startTime;
}
}
/**
* 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
@ -535,9 +574,14 @@ class Show {
}
}
public function getDuration(){
public function getDuration($format=false){
$showDay = CcShowDaysQuery::create()->filterByDbShowId($this->getId())->findOne();
return $showDay->getDbDuration();
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(){