Exemplo n.º 1
0
 /**
  * @see CultureFeed_Cdb_IElement::parseFromCdbXml(SimpleXMLElement
  *     $xmlElement)
  * @return CultureFeed_Cdb_Data_EventDetailList
  */
 public static function parseFromCdbXml(SimpleXMLElement $xmlElement)
 {
     $detailList = new CultureFeed_Cdb_Data_EventDetailList();
     if (!empty($xmlElement->eventdetail)) {
         foreach ($xmlElement->eventdetail as $detailElement) {
             $detailList->add(CultureFeed_Cdb_Data_EventDetail::parseFromCdbXml($detailElement));
         }
     }
     return $detailList;
 }
Exemplo n.º 2
0
 /**
  * @see CultureFeed_Cdb_IElement::parseFromCdbXml(SimpleXMLElement
  *     $xmlElement)
  * @return CultureFeed_Cdb_Item_Event
  */
 public static function parseFromCdbXml(SimpleXMLElement $xmlElement)
 {
     if (empty($xmlElement->calendar)) {
         throw new CultureFeed_Cdb_ParseException('Calendar missing for event element');
     }
     if (empty($xmlElement->categories)) {
         throw new CultureFeed_Cdb_ParseException('Categories missing for event element');
     }
     if (empty($xmlElement->contactinfo)) {
         throw new CultureFeed_Cdb_ParseException('Contact info missing for event element');
     }
     if (empty($xmlElement->eventdetails)) {
         throw new CultureFeed_Cdb_ParseException('Eventdetails missing for event element');
     }
     if (empty($xmlElement->location)) {
         throw new CultureFeed_Cdb_ParseException('Location missing for event element');
     }
     $event_attributes = $xmlElement->attributes();
     $event = new CultureFeed_Cdb_Item_Event();
     CultureFeed_Cdb_Item_Base::parseCommonAttributes($event, $xmlElement);
     if (isset($event_attributes['private'])) {
         $event->setPrivate(filter_var((string) $event_attributes['private'], FILTER_VALIDATE_BOOLEAN));
     }
     if (isset($event_attributes['isparent'])) {
         $event->setIsParent(filter_var((string) $event_attributes['isparent'], FILTER_VALIDATE_BOOLEAN));
     }
     if (isset($event_attributes['pctcomplete'])) {
         $event->setPctComplete(floatval($event_attributes['pctcomplete']));
     }
     if (isset($event_attributes['published'])) {
         $event->setPublished(filter_var((string) $event_attributes['published'], FILTER_VALIDATE_BOOLEAN));
     }
     if (isset($event_attributes['validator'])) {
         $event->setValidator((string) $event_attributes['validator']);
     }
     if (isset($event_attributes['weight'])) {
         $event->setWeight((int) $event_attributes['weight']);
     }
     if (isset($xmlElement->agefrom)) {
         $event->setAgeFrom((int) $xmlElement->agefrom);
     }
     // Set calendar information.
     $calendar_type = key($xmlElement->calendar);
     if ($calendar_type == 'permanentopeningtimes') {
         $event->setCalendar(CultureFeed_Cdb_Data_Calendar_Permanent::parseFromCdbXml($xmlElement->calendar));
     } elseif ($calendar_type == 'timestamps') {
         $event->setCalendar(CultureFeed_Cdb_Data_Calendar_TimestampList::parseFromCdbXml($xmlElement->calendar->timestamps));
     } elseif ($calendar_type == 'periods') {
         $event->setCalendar(CultureFeed_Cdb_Data_Calendar_PeriodList::parseFromCdbXml($xmlElement->calendar));
     }
     // Set categories
     $event->setCategories(CultureFeed_Cdb_Data_CategoryList::parseFromCdbXml($xmlElement->categories));
     // Set contact information.
     $event->setContactInfo(CultureFeed_Cdb_Data_ContactInfo::parseFromCdbXml($xmlElement->contactinfo));
     // Set event details.
     $event->setDetails(CultureFeed_Cdb_Data_EventDetailList::parseFromCdbXml($xmlElement->eventdetails));
     // Set location.
     $event->setLocation(CultureFeed_Cdb_Data_Location::parseFromCdbXml($xmlElement->location));
     // Set organiser
     if (!empty($xmlElement->organiser)) {
         $event->setOrganiser(CultureFeed_Cdb_Data_Organiser::parseFromCdbXml($xmlElement->organiser));
     }
     // Set max participants.
     if (!empty($xmlElement->maxparticipants)) {
         $event->setMaxParticipants((int) $xmlElement->maxparticipants);
     }
     // Set booking period.
     if (!empty($xmlElement->bookingperiod)) {
         $event->setBookingPeriod(CultureFeed_Cdb_Data_Calendar_BookingPeriod::parseFromCdbXml($xmlElement->bookingperiod));
     }
     // Set relations.
     if (!empty($xmlElement->eventrelations) && !empty($xmlElement->eventrelations->relatedproduction)) {
         foreach ($xmlElement->eventrelations->relatedproduction as $relatedProduction) {
             $attributes = $relatedProduction->attributes();
             $event->addRelation(new CultureFeed_Cdb_Item_Reference((string) $attributes['cdbid'], (string) $relatedProduction, (string) $attributes['externalid']));
         }
     }
     self::parseKeywords($xmlElement, $event);
     if (!empty($xmlElement->languages)) {
         $event->setLanguages(CultureFeed_Cdb_Data_LanguageList::parseFromCdbXml($xmlElement->languages));
     }
     return $event;
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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);
    }
}