AddShowRepeats.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. class Application_Form_AddShowRepeats extends Zend_Form_SubForm
  3. {
  4. public function init()
  5. {
  6. $linked = new Zend_Form_Element_Checkbox("add_show_linked");
  7. $linked->setLabel(_("Link:"));
  8. $this->addElement($linked);
  9. //Add type select
  10. $this->addElement('select', 'add_show_repeat_type', array(
  11. 'required' => true,
  12. 'label' => _('Repeat Type:'),
  13. 'class' => ' input_select',
  14. 'multiOptions' => array(
  15. "0" => _("weekly"),
  16. "1" => _("every 2 weeks"),
  17. "4" => _("every 3 weeks"),
  18. "5" => _("every 4 weeks"),
  19. "2" => _("monthly")
  20. ),
  21. ));
  22. // Add days checkboxes
  23. $this->addElement(
  24. 'multiCheckbox',
  25. 'add_show_day_check',
  26. array(
  27. 'label' => _('Select Days:'),
  28. 'required' => false,
  29. 'multiOptions' => array(
  30. "0" => _("Sun"),
  31. "1" => _("Mon"),
  32. "2" => _("Tue"),
  33. "3" => _("Wed"),
  34. "4" => _("Thu"),
  35. "5" => _("Fri"),
  36. "6" => _("Sat"),
  37. ),
  38. ));
  39. $repeatMonthlyType = new Zend_Form_Element_Radio("add_show_monthly_repeat_type");
  40. $repeatMonthlyType
  41. ->setLabel(_("Repeat By:"))
  42. ->setRequired(true)
  43. ->setMultiOptions(
  44. array(2 => _("day of the month"), 3 => _("day of the week")))
  45. ->setValue(2);
  46. $this->addElement($repeatMonthlyType);
  47. // Add end date element
  48. $this->addElement('text', 'add_show_end_date', array(
  49. 'label' => _('Date End:'),
  50. 'class' => 'input_text',
  51. 'value' => date("Y-m-d"),
  52. 'required' => false,
  53. 'filters' => array('StringTrim'),
  54. 'validators' => array(
  55. 'NotEmpty',
  56. array('date', false, array('YYYY-MM-DD'))
  57. )
  58. ));
  59. // Add no end element
  60. $this->addElement('checkbox', 'add_show_no_end', array(
  61. 'label' => _('No End?'),
  62. 'required' => false,
  63. 'checked' => true,
  64. ));
  65. }
  66. public function disable()
  67. {
  68. $elements = $this->getElements();
  69. foreach ($elements as $element) {
  70. if ($element->getType() != 'Zend_Form_Element_Hidden') {
  71. $element->setAttrib('disabled','disabled');
  72. }
  73. }
  74. }
  75. public function isValid($formData) {
  76. if (parent::isValid($formData)) {
  77. return $this->checkReliantFields($formData);
  78. } else {
  79. return false;
  80. }
  81. }
  82. public function checkReliantFields($formData)
  83. {
  84. if (!$formData['add_show_no_end']) {
  85. $start_timestamp = $formData['add_show_start_date'];
  86. $end_timestamp = $formData['add_show_end_date'];
  87. $showTimeZone = new DateTimeZone($formData['add_show_timezone']);
  88. //We're assuming all data is valid at this point (timezone, etc.).
  89. $startDate = new DateTime($start_timestamp, $showTimeZone);
  90. $endDate = new DateTime($end_timestamp, $showTimeZone);
  91. if ($endDate < $startDate) {
  92. $this->getElement('add_show_end_date')->setErrors(array(_('End date must be after start date')));
  93. return false;
  94. }
  95. return true;
  96. }
  97. if (!isset($formData['add_show_day_check'])) {
  98. $this->getElement('add_show_day_check')->setErrors(array(_('Please select a repeat day')));
  99. }
  100. return true;
  101. }
  102. }