CC-2116 : Add Extra Form Validation For Rebroadcasts

can only schedule rebroadcast shows an hour after original broadcast or later.

zend date validator passes '09:0f' which it shouldn't...
This commit is contained in:
naomiaro 2011-04-01 18:18:32 -04:00
parent 7a49137edd
commit 132c78453a
6 changed files with 148 additions and 15 deletions

View File

@ -355,6 +355,10 @@ class ScheduleController extends Zend_Controller_Action
$data['add_show_hosts'] = $this->_getParam('hosts');
$data['add_show_day_check'] = $this->_getParam('days');
if($data['add_show_day_check'] == "") {
$data['add_show_day_check'] = null;
}
$formWhat = new Application_Form_AddShowWhat();
$formWho = new Application_Form_AddShowWho();
$formWhen = new Application_Form_AddShowWhen();
@ -389,20 +393,40 @@ class ScheduleController extends Zend_Controller_Action
}
if($data["add_show_repeats"]) {
$repeats = $formRepeats->isValid($data);
if($repeats) {
$repeats = $formRepeats->checkReliantFields($data);
}
$formAbsoluteRebroadcast->reset();
//make it valid, results don't matter anyways.
$rebroadAb = 1;
if ($data["add_show_rebroadcast"]) {
$rebroad = $formRebroadcast->isValid($data);
if($rebroad) {
$rebroad = $formRebroadcast->checkReliantFields($data);
}
}
}
else {
$repeats = 1; //make it valid, results don't matter anyways.
$formRebroadcast->reset();
//make it valid, results don't matter anyways.
$repeats = 1;
$rebroad = 1;
if ($data["add_show_rebroadcast"]) {
$rebroadAb = $formAbsoluteRebroadcast->isValid($data);
if($rebroadAb) {
$rebroadAb = $formAbsoluteRebroadcast->checkReliantFields($data);
}
}
}
$who = $formWho->isValid($data);
$style = $formStyle->isValid($data);
$record = $formRecord->isValid($data);
$rebroadAb = $formAbsoluteRebroadcast->isValid($data);
$rebroad = $formRebroadcast->isValid($data);
$record = $formRecord->isValid($data);
if ($what && $when && $repeats && $who && $style && $record && $rebroadAb && $rebroad) {
@ -421,6 +445,7 @@ class ScheduleController extends Zend_Controller_Action
'add_show_duration' => '1:00'));
$formRepeats->reset();
$formRepeats->populate(array('add_show_end_date' => date("Y-m-d")));
$formStyle->reset();
$formRecord->reset();
$formAbsoluteRebroadcast->reset();

View File

@ -178,6 +178,38 @@ class Application_Form_AddShowAbsoluteRebroadcastDates extends Zend_Form_SubForm
}
public function checkReliantFields($formData) {
$valid = true;
for($i=1; $i<=5; $i++) {
$day = $formData['add_show_rebroadcast_absolute_date_'.$i];
if($day == "") {
continue;
}
$show_start_time = $formData['add_show_start_date']."".$formData['add_show_start_time'];
$show_end = new DateTime($show_start_time);
$duration = $formData['add_show_duration'];
$duration = explode(":", $duration);
$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 = 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"));
$valid = false;
}
}
return $valid;
}
}

View File

@ -141,5 +141,43 @@ class Application_Form_AddShowRebroadcastDates extends Zend_Form_SubForm
)
));
}
public function checkReliantFields($formData) {
$valid = true;
for($i=1; $i<=5; $i++) {
$days = $formData['add_show_rebroadcast_date_'.$i];
if($days == "") {
continue;
}
$days = explode(" ", $days);
$day = $days[0];
$show_start_time = $formData['add_show_start_date']."".$formData['add_show_start_time'];
$show_end = new DateTime($show_start_time);
$duration = $formData['add_show_duration'];
$duration = explode(":", $duration);
$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"));
if($rebroad_start < $show_end) {
$this->getElement('add_show_rebroadcast_time_'.$i)->setErrors(array("Must wait at least 1 hour to rebroadcast"));
$valid = false;
}
}
return $valid;
}
}

View File

@ -1,4 +1,4 @@
<fieldset>
<fieldset id="add_show_rebroadcast_absolute">
<dl>
<dt id="add_show_hosts_rebroadcast_day-label" class="block-display">
<label for="add_show_rebroadcast_day" class="optional">Choose Days:</label>
@ -10,10 +10,21 @@
<?php echo $this->element->getElement('add_show_rebroadcast_absolute_date_'.$i) ?>
<span class="inline-text">@</span>
<?php echo $this->element->getElement('add_show_rebroadcast_absolute_time_'.$i) ?>
<?php if($this->element->getElement('add_show_rebroadcast_absolute_time_'.$i)->hasErrors()) : ?>
<?php echo var_dump($this->element->getElement('add_show_rebroadcast_absolute_time_'.$i)->getMessages()); ?>
<?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())) : ?>
<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()
);
?>
<?php foreach($errors as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endfor; ?>
</ul>
</dd>

View File

@ -1,4 +1,4 @@
<fieldset>
<fieldset id="add_show_rebroadcast_relative">
<dl>
<dt id="add_show_hosts_rebroadcast_repeat_day-label" class="block-display">
<label for="add_show_rebroadcast_repeat_day" class="optional">Repeat Days:</label>
@ -11,6 +11,21 @@
<span class="inline-text">@</span>
<?php echo $this->element->getElement('add_show_rebroadcast_time_'.$i) ?>
</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 foreach($errors as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endfor; ?>
</ul>
</dd>

View File

@ -64,6 +64,10 @@ function setAddShowEvents() {
if(!form.find("#add_show_repeats").attr('checked')) {
form.find("#schedule-show-when > fieldset:last").hide();
$("#add_show_rebroadcast_relative").hide();
}
else {
$("#add_show_rebroadcast_absolute").hide();
}
if(!form.find("#add_show_record").attr('checked')) {
@ -82,12 +86,12 @@ function setAddShowEvents() {
if(form.find("#add_show_rebroadcast").attr('checked')) {
if($(this).attr('checked')){
form.find("#schedule-record-rebroadcast > fieldset:eq(1)").hide();
form.find("#schedule-record-rebroadcast > fieldset:last").show();
form.find("#add_show_rebroadcast_absolute").hide();
form.find("#add_show_rebroadcast_relative").show();
}
else {
form.find("#schedule-record-rebroadcast > fieldset:eq(1)").show();
form.find("#schedule-record-rebroadcast > fieldset:last").hide();
form.find("#add_show_rebroadcast_absolute").show();
form.find("#add_show_rebroadcast_relative").hide();
}
}
});
@ -100,10 +104,10 @@ function setAddShowEvents() {
form.find("#add_show_rebroadcast").click(function(){
$(this).blur();
if($(this).attr('checked') && !form.find("#add_show_repeats").attr('checked')) {
form.find("#schedule-record-rebroadcast > fieldset:eq(1)").show();
form.find("#add_show_rebroadcast_absolute").show();
}
else if($(this).attr('checked') && form.find("#add_show_repeats").attr('checked')) {
form.find("#schedule-record-rebroadcast > fieldset:last").show();
form.find("#add_show_rebroadcast_relative").show();
}
else {
form.find("#schedule-record-rebroadcast > fieldset:not(:first-child)").hide();
@ -248,6 +252,14 @@ function showErrorSections() {
if($("#schedule-show-style .errors").length > 0) {
$("#schedule-show-style").show();
}
if($("#add_show_rebroadcast_absolute .errors").length > 0) {
$("#schedule-record-rebroadcast").show();
$("#add_show_rebroadcast_absolute").show();
}
if($("#add_show_rebroadcast_relative .errors").length > 0) {
$("#schedule-record-rebroadcast").show();
$("#add_show_rebroadcast_relative").show();
}
}
$(document).ready(function() {