AddShowAbsoluteRebroadcastDates.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. class Application_Form_AddShowAbsoluteRebroadcastDates extends Zend_Form_SubForm
  3. {
  4. public function init()
  5. {
  6. $this->setDecorators(array(
  7. array('ViewScript', array('viewScript' => 'form/add-show-rebroadcast-absolute.phtml'))
  8. ));
  9. for ($i=1; $i<=10; $i++) {
  10. $text = new Zend_Form_Element_Text("add_show_rebroadcast_date_absolute_$i");
  11. $text->setAttrib('class', 'input_text');
  12. $text->addFilter('StringTrim');
  13. $text->addValidator('date', false, array('YYYY-MM-DD'));
  14. $text->setRequired(false);
  15. $text->setDecorators(array('ViewHelper'));
  16. $this->addElement($text);
  17. $text = new Zend_Form_Element_Text("add_show_rebroadcast_time_absolute_$i");
  18. $text->setAttrib('class', 'input_text');
  19. $text->addFilter('StringTrim');
  20. $text->addValidator('date', false, array('HH:mm'));
  21. $text->addValidator('regex', false, array('/^[0-2]?[0-9]:[0-5][0-9]$/', 'messages' => _('Invalid character entered')));
  22. $text->setRequired(false);
  23. $text->setDecorators(array('ViewHelper'));
  24. $this->addElement($text);
  25. }
  26. }
  27. public function disable()
  28. {
  29. $elements = $this->getElements();
  30. foreach ($elements as $element) {
  31. if ($element->getType() != 'Zend_Form_Element_Hidden') {
  32. $element->setAttrib('disabled','disabled');
  33. }
  34. }
  35. }
  36. public function isValid($formData) {
  37. if (parent::isValid($formData)) {
  38. return $this->checkReliantFields($formData);
  39. } else {
  40. return false;
  41. }
  42. }
  43. public function checkReliantFields($formData)
  44. {
  45. $noError = true;
  46. for ($i=1; $i<=10; $i++) {
  47. $valid = true;
  48. $day = $formData['add_show_rebroadcast_date_absolute_'.$i];
  49. $time = $formData['add_show_rebroadcast_time_absolute_'.$i];
  50. if (trim($day) == "" && trim($time) == "") {
  51. continue;
  52. }
  53. if (trim($day) == "") {
  54. $this->getElement('add_show_rebroadcast_date_absolute_'.$i)->setErrors(array(_("Day must be specified")));
  55. $valid = false;
  56. }
  57. if (trim($time) == "") {
  58. $this->getElement('add_show_rebroadcast_time_absolute_'.$i)->setErrors(array(_("Time must be specified")));
  59. $valid = false;
  60. }
  61. if ($valid === false) {
  62. $noError = false;
  63. continue;
  64. }
  65. $show_start_time = $formData['add_show_start_date']." ".$formData['add_show_start_time'];
  66. $show_end = new DateTime($show_start_time);
  67. $duration = $formData['add_show_duration'];
  68. $duration = explode(":", $duration);
  69. $show_end->add(new DateInterval("PT$duration[0]H"));
  70. $show_end->add(new DateInterval("PT$duration[1]M"));
  71. $show_end->add(new DateInterval("PT1H"));//min time to wait until a rebroadcast
  72. $rebroad_start = $day." ".$formData['add_show_rebroadcast_time_absolute_'.$i];
  73. $rebroad_start = new DateTime($rebroad_start);
  74. if ($rebroad_start < $show_end) {
  75. $this->getElement('add_show_rebroadcast_time_absolute_'.$i)->setErrors(array(_("Must wait at least 1 hour to rebroadcast")));
  76. $valid = false;
  77. $noError = false;
  78. }
  79. }
  80. return $noError;
  81. }
  82. }