sintonia/legacy/application/forms/AddShowAbsoluteRebroadcastD...

102 lines
3.5 KiB
PHP
Raw Permalink Normal View History

<?php
class Application_Form_AddShowAbsoluteRebroadcastDates extends Zend_Form_SubForm
{
public function init()
{
2021-10-11 16:10:47 +02:00
$this->setDecorators([
['ViewScript', ['viewScript' => 'form/add-show-rebroadcast-absolute.phtml']],
]);
2021-10-11 16:10:47 +02:00
for ($i = 1; $i <= 10; ++$i) {
$text = new Zend_Form_Element_Text("add_show_rebroadcast_date_absolute_{$i}");
$text->setAttrib('class', 'input_text');
$text->addFilter('StringTrim');
2021-10-11 16:10:47 +02:00
$text->addValidator('date', false, ['YYYY-MM-DD']);
$text->setRequired(false);
2021-10-11 16:10:47 +02:00
$text->setDecorators(['ViewHelper']);
$this->addElement($text);
2021-10-11 16:10:47 +02:00
$text = new Zend_Form_Element_Text("add_show_rebroadcast_time_absolute_{$i}");
$text->setAttrib('class', 'input_text');
$text->addFilter('StringTrim');
2021-10-11 16:10:47 +02:00
$text->addValidator('date', false, ['HH:mm']);
$text->addValidator('regex', false, ['/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Invalid character entered')]);
$text->setRequired(false);
2021-10-11 16:10:47 +02:00
$text->setDecorators(['ViewHelper']);
$this->addElement($text);
}
}
public function disable()
{
$elements = $this->getElements();
foreach ($elements as $element) {
if ($element->getType() != 'Zend_Form_Element_Hidden') {
2021-10-11 16:10:47 +02:00
$element->setAttrib('disabled', 'disabled');
}
}
}
2021-10-11 16:10:47 +02:00
public function isValid($formData)
{
if (parent::isValid($formData)) {
2021-10-11 16:10:47 +02:00
return $this->checkReliantFields($formData);
}
2021-10-11 16:10:47 +02:00
return false;
}
public function checkReliantFields($formData)
{
$noError = true;
2021-10-11 16:10:47 +02:00
for ($i = 1; $i <= 10; ++$i) {
2011-04-15 17:13:42 +02:00
$valid = true;
2021-10-11 16:10:47 +02:00
$day = $formData['add_show_rebroadcast_date_absolute_' . $i];
$time = $formData['add_show_rebroadcast_time_absolute_' . $i];
2021-10-11 16:10:47 +02:00
if (trim($day) == '' && trim($time) == '') {
continue;
}
2021-10-11 16:10:47 +02:00
if (trim($day) == '') {
$this->getElement('add_show_rebroadcast_date_absolute_' . $i)->setErrors([_('Day must be specified')]);
$valid = false;
}
2021-10-11 16:10:47 +02:00
if (trim($time) == '') {
$this->getElement('add_show_rebroadcast_time_absolute_' . $i)->setErrors([_('Time must be specified')]);
$valid = false;
}
if ($valid === false) {
$noError = false;
2021-10-11 16:10:47 +02:00
2011-04-15 17:13:42 +02:00
continue;
}
2021-10-11 16:10:47 +02:00
$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'];
2021-10-11 16:10:47 +02:00
$duration = explode(':', $duration);
2021-10-11 16:10:47 +02:00
$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
2021-10-11 16:10:47 +02:00
$rebroad_start = $day . ' ' . $formData['add_show_rebroadcast_time_absolute_' . $i];
$rebroad_start = new DateTime($rebroad_start);
if ($rebroad_start < $show_end) {
2021-10-11 16:10:47 +02:00
$this->getElement('add_show_rebroadcast_time_absolute_' . $i)->setErrors([_('Must wait at least 1 hour to rebroadcast')]);
$valid = false;
$noError = false;
}
}
return $noError;
}
}