Пример #1
0
 /**
  * @see CultureFeed_Cdb_IElement::parseFromCdbXml(SimpleXMLElement
  *     $xmlElement)
  *
  * @return CultureFeed_Cdb_Item_Production
  */
 public static function parseFromCdbXml(SimpleXMLElement $xmlElement)
 {
     if (empty($xmlElement->categories)) {
         throw new CultureFeed_ParseException('Categories are required for production element');
     }
     if (empty($xmlElement->productiondetails)) {
         throw new CultureFeed_ParseException('Production details are required for production element');
     }
     $attributes = $xmlElement->attributes();
     $production = new CultureFeed_Cdb_Item_Production();
     // Set ID.
     if (isset($attributes['cdbid'])) {
         $production->setCdbId((string) $attributes['cdbid']);
     }
     if (isset($attributes['externalid'])) {
         $production->setExternalId((string) $attributes['externalid']);
     }
     if (isset($event_attributes['availablefrom'])) {
         $production->setAvailableFrom((string) $event_attributes['availablefrom']);
     }
     if (isset($event_attributes['availableto'])) {
         $production->setAvailableTo((string) $event_attributes['availableto']);
     }
     if (isset($event_attributes['createdby'])) {
         $production->setCreatedBy((string) $event_attributes['createdby']);
     }
     if (isset($event_attributes['creationdate'])) {
         $production->setCreationDate((string) $event_attributes['creationdate']);
     }
     if (!empty($xmlElement->agefrom)) {
         $production->setAgeFrom((int) $xmlElement->agefrom);
     }
     // Set organiser.
     if (!empty($xmlElement->organiser)) {
         $production->setOrganiser(CultureFeed_Cdb_Data_Organiser::parseFromCdbXml($xmlElement->organiser));
     }
     // Set categories
     $production->setCategories(CultureFeed_Cdb_Data_CategoryList::parseFromCdbXml($xmlElement->categories));
     // Set production details.
     $production->setDetails(CultureFeed_Cdb_Data_ProductionDetailList::parseFromCdbXml($xmlElement->productiondetails));
     // Set max participants.
     if (!empty($xmlElement->maxparticipants)) {
         $production->setMaxParticipants((int) $xmlElement->maxparticipants);
     }
     // Set booking period.
     if (!empty($xmlElement->bookingperiod)) {
         $production->setBookingPeriod(CultureFeed_Cdb_Data_Calendar_BookingPeriod::parseFromCdbXml($xmlElement->bookingperiod));
     }
     // Set the related events for this production.
     if (!empty($xmlElement->relatedevents) && isset($xmlElement->relatedevents->id)) {
         foreach ($xmlElement->relatedevents->id as $relatedItem) {
             $attributes = $relatedItem->attributes();
             $production->addRelation(new CultureFeed_Cdb_Item_Reference((string) $attributes['cdbid']));
         }
     }
     // Set the keywords.
     self::parseKeywords($xmlElement, $production);
     return $production;
 }
Пример #2
0
 public function testCreateCdbXMLGuideExample6Dot2()
 {
     $event = new CultureFeed_Cdb_Item_Event();
     $event->setAvailableFrom('2010-02-25T00:00:00');
     $event->setAvailableTo('2010-08-09T00:00:00');
     $event->setCdbId('ea37cae2-c91e-4810-89ab-e060432d2b78');
     $event->setCreatedBy('mverdoodt');
     $event->setCreationDate('2010-07-05T18:28:18');
     $event->setExternalId('SKB Import:SKB00001_216413');
     $event->setIsParent(FALSE);
     $event->setLastUpdated('2010-07-28T13:58:55');
     $event->setLastUpdatedBy('mverdoodt');
     $event->setOwner('SKB Import');
     $event->setPctComplete(80);
     $event->setPublished(TRUE);
     $event->setValidator('SKB');
     $event->setWfStatus('approved');
     $event->setAgeFrom(18);
     $event->setPrivate(FALSE);
     $calendar = new CultureFeed_Cdb_Data_Calendar_TimestampList();
     $calendar->add(new CultureFeed_Cdb_Data_Calendar_Timestamp('2010-08-01', '21:00:00.0000000'));
     $event->setCalendar($calendar);
     $categories = new CultureFeed_Cdb_Data_CategoryList();
     $categories->add(new CultureFeed_Cdb_Data_Category(CultureFeed_Cdb_Data_Category::CATEGORY_TYPE_EVENT_TYPE, '0.50.4.0.0', 'Concert'));
     $categories->add(new CultureFeed_Cdb_Data_Category(CultureFeed_Cdb_Data_Category::CATEGORY_TYPE_THEME, '1.8.2.0.0', 'Jazz en blues'));
     $categories->add(new CultureFeed_Cdb_Data_Category(CultureFeed_Cdb_Data_Category::CATEGORY_TYPE_PUBLICSCOPE, '6.2.0.0.0', 'Regionaal'));
     $event->setCategories($categories);
     $contactInfo = new CultureFeed_Cdb_Data_ContactInfo();
     $contactInfo->addMail(new CultureFeed_Cdb_Data_Mail('*****@*****.**', NULL, NULL));
     $contactInfo->addPhone(new CultureFeed_Cdb_Data_Phone('0487-62.22.31'));
     $url = new CultureFeed_Cdb_Data_Url('http://www.bonnefooi.be');
     $url->setMain();
     $contactInfo->addUrl($url);
     $event->setContactInfo($contactInfo);
     $details = new CultureFeed_Cdb_Data_EventDetailList();
     $detailNl = new CultureFeed_Cdb_Data_EventDetail();
     $detailNl->setLanguage('nl');
     $detailNl->setTitle('The Bonnefooi Acoustic Jam');
     $detailNl->setCalendarSummary('zo 01/08/10 om 21:00');
     $performers = new CultureFeed_Cdb_Data_PerformerList();
     $performers->add(new CultureFeed_Cdb_Data_Performer('Muzikant', 'Matt, the Englishman in Brussels'));
     $detailNl->setPerformers($performers);
     $detailNl->setLongDescription('Weggelaten voor leesbaarheid...');
     $file = new CultureFeed_Cdb_Data_File();
     $file->setMain();
     $file->setCopyright('Bonnefooi');
     $file->setHLink('http://www.bonnefooi.be/images/sized/site/images/uploads/Jeroen_Jamming-453x604.jpg');
     $file->setMediaType(CultureFeed_Cdb_Data_File::MEDIA_TYPE_IMAGEWEB);
     $file->setTitle('Jeroen Jamming');
     $detailNl->getMedia()->add($file);
     $price = new CultureFeed_Cdb_Data_Price(0);
     $price->setTitle('The Bonnefooi Acoustic Jam');
     $detailNl->setPrice($price);
     $detailNl->setShortDescription('Korte omschrijving.');
     $details->add($detailNl);
     $detailEn = new CultureFeed_Cdb_Data_EventDetail();
     $detailEn->setLanguage('en');
     $detailEn->setShortDescription('Short description.');
     $details->add($detailEn);
     $event->setDetails($details);
     // @todo Add headings.
     //$headings = array();
     $event->addKeyword('Free Jazz, Acoustisch');
     $address = new CultureFeed_Cdb_Data_Address();
     $physicalAddress = new CultureFeed_Cdb_Data_Address_PhysicalAddress();
     $physicalAddress->setCity('Brussel');
     $physicalAddress->setCountry('BE');
     $physicalAddress->setHouseNumber(8);
     $physicalAddress->setStreet('Steenstraat');
     $physicalAddress->setZip(1000);
     $address->setPhysicalAddress($physicalAddress);
     $location = new CultureFeed_Cdb_Data_Location($address);
     $location->setLabel('Café Bonnefooi');
     $location->setCdbid('920e9755-94a0-42c1-8c8c-9d17f693d0be');
     $event->setLocation($location);
     $organiser = new CultureFeed_Cdb_Data_Organiser();
     $organiser->setLabel('Café Bonnefooi');
     $event->setOrganiser($organiser);
     $languages = new CultureFeed_Cdb_Data_LanguageList();
     $languages->add(new CultureFeed_Cdb_Data_Language('Nederlands', CultureFeed_Cdb_Data_Language::TYPE_SPOKEN));
     $languages->add(new CultureFeed_Cdb_Data_Language('Frans', CultureFeed_Cdb_Data_Language::TYPE_SPOKEN));
     $event->setLanguages($languages);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $dom->preserveWhiteSpace = FALSE;
     $dom->formatOutput = TRUE;
     $dummy_element = $dom->createElementNS(CultureFeed_Cdb_Xml::namespaceUri(), 'cdbxml');
     $dom->appendChild($dummy_element);
     $event->appendToDOM($dummy_element);
     $xpath = new DOMXPath($dom);
     $items = $xpath->query('//event');
     $this->assertEquals(1, $items->length);
     $event_element = $items->item(0);
     $dom->removeChild($dummy_element);
     $dom->appendChild($event_element);
     /*$namespaceAttribute = $dom->createAttribute('xmlns');
       $namespaceAttribute->value = CultureFeed_Cdb_Xml::namespaceUri();
       $event_element->appendChild($namespaceAttribute);*/
     // @todo Put xmlns attribute first.
     $xml = $dom->saveXML();
     $sample_dom = new DOMDocument('1.0', 'UTF-8');
     $contents = file_get_contents($this->samplePath('cdbxml-guide-example-6-2.xml'));
     $contents = str_replace('xmlns="http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.2/FINAL" ', '', $contents);
     $sample_dom->preserveWhiteSpace = FALSE;
     $sample_dom->formatOutput = TRUE;
     $sample_dom->loadXML($contents);
     $sample_dom->preserveWhiteSpace = FALSE;
     $sample_dom->formatOutput = TRUE;
     $expected_xml = $sample_dom->saveXML();
     //$this->assertEquals($sample_dom->documentElement->C14N(), $dom->documentElement->C14N());
     $this->assertEquals($expected_xml, $xml);
 }
Пример #3
0
 /**
  * @see CultureFeed_Cdb_IElement::parseFromCdbXml(SimpleXMLElement $xmlElement)
  * @return CultureFeed_Cdb_Data_Organiser
  */
 public static function parseFromCdbXml(SimpleXMLElement $xmlElement)
 {
     $organiser = new CultureFeed_Cdb_Data_Organiser();
     if (empty($xmlElement->label) && empty($xmlElement->actor)) {
         //throw new CultureFeed_Cdb_ParseException("One of the required fields (actor or label) is missing for organiser element");
     }
     if (!empty($xmlElement->label)) {
         $organiser->setLabel((string) $xmlElement->label);
         $attributes = $xmlElement->label->attributes();
         if (!empty($attributes->cdbid)) {
             $organiser->setCdbid((string) $attributes->cdbid);
         }
     } elseif (!empty($xmlElement->actor)) {
         $actor = CultureFeed_Cdb_Item_Actor::parseFromCdbXml($xmlElement->actor);
         $organiser->setActor($actor);
     }
     return $organiser;
 }
Пример #4
0
 /**
  * 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);
 }
Пример #5
0
 /**
  * @param \CultureFeed_Cdb_Data_Organiser|\CultureFeed_Cdb_Data_Location $item
  * @throws \EgoCore\Error\Exception
  */
 private function completeActor($item)
 {
     if ($item && !$item->getActor() && ($actorCdbId = $item->getCdbid())) {
         if (isset($actorCache[$actorCdbId])) {
             $actor = $actorCache[$actorCdbId];
         } else {
             if ($actor = $this->getActor($actorCdbId)) {
                 $actorCache[$actorCdbId] = $actor;
             }
         }
         if ($actor) {
             $item->setActor($actor);
         }
     }
 }
Пример #6
0
function _watersportkampen_bootstrap_event_form_save_event($form, &$form_state, CultuurNet\Search\ActivityStatsExtendedEntity $location = NULL, CultuurNet\Search\ActivityStatsExtendedEntity $organiser = NULL)
{
    $values = $form_state['values'];
    $performerList = new CultureFeed_Cdb_Data_PerformerList();
    $mails = array();
    $phones = array();
    $links = array();
    $performers_count = 0;
    $update = FALSE;
    if (isset($form['#event'])) {
        $update = TRUE;
        $event = $form['#event'];
    } else {
        $event = new CultureFeed_Cdb_Item_Event();
    }
    // Reset old tags.
    foreach ($values['old_tags'] as $tag => $keyword) {
        if (!in_array($tag, array_keys($values['tags']))) {
            $event->deleteKeyword(new CultureFeed_Cdb_Data_Keyword($keyword['value'], $keyword['visible']));
        }
    }
    // Categories.
    $category_options = array();
    $values['categories'] = "0.57.0.0.0";
    $category_options[$values['categories']] = culturefeed_search_get_eventtype_categories(array('tid' => $values['categories']));
    $categories = new CultureFeed_Cdb_Data_CategoryList();
    foreach ($category_options as $key => $value) {
        if ($value) {
            $categories->add(new CultureFeed_Cdb_Data_Category(CultureFeed_Cdb_Data_Category::CATEGORY_TYPE_EVENT_TYPE, $key, $value[$key]));
        }
    }
    $event->setCategories($categories);
    //add sports to db
    foreach ($values['sports'] as $sport) {
        if (isset($sport) && $sport !== 0) {
            $values['tags'][$sport] = array('value' => $sport, 'visible' => TRUE);
        }
    }
    // Put new created tags in $form_state variable for further handling.
    $form_state['values']['tags'] = $values['tags'];
    foreach ($values['wrapper'] as $extra) {
        if (is_array($extra)) {
            // Performer
            if (!empty($extra['performer']) || !empty($extra['role'])) {
                $performer = new CultureFeed_Cdb_Data_Performer();
                $performer->setLabel($extra['performer']);
                $performer->setRole($extra['role']);
                $performerList->add($performer);
                $performers_count++;
            }
            // Contacts
            if (isset($extra['channel_input'])) {
                switch ($extra['channel']) {
                    case '0':
                        $phone = new CultureFeed_Cdb_Data_Phone($extra['channel_input'], CultureFeed_Cdb_Data_Phone::PHONE_TYPE_PHONE, FALSE, FALSE);
                        array_push($phones, $phone);
                        break;
                    case '1':
                        if ($extra['channel_input']) {
                            $mail = new CultureFeed_Cdb_Data_Mail($extra['channel_input'], FALSE, FALSE);
                            array_push($mails, $mail);
                        }
                        break;
                }
            }
        }
    }
    // Links
    $media_links = array();
    foreach ($values['links'] as $link_data) {
        if ($link_data['URL']) {
            if (!preg_match("@^https?://@", $link_data['URL'])) {
                $link_data['URL'] = 'http://' . $link_data['URL'];
            }
            $mediatype = CultureFeed_Cdb_Data_File::MEDIA_TYPE_WEBRESOURCE;
            if (strpos($link_data['URL'], 'plus.google.com')) {
                $mediatype = CultureFeed_Cdb_Data_File::MEDIA_TYPE_GOOGLEPLUS;
            }
            if (strpos($link_data['URL'], 'facebook.com')) {
                $mediatype = CultureFeed_Cdb_Data_File::MEDIA_TYPE_FACEBOOK;
            }
            if (strpos($link_data['URL'], 'twitter.com')) {
                $mediatype = CultureFeed_Cdb_Data_File::MEDIA_TYPE_TWITTER;
            }
            if (strpos($link_data['URL'], 'youtube.com') || strpos($link_data['URL'], 'youtu.be')) {
                $mediatype = CultureFeed_Cdb_Data_File::MEDIA_TYPE_YOUTUBE;
            }
            if ($link_data['reservation']) {
                // Make reservation link for contact element
                $link = new CultureFeed_Cdb_Data_Url($link_data['URL'], FALSE, $link_data['reservation']);
                array_push($links, $link);
                // Make reservation link for media element
                $mediatype = CultureFeed_Cdb_Data_File::MEDIA_TYPE_RESERVATIONS;
            }
            $link = new CultureFeed_Cdb_Data_File();
            $link->setHLink($link_data['URL']);
            $link->setMediaType($mediatype);
            if ($link_data['reservation']) {
                $link->setTitle(t('Order tickets'));
            }
            array_push($media_links, $link);
        }
    }
    // Age
    if ($values['age']) {
        $event->setAgeFrom($values['age'] ? $values['age'] : 0);
    } else {
        // Age Category
        switch ($values['age_category']) {
            case '1-12':
                $event->setAgeFrom(1);
                break;
            case '12-18':
                $event->setAgeFrom(12);
                break;
            case '18+':
                $event->setAgeFrom(18);
                break;
            case 'everyone':
            default:
                break;
        }
    }
    // Timestamps.
    if ($values['when']['date_control']['type'] == 'timestamps') {
        _culturefeed_entry_ui_event_save_timestamps($event, $values['when']['date_control']['timestamps']['stamps']);
    }
    // Period.
    if ($values['when']['date_control']['type'] == 'period') {
        _culturefeed_entry_ui_event_save_period($event, $values['when']['date_control']['period']);
    }
    // Weekscheme.
    if ($values['when']['date_control']['type'] == 'period' || $values['when']['date_control']['type'] == 'permanent') {
        _culturefeed_entry_ui_event_save_weekscheme($event, $values['when']['date_control']);
    }
    // Event details.
    $detail = new CultureFeed_Cdb_Data_EventDetail();
    $detail->setTitle($values['title']);
    if (!empty($values['description']['sd']['short_description'])) {
        $detail->setShortDescription($values['description']['sd']['short_description']);
    }
    if (!empty($values['description']['ld']['long_description'])) {
        $detail->setLongDescription($values['description']['ld']['long_description']);
    }
    // Photo
    if ($values['photo']['upload']) {
        // Save to Drupal
        $drupal_file = file_load($values['photo']['upload']);
        $drupal_file->status = FILE_STATUS_PERMANENT;
        file_save($drupal_file);
        file_usage_add($drupal_file, 'culturefeed_entry_ui', 'event', $drupal_file->fid);
        // Add to detail
        $file = new CultureFeed_Cdb_Data_File();
        $file->setMediaType($file::MEDIA_TYPE_PHOTO);
        $file->setCopyright($values['photo']['copyright_text']);
        $file->setMain(TRUE);
        switch ($drupal_file->filemime) {
            case 'image/gif':
                $file->setFileType($file::FILE_TYPE_GIF);
                break;
            case 'image/jpg':
            case 'image/jpeg':
                $file->setFileType($file::FILE_TYPE_JPEG);
                break;
            case 'image/png':
                $file->setFileType($file::FILE_TYPE_PNG);
                break;
        }
        $file->setHLink(file_create_url($drupal_file->uri));
        $file->setFilename($drupal_file->filename);
        $detail->getMedia()->add($file);
        // Remove old image
        // Bug on UDB ... will be fixed soon
        if (isset($values['photo']['current_file_hlink'])) {
            try {
                Drupalculturefeed_EntryApi::removeLinkFromEvent($event, $values['photo']['current_file_hlink']);
            } catch (Exception $e) {
                watchdog_exception('culturefeed_entry_ui', $e);
            }
        }
    }
    // Media links
    if ($media_links) {
        foreach ($media_links as $media_link) {
            $detail->getMedia()->add($media_link);
        }
    }
    // Price
    if ($values['price']['free']) {
        $price = new CultureFeed_Cdb_Data_Price(0);
        $detail->setPrice($price);
    } else {
        if (!empty($values['price']['amount'])) {
            $price = new CultureFeed_Cdb_Data_Price(floatval(str_replace(',', '.', $values['price']['amount'])));
            if (!empty($values['price']['extra']['extra_info'])) {
                $price->setDescription($values['price']['extra']['extra_info']);
            }
            $detail->setPrice($price);
        }
    }
    // Performers
    if ($performers_count) {
        $detail->setPerformers($performerList);
    }
    $detail->setLanguage(culturefeed_entry_ui_get_preferred_language());
    $details = new CultureFeed_Cdb_Data_EventDetailList();
    $details->add($detail);
    // Translations Dutch.
    if (culturefeed_search_get_preferred_language() != 'nl') {
        if ($values['dutch']['language'] || $values['dutch']['short_description'] || $values['dutch']['long_description']) {
            $detail = new CultureFeed_Cdb_Data_EventDetail();
            if ($values['dutch']['language']) {
                $detail->setTitle($values['dutch']['language']);
            }
            if (!empty($values['dutch']['short_description'])) {
                $detail->setShortDescription($values['dutch']['short_description']);
            }
            if (!empty($values['dutch']['long_description'])) {
                $detail->setLongDescription($values['dutch']['long_description']);
            }
            $detail->setLanguage("nl");
            $details->add($detail);
        }
    }
    $event->setDetails($details);
    // Location.
    $address = culturefeed_entry_ui_location_form_save($event, $location, $form_state);
    // Event organiser.
    if ($organiser) {
        $organiser_object = new CultureFeed_Cdb_Data_Organiser();
        $organiser_detail = $organiser->getEntity()->getDetails()->getDetailByLanguage(culturefeed_search_get_preferred_language());
        if (!$organiser_detail) {
            $organiser_detail = $organiser->getEntity()->getDetails()->getDetailByLanguage("nl");
        }
        $organiser_object->setLabel($organiser_detail->getTitle());
        $organiser_object->setCdbid($organiser->getEntity()->getCdbId());
        $event->setOrganiser($organiser_object);
    } else {
        if (isset($values['organiser']['new_actor'])) {
            $organiser_object = new CultureFeed_Cdb_Data_Organiser();
            $organiser_object->setLabel($values['organiser']['new_actor']);
            $event->setOrganiser($organiser_object);
        }
    }
    // Contact info.
    $physical_address = $address->getPhysicalAddress();
    $contact_object = new CultureFeed_Cdb_Data_ContactInfo();
    $contact_object->addAddress(new CultureFeed_Cdb_Data_Address($physical_address));
    foreach ($mails as $mail) {
        $contact_object->addMail($mail);
    }
    foreach ($phones as $phone) {
        $contact_object->addPhone($phone);
    }
    foreach ($links as $link) {
        $contact_object->addUrl($link);
    }
    $event->setContactInfo($contact_object);
    // Keywords.
    culturefeed_entry_ui_tags_form_save($event, $form_state);
    // Members.
    if ($values['members']) {
        $event->setPrivate(TRUE);
    }
    $form_state['submit_time'] = time();
    try {
        if ($update) {
            Drupalculturefeed_EntryApi::updateEvent($event);
            $form_state['#event_id'] = $event->getCdbId();
            watchdog('culturefeed_entry_ui', 'Event %eventid updated.', array('%eventid' => $form_state['#event_id']));
            cache_clear_all('culturefeed:results:detail:event:' . $event->getCdbId(), 'cache_culturefeed_search');
        } else {
            $form_state['#event_id'] = Drupalculturefeed_EntryApi::createEvent($event);
            watchdog('culturefeed_entry_ui', 'Event %eventid created.', array('%eventid' => $form_state['#event_id']));
        }
        $form_state['#update_event'] = $update;
    } catch (Exception $e) {
        watchdog_exception('culturefeed_entry_ui', $e);
        form_set_error('', t('An error occurred while saving the event'));
    }
    // Delete files from file system
    if ($form_state['values']['photo']['upload']) {
        $file = file_load($form_state['values']['photo']['upload']);
        file_delete($file);
    }
    if (isset($form_state['values']['photo']['current_file'])) {
        $file = file_load($form_state['values']['photo']['current_file']);
        file_delete($file);
    }
}