/** * 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; }
/** * Set the to date for this period. * * @param string $dateTo * End date to set. */ public function setDateTo($dateTo) { CultureFeed_Cdb_Data_Calendar::validateDate($dateTo); $this->dateTo = $dateTo; }
/** * Appends the current object to the passed DOM tree. * * @param DOMElement $element * The DOM tree to append to. * @param string $cdbScheme * The cdb schema version. * * @see CultureFeed_Cdb_IElement::appendToDOM() */ public function appendToDOM(DOMElement $element, $cdbScheme = '3.2') { $dom = $element->ownerDocument; $eventElement = $dom->createElement('event'); if ($this->ageFrom) { $eventElement->appendChild($dom->createElement('agefrom', $this->ageFrom)); } if ($this->availableFrom) { $eventElement->setAttribute('availablefrom', $this->availableFrom); } if ($this->availableTo) { $eventElement->setAttribute('availableto', $this->availableTo); } if ($this->cdbId) { $eventElement->setAttribute('cdbid', $this->cdbId); } if ($this->createdBy) { $eventElement->setAttribute('createdby', $this->createdBy); } if ($this->creationDate) { $eventElement->setAttribute('creationdate', $this->creationDate); } if ($this->externalId) { $eventElement->setAttribute('externalid', $this->externalId); } if (isset($this->isParent)) { $eventElement->setAttribute('isparent', $this->isParent ? 'true' : 'false'); } if (isset($this->lastUpdated)) { $eventElement->setAttribute('lastupdated', $this->lastUpdated); } if (isset($this->lastUpdatedBy)) { $eventElement->setAttribute('lastupdatedby', $this->lastUpdatedBy); } if (isset($this->owner)) { $eventElement->setAttribute('owner', $this->owner); } if (isset($this->pctComplete)) { $eventElement->setAttribute('pctcomplete', $this->pctComplete); } if (isset($this->private)) { $eventElement->setAttribute('private', $this->private ? 'true' : 'false'); } if (isset($this->published)) { $eventElement->setAttribute('published', $this->published ? 'true' : 'false'); } if (isset($this->validator)) { $eventElement->setAttribute('validator', $this->validator); } if (isset($this->wfStatus)) { $eventElement->setAttribute('wfstatus', $this->wfStatus); } if ($this->publisher) { $eventElement->setAttribute('publisher', $this->publisher); } if ($this->calendar) { $this->calendar->appendToDOM($eventElement); } if ($this->categories) { $this->categories->appendToDOM($eventElement); } if ($this->contactInfo) { $this->contactInfo->appendToDOM($eventElement); } if ($this->details) { $this->details->appendToDOM($eventElement); } if (count($this->keywords) > 0) { $keywordsElement = $dom->createElement('keywords'); if (version_compare($cdbScheme, '3.3', '>=')) { foreach ($this->keywords as $keyword) { $keyword->appendToDOM($keywordsElement); } $eventElement->appendChild($keywordsElement); } else { $keywords = array(); foreach ($this->keywords as $keyword) { $keywords[$keyword->getValue()] = $keyword->getValue(); } $keywordsElement->appendChild($dom->createTextNode(implode(';', $keywords))); $eventElement->appendChild($keywordsElement); } } if (isset($this->languages)) { $this->languages->appendToDOM($eventElement); } if ($this->location) { $this->location->appendToDOM($eventElement); } if ($this->organiser) { $this->organiser->appendToDOM($eventElement); } if ($this->maxParticipants) { $eventElement->appendChild($dom->createElement('maxparticipants', $this->maxParticipants)); } if ($this->bookingPeriod) { $this->bookingPeriod->appendToDOM($eventElement); } if (!empty($this->relations)) { $relationsElement = $dom->createElement('eventrelations'); foreach ($this->relations as $relation) { $relationElement = $dom->createElement('relatedproduction'); $relationElement->appendChild($dom->createTextNode($relation->getTitle())); $relationElement->setAttribute('cdbid', $relation->getCdbid()); $externalId = $relation->getExternalId(); if ($externalId) { $relationElement->setAttribute('externalid', $relation->getExternalId()); } $relationsElement->appendChild($relationElement); } $eventElement->appendChild($relationsElement); } $element->appendChild($eventElement); }
/** * 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; }
/** * 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); } }