2011-01-21 00:30:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
|
|
|
{
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
2011-10-05 18:22:54 +02:00
|
|
|
$this->setDecorators(array(
|
|
|
|
array('ViewScript', array('viewScript' => 'form/add-show-when.phtml'))
|
|
|
|
));
|
|
|
|
|
2011-06-27 20:37:31 +02:00
|
|
|
// Add start date element
|
|
|
|
$startDate = new Zend_Form_Element_Text('add_show_start_date');
|
|
|
|
$startDate->class = 'input_text';
|
|
|
|
$startDate->setRequired(true)
|
|
|
|
->setLabel('Date/Time Start:')
|
|
|
|
->setValue(date("Y-m-d"))
|
|
|
|
->setFilters(array('StringTrim'))
|
|
|
|
->setValidators(array(
|
|
|
|
'NotEmpty',
|
|
|
|
array('date', false, array('YYYY-MM-DD'))))
|
2011-10-05 18:22:54 +02:00
|
|
|
->setDecorators(array('ViewHelper'));
|
2011-10-03 22:43:32 +02:00
|
|
|
$startDate->setAttrib('alt', 'date');
|
2011-06-27 20:37:31 +02:00
|
|
|
$this->addElement($startDate);
|
2011-06-03 20:53:01 +02:00
|
|
|
|
2011-06-27 20:37:31 +02:00
|
|
|
// Add start time element
|
|
|
|
$startTime = new Zend_Form_Element_Text('add_show_start_time');
|
|
|
|
$startTime->class = 'input_text';
|
|
|
|
$startTime->setRequired(true)
|
|
|
|
->setValue('00:00')
|
|
|
|
->setFilters(array('StringTrim'))
|
|
|
|
->setValidators(array(
|
|
|
|
'NotEmpty',
|
|
|
|
array('date', false, array('HH:mm')),
|
2012-04-25 18:02:06 +02:00
|
|
|
array('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => 'Time format should be HH:mm'))
|
2012-04-25 15:19:15 +02:00
|
|
|
))->setDecorators(array('ViewHelper'));
|
2011-10-03 22:43:32 +02:00
|
|
|
$startTime->setAttrib('alt', 'time');
|
2011-06-27 20:37:31 +02:00
|
|
|
$this->addElement($startTime);
|
2011-01-21 00:30:53 +01:00
|
|
|
|
2011-06-03 20:53:01 +02:00
|
|
|
// Add end date element
|
2011-06-27 20:37:31 +02:00
|
|
|
$endDate = new Zend_Form_Element_Text('add_show_end_date_no_repeat');
|
|
|
|
$endDate->class = 'input_text';
|
|
|
|
$endDate->setRequired(true)
|
|
|
|
->setLabel('Date/Time End:')
|
|
|
|
->setValue(date("Y-m-d"))
|
|
|
|
->setFilters(array('StringTrim'))
|
|
|
|
->setValidators(array(
|
|
|
|
'NotEmpty',
|
|
|
|
array('date', false, array('YYYY-MM-DD'))))
|
2011-10-05 18:22:54 +02:00
|
|
|
->setDecorators(array('ViewHelper'));
|
2011-10-03 22:43:32 +02:00
|
|
|
$endDate->setAttrib('alt', 'date');
|
2011-06-27 20:37:31 +02:00
|
|
|
$this->addElement($endDate);
|
2011-06-03 20:53:01 +02:00
|
|
|
|
|
|
|
// Add end time element
|
2011-06-27 20:37:31 +02:00
|
|
|
$endTime = new Zend_Form_Element_Text('add_show_end_time');
|
|
|
|
$endTime->class = 'input_text';
|
|
|
|
$endTime->setRequired(true)
|
|
|
|
->setValue('01:00')
|
|
|
|
->setFilters(array('StringTrim'))
|
|
|
|
->setValidators(array(
|
|
|
|
'NotEmpty',
|
|
|
|
array('date', false, array('HH:mm')),
|
2012-04-25 18:07:58 +02:00
|
|
|
array('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => 'Time format should be HH:mm'))))
|
2011-10-05 18:22:54 +02:00
|
|
|
->setDecorators(array('ViewHelper'));
|
2011-10-03 22:43:32 +02:00
|
|
|
$endTime->setAttrib('alt', 'time');
|
2011-06-27 20:37:31 +02:00
|
|
|
$this->addElement($endTime);
|
2011-06-03 20:53:01 +02:00
|
|
|
|
|
|
|
// Add duration element
|
|
|
|
$this->addElement('text', 'add_show_duration', array(
|
2012-05-28 22:46:22 +02:00
|
|
|
'label' => 'Duration:',
|
2011-06-03 20:53:01 +02:00
|
|
|
'class' => 'input_text',
|
2012-05-28 22:46:22 +02:00
|
|
|
'value' => '01h 00m',
|
|
|
|
'readonly' => true,
|
2011-10-05 18:22:54 +02:00
|
|
|
'decorators' => array('ViewHelper')
|
2011-01-21 00:30:53 +01:00
|
|
|
));
|
|
|
|
|
2012-05-28 22:46:22 +02:00
|
|
|
// Add repeats element
|
|
|
|
$this->addElement('checkbox', 'add_show_repeats', array(
|
2011-04-04 19:50:51 +02:00
|
|
|
'label' => 'Repeats?',
|
2011-01-21 00:30:53 +01:00
|
|
|
'required' => false,
|
2012-05-28 22:46:22 +02:00
|
|
|
'decorators' => array('ViewHelper')
|
|
|
|
));
|
2011-01-21 00:30:53 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-05 00:58:22 +02:00
|
|
|
public function checkReliantFields($formData, $validateStartDate, $originalStartDate=null, $update=false, $instanceId=null) {
|
2011-01-31 03:42:53 +01:00
|
|
|
$valid = true;
|
2011-10-05 18:22:54 +02:00
|
|
|
|
2011-08-15 20:22:33 +02:00
|
|
|
$start_time = $formData['add_show_start_date']." ".$formData['add_show_start_time'];
|
2012-06-07 18:25:21 +02:00
|
|
|
$end_time = $formData['add_show_end_date_no_repeat']." ".$formData['add_show_end_time'];
|
2011-08-15 20:22:33 +02:00
|
|
|
|
|
|
|
//DateTime stores $start_time in the current timezone
|
|
|
|
$nowDateTime = new DateTime();
|
|
|
|
$showStartDateTime = new DateTime($start_time);
|
2012-06-07 18:25:21 +02:00
|
|
|
$showEndDateTime = new DateTime($end_time);
|
2012-05-28 22:46:22 +02:00
|
|
|
if ($validateStartDate){
|
|
|
|
if($showStartDateTime->getTimestamp() < $nowDateTime->getTimestamp()) {
|
|
|
|
$this->getElement('add_show_start_time')->setErrors(array('Cannot create show in the past'));
|
|
|
|
$valid = false;
|
|
|
|
}
|
2012-06-07 00:23:27 +02:00
|
|
|
// if edit action, check if original show start time is in the past. CC-3864
|
|
|
|
if($originalStartDate){
|
|
|
|
if($originalStartDate->getTimestamp() < $nowDateTime->getTimestamp()) {
|
2012-06-07 18:14:22 +02:00
|
|
|
$this->getElement('add_show_start_time')->setValue($originalStartDate->format("H:i"));
|
|
|
|
$this->getElement('add_show_start_date')->setValue($originalStartDate->format("Y-m-d"));
|
2012-06-07 00:23:27 +02:00
|
|
|
$this->getElement('add_show_start_time')->setErrors(array('Cannot modify start date/time of the show that is already started'));
|
|
|
|
$this->disableStartDateAndTime();
|
|
|
|
$valid = false;
|
|
|
|
}
|
|
|
|
}
|
2012-05-28 22:46:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-07 18:25:21 +02:00
|
|
|
// if end time is in the past, return error
|
|
|
|
if($showEndDateTime->getTimestamp() < $nowDateTime->getTimestamp()) {
|
|
|
|
$this->getElement('add_show_end_time')->setErrors(array('End date/time cannot be in the past'));
|
|
|
|
$valid = false;
|
|
|
|
}
|
|
|
|
|
2012-06-06 16:31:49 +02:00
|
|
|
$pattern = '/([0-9][0-9])h ([0-9][0-9])m/';
|
2012-06-08 17:39:04 +02:00
|
|
|
|
|
|
|
if (preg_match($pattern, $formData['add_show_duration'], $matches) && count($matches) == 3) {
|
|
|
|
$hours = $matches[1];
|
|
|
|
$minutes = $matches[2];
|
|
|
|
if( $formData["add_show_duration"] == "00h 00m" ) {
|
|
|
|
$this->getElement('add_show_duration')->setErrors(array('Cannot have duration 00h 00m'));
|
|
|
|
$valid = false;
|
|
|
|
}elseif(strpos($formData["add_show_duration"], 'h') !== false && $hours >= 24) {
|
|
|
|
if ($hours > 24 || ($hours == 24 && $minutes > 0)) {
|
|
|
|
$this->getElement('add_show_duration')->setErrors(array('Cannot have duration greater than 24h'));
|
|
|
|
$valid = false;
|
|
|
|
}
|
|
|
|
}elseif( strstr($formData["add_show_duration"], '-') ){
|
|
|
|
$this->getElement('add_show_duration')->setErrors(array('Cannot have duration < 0m'));
|
2012-05-28 22:46:22 +02:00
|
|
|
$valid = false;
|
|
|
|
}
|
2012-06-08 17:39:04 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-06-06 18:49:52 +02:00
|
|
|
$valid = false;
|
2011-01-28 23:37:31 +01:00
|
|
|
}
|
2011-04-04 19:50:51 +02:00
|
|
|
|
2012-07-04 17:34:18 +02:00
|
|
|
/* Check if show is overlapping
|
|
|
|
* We will only do this check if the show is valid
|
|
|
|
* upto this point
|
|
|
|
*/
|
|
|
|
if ($valid) {
|
|
|
|
$show_start = new DateTime($start_time);
|
2012-07-05 00:58:22 +02:00
|
|
|
$show_start->setTimezone(new DateTimeZone('UTC'));
|
2012-07-04 17:34:18 +02:00
|
|
|
$show_end = new DateTime($end_time);
|
2012-07-05 00:58:22 +02:00
|
|
|
$show_end->setTimezone(new DateTimeZone('UTC'));
|
|
|
|
|
|
|
|
$overlapping = Application_Model_Schedule::checkOverlappingShows($show_start, $show_end, $update, $instanceId);
|
2012-07-04 17:34:18 +02:00
|
|
|
if ($overlapping) {
|
2012-07-05 17:33:03 +02:00
|
|
|
$this->getElement('add_show_duration')->setErrors(array('Cannot schedule overlapping shows'));
|
2012-07-04 17:34:18 +02:00
|
|
|
$valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-31 03:42:53 +01:00
|
|
|
return $valid;
|
2011-01-28 23:37:31 +01:00
|
|
|
}
|
2012-03-30 21:11:24 +02:00
|
|
|
|
|
|
|
public function disable(){
|
|
|
|
$elements = $this->getElements();
|
|
|
|
foreach ($elements as $element)
|
|
|
|
{
|
|
|
|
if ($element->getType() != 'Zend_Form_Element_Hidden')
|
|
|
|
{
|
2012-04-05 22:01:27 +02:00
|
|
|
$element->setAttrib('disabled','disabled');
|
2012-03-30 21:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-04 20:53:26 +02:00
|
|
|
|
|
|
|
public function disableRepeatCheckbox(){
|
|
|
|
$element = $this->getElement('add_show_repeats');
|
|
|
|
if ($element->getType() != 'Zend_Form_Element_Hidden')
|
|
|
|
{
|
2012-04-05 22:01:27 +02:00
|
|
|
$element->setAttrib('disabled','disabled');
|
2012-04-04 20:53:26 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-16 22:48:04 +02:00
|
|
|
|
|
|
|
public function disableStartDateAndTime(){
|
|
|
|
$elements = array($this->getElement('add_show_start_date'), $this->getElement('add_show_start_time'));
|
|
|
|
foreach ($elements as $element)
|
|
|
|
{
|
|
|
|
if ($element->getType() != 'Zend_Form_Element_Hidden')
|
|
|
|
{
|
|
|
|
$element->setAttrib('disabled','disabled');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-21 00:30:53 +01:00
|
|
|
}
|
|
|
|
|