/** * Set the end time from the timestamp. * * @param string $time * End time to set. */ public function setEndTime($time) { CultureFeed_Cdb_Data_Calendar::validateTime($time); $this->endTime = $time; }
/** * Set the open till time. * * @param string $openTill * Open till time to set. */ public function setOpenTill($openTill) { CultureFeed_Cdb_Data_Calendar::validateTime($openTill); $this->openTill = $openTill; }
/** * Validate the event form. */ function watersportkampen_bootstrap_event_save_validate($form, &$form_state) { $values = $form_state['values']; // Validate age. if ($values['age'] && !is_numeric($values['age'])) { form_set_error('age', t('Please fill in correct age')); } // Validate period. if ($values['when']['date_control']['type'] == 'period') { $period = $values['when']['date_control']['period']; // Form validation hasn't processed the dates values yet, so don't validate. if (!is_array($period['start_date']) && !is_array($period['end_date'])) { // The dates. try { CultureFeed_Cdb_Data_Calendar::validateDate($period['start_date']); CultureFeed_Cdb_Data_Calendar::validateDate($period['end_date']); } catch (UnexpectedValueException $e) { form_set_error('when][date_control][period', t('Please fill in correct date and time')); } // Order of dates. $start_date = strtotime($period['start_date']); $end_date = strtotime($period['end_date']); if ($start_date > $end_date) { form_set_error('when][date_control][period', t('Date field is invalid. The end date is earlier than the beginning date.')); } } } // Validate timestamps. if ($values['when']['date_control']['type'] == 'timestamps') { $timestamps = $values['when']['date_control']['timestamps']['stamps']; foreach ($timestamps as $key => $timestamp) { // Form validation hasn't processed the dates values yet, so don't validate. if (is_array($timestamp['date'])) { continue; } // The date. try { CultureFeed_Cdb_Data_Calendar::validateDate($timestamp['date']); } catch (UnexpectedValueException $e) { form_set_error('when][date_control][timestamps][stamps][' . $key, t('Please fill in correct date and time')); } // The times. $start_time = isset($timestamp['start_time']) ? strtotime($timestamp['start_time']) : ''; $end_time = isset($timestamp['end_time']) ? strtotime($timestamp['end_time']) : ''; if ($start_time && $end_time && $start_time > $end_time) { form_set_error('when][date_control][timestamps][stamps][' . $key, t('Date field is invalid. The end time is earlier than the beginning time.')); } } } // Validate weekscheme. if ($values['when']['date_control']['type'] == 'period' || $values['when']['date_control']['type'] == 'permanent') { $opening_times = $values['when']['date_control']['opening_times']; // Validate the weekscheme. if (!$opening_times['all_day']) { foreach ($opening_times['days'] as $day => $opening_times) { foreach ($opening_times as $key => $opening_time) { if (!empty($opening_time['open_from']) || !empty($opening_time['open_till'])) { $parents = array('when', 'date_control', 'opening_times', 'days', $day, $key); if (substr_count($opening_time['open_from'], ':') == 1) { $opening_time['open_from'] .= ':00'; form_set_value(array('#parents' => array_merge($parents, array('open_from'))), $opening_time['open_from'], $form_state); } if (substr_count($opening_time['open_till'], ':') == 1) { $opening_time['open_till'] .= ':00'; form_set_value(array('#parents' => array_merge($parents, array('open_till'))), $opening_time['open_till'], $form_state); } try { CultureFeed_Cdb_Data_Calendar::validateTime($opening_time['open_from']); } catch (Exception $e) { form_set_error('when][date_control][opening_times][days][' . $day . '][' . $key . '][open_from', t('Please fill in correct time.')); } try { CultureFeed_Cdb_Data_Calendar::validateTime($opening_time['open_till']); } catch (Exception $e) { form_set_error('when][date_control][opening_times][days][' . $day . '][' . $key . '][open_till', t('Please fill in correct time.')); } } } } } } // Validate copyright if (!empty($values['photo']['upload']) && $values['photo']['copyright'] != 1) { form_set_error('photo', t('Please agree to the general conditions of UiTdatabank and declare that you have the necessary rights or permissions to distribute the image through UiTdatabank.')); } if (!empty($values['photo']['upload']) && empty($values['photo']['copyright_text'])) { form_set_error('photo', t('Copyright field is required.')); } // Validate location $location = culturefeed_entry_ui_location_form_validate($form, $form_state); // Validate Links $i = 0; foreach ($values['links'] as $link_data) { if (!empty($link_data['URL'])) { if (!preg_match("@^https?://@", $link_data['URL'])) { $link_data['URL'] = 'http://' . $link_data['URL']; } if (!valid_url($link_data['URL'], TRUE)) { form_set_error('links][' . $i . '][URL', t('Not a valid URL')); } } $i++; } // Validate organiser. if (!empty($values['organiser']['actor']['organiser_actor_id'])) { try { $organiser = culturefeed_search_item_load($values['organiser']['actor']['organiser_actor_id'], 'actor'); if (!$organiser) { form_set_error('organiser', t('We could not validate the organizer')); } } catch (Exception $e) { watchdog_exception('culturefeed_entry_ui', $e); form_set_error('organiser', t('We could not validate the organizer')); } } else { $organiser = NULL; } foreach ($values['wrapper'] as $extra) { if (is_array($extra)) { // Contacts if (!empty($extra['channel_input'])) { //if mail is selected if ($extra['channel'] == 1) { if (!valid_email_address($extra['channel_input'])) { form_set_error('channel_input', t('Not a valid email address')); } } } } } $errors = form_get_errors(); if (empty($errors)) { _watersportkampen_bootstrap_event_form_save_event($form, $form_state, $location, $organiser); } }