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')),
|
|
|
|
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))))
|
2011-10-05 18:22:54 +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')),
|
|
|
|
array('regex', false, array('/^[0-9:]+$/', 'messages' => 'Invalid character entered'))))
|
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(
|
|
|
|
'label' => 'Duration:',
|
|
|
|
'class' => 'input_text',
|
|
|
|
'value' => '01h00m',
|
2011-10-05 18:22:54 +02:00
|
|
|
'readonly' => true,
|
|
|
|
'decorators' => array('ViewHelper')
|
2011-01-21 00:30:53 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
// Add repeats element
|
2011-01-21 19:25:12 +01:00
|
|
|
$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,
|
2011-10-05 18:22:54 +02:00
|
|
|
'decorators' => array('ViewHelper')
|
2011-01-21 00:30:53 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-11 22:45:03 +02:00
|
|
|
public function checkReliantFields($formData, $validateStartDate) {
|
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'];
|
|
|
|
|
|
|
|
//DateTime stores $start_time in the current timezone
|
|
|
|
$nowDateTime = new DateTime();
|
|
|
|
$showStartDateTime = new DateTime($start_time);
|
2011-01-31 03:42:53 +01:00
|
|
|
|
2012-04-11 22:45:03 +02:00
|
|
|
if ($validateStartDate){
|
2011-08-15 20:22:33 +02:00
|
|
|
if($showStartDateTime->getTimestamp() < $nowDateTime->getTimestamp()) {
|
2011-06-27 20:37:31 +02:00
|
|
|
$this->getElement('add_show_start_time')->setErrors(array('Cannot create show in the past'));
|
2011-06-03 20:53:01 +02:00
|
|
|
$valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $formData["add_show_duration"] == "0m" ) {
|
|
|
|
$this->getElement('add_show_duration')->setErrors(array('Cannot have duration 0m'));
|
|
|
|
$valid = false;
|
2011-06-27 21:59:29 +02:00
|
|
|
}elseif(strpos($formData["add_show_duration"], 'h') !== false && intval(substr($formData["add_show_duration"], 0, strpos($formData["add_show_duration"], 'h'))) > 24) {
|
|
|
|
$this->getElement('add_show_duration')->setErrors(array('Cannot have duration greater than 24h'));
|
2011-01-31 03:42:53 +01:00
|
|
|
$valid = false;
|
2011-06-06 18:49:52 +02:00
|
|
|
}elseif( strstr($formData["add_show_duration"], '-') ){
|
|
|
|
$this->getElement('add_show_duration')->setErrors(array('Cannot have duration < 0m'));
|
|
|
|
$valid = false;
|
2011-01-28 23:37:31 +01:00
|
|
|
}
|
2011-04-04 19:50:51 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2011-01-21 00:30:53 +01:00
|
|
|
}
|
|
|
|
|