Example #1
0
 public function getDatetimeObject($data = null)
 {
     $dateObj = new SocialFieldsEventStartendObject();
     if (empty($data)) {
         return $dateObj;
     }
     $dateObj->load($data);
     return $dateObj;
 }
Example #2
0
 private function onValidate(&$post)
 {
     $value = $this->getRecurringValue($post[$this->inputName]);
     if ($value->type !== 'none' && empty($value->end)) {
         $this->setError(JText::_('FIELD_EVENT_RECURRING_VALIDATION_END_DATE_REQUIRED'));
         return false;
     }
     if ($value->type === 'none') {
         return true;
     }
     $endDatetime = !empty($post['endDatetime']) ? $post['endDatetime'] : '';
     $endDatetimeObj = new SocialFieldsEventStartendObject();
     $endDatetimeObj->load($endDatetime);
     $recurringEnd = FD::date($value->end);
     // Check if the end recur date is more than the event end date
     if ($recurringEnd->toUnix() < $endDatetimeObj->toUnix()) {
         $this->setError(JText::_('FIELD_EVENT_RECURRING_VALIDATION_INVALID_END_DATE'));
         return false;
     }
     // If max is set to 0 then we don need to validate
     $max = FD::config()->get('events.recurringlimit', 0);
     if (empty($max) || $max == 0) {
         return true;
     }
     $startDatetime = !empty($post['startDatetime']) ? $post['startDatetime'] : '';
     $startDatetimeObj = new SocialFieldsEventStartendObject();
     $startDatetimeObj->load($startDatetime);
     $schedule = FD::model('Events')->getRecurringSchedule(array('eventStart' => $startDatetimeObj->toDate(), 'end' => $value->end, 'type' => $value->type, 'daily' => $value->daily));
     $totalRecurring = count($schedule);
     if ($totalRecurring > $max) {
         $this->setError(JText::sprintf('FIELD_EVENT_RECURRING_VALIDATION_MAX_RECURRING_LIMIT', $totalRecurring, $max));
         return false;
     }
     return true;
 }