This repository has been archived on 2023-01-23. You can view files and clone it, but cannot push or open issues or pull requests.
importer-parsers-archive-2022/parsers/becollect_dtmb.php

806 lines
38 KiB
PHP
Raw Permalink Normal View History

2023-01-23 15:21:35 +01:00
<?PHP
/**
* Parser for XML generated through CSVXML.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
* @author Stefan Rohde-Enslin <s.rohde-enslin@museum-digital.de>
* @link https://imports.museum-digital.org/importer/parsers/csvxml.php
*/
declare(strict_types = 1);
/**
* Runs explode on many entries.
*
* @param array<non-empty-string> $delimiters List of delimiters.
* @param string $string Haystack.
*
* @return array<string>
*/
function multiexplode(array $delimiters, string $string):array {
$ready = str_replace($delimiters, $delimiters[0], $string);
if (!($launch = explode($delimiters[0], $ready))) {
throw new Exception("Error exploding");
}
return $launch;
}
/**
* Wrapper around $mdEvent->set_zeiten_id.
*
* @param MDEvent $event Event.
* @param SimpleXMLElement $time Time to handle.
*
* @return MDEvent
*/
function setTimeMaybeWithDates(MDEvent $event, SimpleXMLElement $time):MDEvent {
if (!empty((string)$time->year_from) and !empty((string)$time->year_to)) {
$event->set_zeiten_id((string)$time->text_date, intval((string)$time->year_from), intval((string)$time->year_to));
}
else {
$event->set_zeiten_id((string)$time->text_date);
}
return $event;
}
/**
* Function for parsing events. Returns objects of type MDEvent.
*
* @param array<mixed> $version Version information (e.g. DB connections).
* @param MDOutputHandler $outputHandler Output handler.
* @param array<mixed> $allEvents All events.
*
* @return array<MDEvent>
*/
function parseEvents(array $version, MDOutputHandler $outputHandler, array $allEvents):array {
$output = [];
foreach ($allEvents as $eventType => $eventSubjects) {
$placesUsed = $timesUsed = [];
foreach ($eventSubjects['persinst'] as $persinst_id) {
$placesUsedForPersinst = $timesUsedForPersinst = [];
$persinstEvents = [];
foreach ($eventSubjects['places'] as $place_id) {
foreach ($eventSubjects['times'] as $time_id) {
$event = new MDEvent($version['mainDB'], $version['nodaDB'], $version['language'], $eventType, $outputHandler);
$event->set_orte_id($place_id);
$event->set_persinst_id($persinst_id['name']);
$event = setTimeMaybeWithDates($event, $time_id);
if ($event->get_orte_id() !== 0 || $event->get_zeiten_id() !== 0 || $event->get_persinst_id() !== 0)
$persinstEvents[] = $event;
$timesUsed[] = $timesUsedForPersinst[] = $time_id;
$placesUsed[] = $placesUsedForPersinst[] = $place_id;
}
if (!in_array($place_id, $placesUsedForPersinst, true)) {
$event = new MDEvent($version['mainDB'], $version['nodaDB'], $version['language'], $eventType, $outputHandler);
$event->set_orte_id($place_id);
$event->set_persinst_id($persinst_id['name']);
if ($event->get_orte_id() !== 0 || $event->get_zeiten_id() !== 0 || $event->get_persinst_id() !== 0)
$persinstEvents[] = $event;
$placesUsed[] = $placesUsedForPersinst[] = $place_id;
}
}
foreach ($eventSubjects['times'] as $time_id) {
if (in_array($time_id, $timesUsedForPersinst, true)) continue;
$event = new MDEvent($version['mainDB'], $version['nodaDB'], $version['language'], $eventType, $outputHandler);
$event->set_persinst_id($persinst_id['name']);
$event = setTimeMaybeWithDates($event, $time_id);
if ($event->get_orte_id() !== 0 || $event->get_zeiten_id() !== 0 || $event->get_persinst_id() !== 0)
$persinstEvents[] = $event;
$timesUsed[] = $time_id;
}
if ($persinstEvents === []) {
$event = new MDEvent($version['mainDB'], $version['nodaDB'], $version['language'], $eventType, $outputHandler);
$event->set_persinst_id($persinst_id['name']);
if ($event->get_orte_id() !== 0 || $event->get_zeiten_id() !== 0 || $event->get_persinst_id() !== 0)
$persinstEvents[] = $event;
}
$output = array_merge($output, $persinstEvents);
}
foreach ($eventSubjects['places'] as $place_id) {
if (in_array($place_id, $placesUsed, true)) continue;
$placeEvents = [];
foreach ($eventSubjects['times'] as $time_id) {
$event = new MDEvent($version['mainDB'], $version['nodaDB'], $version['language'], $eventType, $outputHandler);
$event->set_orte_id($place_id);
$event = setTimeMaybeWithDates($event, $time_id);
if ($event->get_orte_id() !== 0 || $event->get_zeiten_id() !== 0 || $event->get_persinst_id() !== 0)
$placeEvents[] = $event;
$timesUsed[] = $time_id;
}
if ($placeEvents === []) {
$event = new MDEvent($version['mainDB'], $version['nodaDB'], $version['language'], $eventType, $outputHandler);
$event->set_orte_id($place_id);
if ($event->get_orte_id() !== 0 || $event->get_zeiten_id() !== 0 || $event->get_persinst_id() !== 0)
$placeEvents[] = $event;
$placesUsed[] = $place_id;
}
$output = array_merge($output, $placeEvents);
}
foreach ($eventSubjects['times'] as $time_id) {
if (in_array($time_id, $timesUsed, true)) continue;
$event = new MDEvent($version['mainDB'], $version['nodaDB'], $version['language'], $eventType, $outputHandler);
$event = setTimeMaybeWithDates($event, $time_id);
if ($event->get_orte_id() !== 0 || $event->get_zeiten_id() !== 0 || $event->get_persinst_id() !== 0)
$output[] = $event;
$timesUsed[] = $time_id;
}
}
return $output;
}
/**
* Returns true if the input is "y", false otherwise.
*
* @param string $input Input string.
*
* @return boolean
*/
function translateYNToBool(string $input):bool {
if ($input === "y") return true;
else return false;
}
/**
* Function getSubjectName retrieves subject names.
*
* @param SimpleXMLElement $subjects SimpleXMLElement containing all subjects.
* @param integer $subjectID Subject ID.
*
* @return array<string>
*/
function getSubjectName(SimpleXMLElement $subjects, int $subjectID):array {
foreach ($subjects->subject as $subject) {
if ($subject->attributes()->subject_id == $subjectID) {
$output = [];
if (!empty($subject->attributes()->uri)) {
$uri = strval($subject->attributes()->uri);
if (strpos($uri, "d-nb.info/gnd") !== false and ($uriPos = strrpos($uri, "/")) !== false) $output["gnd"] = substr($uri, $uriPos + 1);
}
$output["name"] = strval($subject->name);
return $output;
}
}
return [];
}
/**
* Parse function.
*
* @param array<mixed> $version Instance to import into.
* @param integer $institution_id Institution to import to.
* @param non-empty-string $XMLFolder Folder of the XML files to import.
* @param string $dataFolder Data folder.
* @param integer $sammlung_id Collection ID. Optional.
* @param boolean $visibility Import objects to be directly visible?.
* @param boolean $insertOnly If set to true, only new objects are added,
* old are not updated.
*
* @return void
*/
function parseImportXML(array $version, int $institution_id, string $XMLFolder, string $dataFolder = "", int $sammlung_id = 0, bool $visibility = false, bool $insertOnly = false) {
if (!is_dir(MD_IMPORTER_CONF::$import_dir_xml . "{$XMLFolder}")) throw new MDFileDoesNotExist("The folder to import from ($XMLFolder) does not exist.");
if (empty($dataFolder)) {
$importImages = false;
}
else $importImages = true;
// Set up writers
$collectionWriter = new MDCollectionWriter($version['mainDB']);
$literatureWriter = new MDLiteratureWriter($version['mainDB']);
$linkWriter = new MDLinkWriter($version['mainDB']);
$seriesWriter = new MDSeriesWriter($version['mainDB']);
$exhibitionWriter = new MDExhibitionWriter($version['mainDB']);
$objectRecordWriter = new MDObjectRecordWriter($version['mainDB']);
$tagWriter = new MDTagWriter($version['nodaDB']);
$outputHandler = new MDOutputHandler;
$outputHandler->setVerbosity(2);
$objectWriter = new MDObjectWriter($version['mainDB'], $version['nodaDB'], $version['link'], $version['filepath'], $version['dataFolderLink']);
foreach (MD_STD::scandir(MD_IMPORTER_CONF::$import_dir_xml . "{$XMLFolder}") as $xmlFile) {
if (pathinfo($xmlFile, PATHINFO_EXTENSION) !== "xml") continue;
$outputHandler->toLog("Attempting to load XML file {$xmlFile}", 2);
$rawData = MD_STD::file_get_contents(MD_IMPORTER_CONF::$import_dir_xml . "{$XMLFolder}/{$xmlFile}");
$rawData = MD_STD::preg_replace_str('/\x{FEFF}/u', '', $rawData);
if (!($xmlData = simplexml_load_string($rawData))) {
echo "$xmlFile is corrupt. Check it lah";
exit;
}
if (!($json_encoded = MD_STD::json_encode_object($xmlData)) || !($objectData = json_decode($json_encoded, true))) {
throw new Exception("Could not load file {$xmlFile}");
}
$objectData = $objectData['objects']['object'];
$subjectData = $xmlData->subjects;
//
// Objekt Basis Angaben
//
$objectData['object_type'] = 'Man-made object';
$objectData['object_title'] = (string)$xmlData->objects->object->object_name;
if (!empty($objectData['online_text']) and $objectData['online_text'] != 'ERSATZ') {
$objectData['online_text'] = str_replace('<br class="linefeed" />', "\n", $objectData['online_text']);
$objectData['online_text'] = str_replace("\n ", "\n", $objectData['online_text']);
$objectData['online_text'] = str_replace("\n\n", "\n", $objectData['online_text']);
$objectData['object_description'] = trim(MD_STD::preg_replace_str('/<[^>]*>/i', '', $objectData['online_text']));
}
else $objectData['object_description'] = 'Beschreibung für ' . $objectData['object_title'] . ' folgt.';
//
// Literatur
//
if (isset($objectData['literature']) and !is_array($objectData['literature'])) {
$literatur = explode('<br class="linefeed" />', $objectData['literature']);
$objectData['object_description'] .= PHP_EOL . PHP_EOL . "Weiterführend: ";
foreach ($literatur as $litEntry) {
if (!empty($litEntry)) $objectData['object_description'] .= PHP_EOL . $litEntry;
}
}
else $literatur = [];
$outputHandler->toLog("Successfully loaded XML file {$xmlFile} (Object: {$objectData['inventory_number']})", 2);
$availableKeys = array_keys($objectData);
// Object base data
$object = new MDObject($version['mainDB'], $version['nodaDB'], $version['language'], $institution_id, (string)$xmlData->objects->object->inventory_number, $objectData['object_type'], $objectData['object_title'], $objectData['object_description'], $outputHandler);
if ($sammlung_id !== 0) {
$object->appendCollectionByID($sammlung_id);
}
else {
echo "Missing collection ID, parsing collection from XML is not yet implemented!";
exit;
}
foreach ($literatur as $litEntry) {
if (!empty($litEntry)) $object->appendLiteratureByName(trim($litEntry), "", "", "", "", $literatureWriter);
}
//
// Tags
//
if (isset($objectData['keywords']) and !is_array($objectData['keywords'])) {
$schlagwort = trim(MD_STD::preg_replace_str('/<[^>]*>/i', '', $objectData['keywords']));
$schlagwort = multiexplode(['; ', ', ', ','], $schlagwort); // ', ' trennt echte Schlagworte und ',' trennt Systematik
}
else $schlagwort = [];
$notag = ['Allgemeines', 'Übergreifendes', '.'];
foreach ($schlagwort as $swEntry) {
if (is_numeric(substr($swEntry, 0, 1))) {
if (!in_array(stristr($swEntry, ' '), $notag, true)) $swEntry = stristr($swEntry, ' ') ?: ""; // Schneide bei Klassifikationsangaben aus Systematik (e.g. 10. Nachrichtentechnik) die Nummern ab.
}
if (substr($swEntry, -1) == '.') $swEntry = substr($swEntry, 0, -1);
//if (stristr(stristr($swEntry, ' '), ' und ') === FALSE)
$object->appendTagByName(trim($swEntry), "", $tagWriter);
}
//
// material / technique
//
if (!empty($objectData['materials_techniques']) and is_array($objectData['materials_techniques']['material_technique'])) {
$object->set_objekt_material_technik(implode(', ', $objectData['materials_techniques']['material_technique']));
}
//
// Ausmaße
//
$measurements = [];
foreach ($xmlData->objects->object->dimensions->dimension as $dimension) {
$tAttribute = trim(str_replace("Objektmaß", "", $dimension->attributes()->type));
$measurements[] = $tAttribute . ": " . strval($dimension);
}
$object->set_objekt_masse(implode('; ', $measurements));
/*
* Handle events
*/
$emptyEvent = [
"places" => [],
"persinst" => [],
"times" => [],
];
$allEvents = [
1 => $emptyEvent, // Production
];
// Events, 1. Alle Zeiten
foreach ($xmlData->objects->object->datings->dating as $dating) {
if (empty((string)$dating->text_date) || in_array((string)$dating->text_date, ["?"], true)) continue;
$tAttribute = trim((string)$dating->attributes()->type);
if (in_array($tAttribute, ["", "Herstellungsjahr", "Herst.-Zeitraum", "Herstellungsjahr (Nachbau)"], true)) {
$allEvents[1]['times'][] = $dating;
}
else if ($tAttribute === "Herstellungsjahr (Original)") {
$allEvents[4]['times'][] = $dating;
}
else if ($tAttribute === "Entwurf") {
$allEvents[35]['times'][] = $dating;
}
else {
echo "Unknown time type: " . $tAttribute . PHP_EOL;
echo "Please enter it at " . __FILE__ . " around line #" . __LINE__ . PHP_EOL;
exit;
}
}
// Events, 2. Alle Orte
foreach ($xmlData->objects->object->geographic_references->geographic_reference as $geographic_reference) {
if ((string)$geographic_reference === "unbekannt") continue;
$tAttribute = trim((string)$geographic_reference->attributes()->type);
if ($tAttribute === "Herstellungsort") {
$allEvents[1]['places'][] = strval($geographic_reference);
}
else if ($tAttribute === "Herkunft") {
$allEvents[8]['places'][] = strval($geographic_reference);
}
else {
echo "Unknown place type: " . $tAttribute . PHP_EOL;
echo "Please enter it at " . __FILE__ . " around line #" . __LINE__ . PHP_EOL;
exit;
}
}
// Events, 3. Alle actor
foreach ($xmlData->objects->object->subject_references->subject_reference as $subject_reference) {
$tAttribute = trim((string)$subject_reference->attribution);
if (in_array($tAttribute, ["Hersteller", "Herstellung", "Reparatur"], true)) {
$allEvents[1]['persinst'][] = getSubjectName($subjectData, intval((string)$subject_reference->subject_id));
}
else if ($tAttribute === "Herkunft") {
$allEvents[8]['persinst'][] = getSubjectName($subjectData, intval((string)$subject_reference->subject_id));
}
else if ($tAttribute === "Entwurf") {
$allEvents[35]['persinst'][] = getSubjectName($subjectData, intval((string)$subject_reference->subject_id));
}
else if ($tAttribute === "Auftraggeber/in") {
$allEvents[25]['persinst'][] = getSubjectName($subjectData, intval((string)$subject_reference->subject_id));
}
else if ($tAttribute === "Entwicklung") {
$allEvents[4]['persinst'][] = getSubjectName($subjectData, intval((string)$subject_reference->subject_id));
}
else if ($tAttribute === "Nutzung") {
$allEvents[6]['persinst'][] = getSubjectName($subjectData, intval((string)$subject_reference->subject_id));
}
else if ($tAttribute === "Künstler/in") {
$allEvents[1]['persinst'][] = getSubjectName($subjectData, intval((string)$subject_reference->subject_id));
}
else if ($tAttribute === "Herstellung elektr. Ausrüstung") {
$allEvents[1]['persinst'][] = getSubjectName($subjectData, intval((string)$subject_reference->subject_id));
}
else if ($tAttribute === "Mit dem Objekt verbunden") {
$allEvents[23]['persinst'][] = getSubjectName($subjectData, intval((string)$subject_reference->subject_id));
}
else if ($tAttribute === "Lieferant") {
$allEvents[23]['persinst'][] = getSubjectName($subjectData, intval((string)$subject_reference->subject_id));
}
else {
echo "Unknown actor type: " . $tAttribute . PHP_EOL;
echo "Please enter it at " . __FILE__ . " around line #" . __LINE__ . PHP_EOL;
exit;
}
}
// Write events based on data parsed beforehand
// 1 => array()
$events = parseEvents($version, $outputHandler, $allEvents);
foreach ($events as $event) {
$object->appendEvent($event);
}
$images = [];
foreach ($xmlData->objects->object->media->medium as $medium) {
$image = new MDImage($version['mainDB'], $objectData["object_title"], MD_IMPORTER_CONF::$import_dir_files . $dataFolder . "/" . $medium->key_file_name[0]);
$image->set_image_owner("Stiftung Deutsches Technikmuseum Berlin");
$image->set_image_rights("CC BY-NC-SA");
if ($medium->status == "online Hauptbild") $mainResourceSet = true;
else $mainResourceSet = false;
$image->set_main_image($mainResourceSet);
$images[] = $image;
}
foreach ($images as $image) $object->appendImage($image);
/*
if (!empty($objectData["object_material_technique"]) and $objectData["object_material_technique"] != "ERSATZ") $object->set_objekt_material_technik($objectData["object_material_technique"]);
if (!empty($objectData["object_dimensions"]) and $objectData["object_dimensions"] != "ERSATZ") $object->set_objekt_masse($objectData["object_dimensions"]);
// Verwaltung
if (!empty($objectData['systematic']) and $objectData['systematic'] != "ERSATZ") $object->set_string("systematik", $objectData['systematic']);
if (!empty($objectData['inclusion_when']) and $objectData['inclusion_when'] != "ERSATZ") $object->set_string("zeitpunkt_zugang", $objectData['inclusion_when']);
if (!empty($objectData['inclusion_kind_of']) and $objectData['inclusion_kind_of'] != "ERSATZ") $object->set_string("zugang_art", $objectData['inclusion_kind_of']);
if (!empty($objectData['inclusion_who']) and $objectData['inclusion_who'] != "ERSATZ") $object->set_string("erwerbender", $objectData['inclusion_who']);
if (!empty($objectData['inclusion_where']) and $objectData['inclusion_where'] != "ERSATZ") $object->set_string("erwerbungsort", $objectData['inclusion_where']);
if (!empty($objectData['registration_first_who']) and $objectData['registration_first_who'] != "ERSATZ") $object->set_string("ersterfasser", $objectData['registration_first_who']);
if (!empty($objectData['owner_previous']) and $objectData['owner_previous'] != "ERSATZ") $object->set_string("vorbesitzer", $objectData['owner_previous']);
if (!empty($objectData['state']) and $objectData['state'] != "ERSATZ") $object->set_string("zustand", $objectData['state']);
// Aufenthalt
if (!empty($objectData['abode_actual']) and $objectData['abode_actual'] != "ERSATZ") $object->set_string("standort_aktuell", $objectData['abode_actual']);
if (!empty($objectData['abode_regular']) and $objectData['abode_regular'] != "ERSATZ") $object->set_string("standort_eigentlich", $objectData['abode_regular']);
// Rechte
if (!empty($objectData['rights_object']) and $objectData['rights_object'] != "ERSATZ") $object->set_string("urheberrechte", $objectData['rights_object']);
if (!empty($objectData['rights_of_use']) and $objectData['rights_of_use'] != "ERSATZ") $object->set_string("nutzungsrechte", $objectData['rights_of_use']);
if (!empty($objectData['rights_annotation']) and $objectData['rights_annotation'] != "ERSATZ") $object->set_string("rechte_anmerkungen", $objectData['rights_annotation']);
// Notizen
if (!empty($objectData['remarks_short']) and $objectData['remarks_short'] != "ERSATZ") $object->set_string("notizen_text2", $objectData['remarks_short']); else $object->set_string("notizen_text2", '');
if (!empty($objectData['remarks_long']) and $objectData['remarks_long'] != "ERSATZ") $object->set_string("notizen_text1", $objectData['remarks_long']);
// Collections
if ($sammlung_id !== 0) {
$object->appendCollectionByID($sammlung_id);
}
else if (!empty($objectData['collection_name1'])) {
$searchTarget = "collection_name";
$availableEntities = [];
foreach ($availableKeys as $key) {
if (substr($key, 0, strlen($searchTarget)) === $searchTarget) {
$availableEntities[] = substr($key, strlen($searchTarget));
}
}
foreach ($availableEntities as $suffix) {
$object->appendCollectionByName($objectData[$searchTarget . $suffix], "", $collectionWriter);
}
}
//
/ Zusatz
//
if (!empty($objectData['detailed_description'])) {
$object->set_string("detaileddescription2", $objectData['detailed_description']);
if (!empty($objectData['detailed_description_md']) and $objectData['detailed_description_md'] == "y") {
$object->set_bool("detaileddescription2show_md", true);
}
else $object->set_bool("detaileddescription2show_md", false);
if (!empty($objectData['detailed_description_extern']) and $objectData['detailed_description_extern'] == "y") {
$object->set_bool("detaileddescription2show_extern", true);
}
else $object->set_bool("detaileddescription2show_extern", false);
}
if (!empty($objectData['number_of_pages']) and $objectData['number_of_pages'] != "ERSATZ") $object->set_string("mass2_seitenzahl", $objectData['number_of_pages']);
if (!empty($objectData['number_of_pieces']) and $objectData['number_of_pieces'] != "ERSATZ") $object->set_string("stueckzahl", $objectData['number_of_pieces']);
if (!empty($objectData['closer_location']) and $objectData['closer_location'] != "ERSATZ") $object->set_string("ort2_name", $objectData['closer_location']);
if (!empty($objectData['closer_location_as']) and $objectData['closer_location_as'] != "ERSATZ") $object->set_closer_location_types("ort2_art", $objectData['closer_location_as']);
if (!empty($objectData['material_separate']) and $objectData['material_separate'] != "ERSATZ") $object->set_string("material2", $objectData['material_separate']);
if (!empty($objectData['technique_separate']) and $objectData['technique_separate'] != "ERSATZ") $object->set_string("technik2", $objectData['technique_separate']);
if (!empty($objectData['dimensions_separate_length_value']) and $objectData['dimensions_separate_length_value'] != "ERSATZ") $object->set_string("mass2_laenge_wert", $objectData['dimensions_separate_length_value']);
if (!empty($objectData['dimensions_separate_length_unit']) and $objectData['dimensions_separate_length_unit'] != "ERSATZ") $object->set_length_unit("mass2_laenge_einheit", $objectData['dimensions_separate_length_unit']);
if (!empty($objectData['dimensions_separate_width_value']) and $objectData['dimensions_separate_width_value'] != "ERSATZ") $object->set_string("mass2_breite_wert", $objectData['dimensions_separate_width_value']);
if (!empty($objectData['dimensions_separate_width_unit']) and $objectData['dimensions_separate_width_unit'] != "ERSATZ") $object->set_length_unit("mass2_breite_einheit", $objectData['dimensions_separate_width_unit']);
if (!empty($objectData['dimensions_separate_height_value']) and $objectData['dimensions_separate_height_value'] != "ERSATZ") $object->set_string("mass2_hoehe_wert", $objectData['dimensions_separate_height_value']);
if (!empty($objectData['dimensions_separate_height_unit']) and $objectData['dimensions_separate_height_unit'] != "ERSATZ") $object->set_length_unit("mass2_hoehe_einheit", $objectData['dimensions_separate_height_unit']);
if (!empty($objectData['dimensions_separate_diameter_value']) and $objectData['dimensions_separate_diameter_value'] != "ERSATZ") $object->set_string("mass2_durchmesser_wert", $objectData['dimensions_separate_diameter_value']);
if (!empty($objectData['dimensions_separate_diameter_unit']) and $objectData['dimensions_separate_diameter_unit'] != "ERSATZ") $object->set_length_unit("mass2_durchmesser_einheit", $objectData['dimensions_separate_diameter_unit']);
if (!empty($objectData['dimensions_separate_weight_value']) and $objectData['dimensions_separate_weight_value'] != "ERSATZ") $object->set_string("mass2_gewicht_wert", $objectData['dimensions_separate_weight_value']);
if (!empty($objectData['dimensions_separate_weight_unit']) and $objectData['dimensions_separate_weight_unit'] != "ERSATZ") $object->set_weight_unit("mass2_gewicht_einheit", $objectData['dimensions_separate_weight_unit']);
if (!empty($objectData['dimensions_separate_wall_thickness_value']) and $objectData['dimensions_separate_wall_thickness_value'] != "ERSATZ") $object->set_string("wandungsstaerke_wert", $objectData['dimensions_separate_wall_thickness_value']);
if (!empty($objectData['dimensions_separate_wall_thickness_unit']) and $objectData['dimensions_separate_wall_thickness_unit'] != "ERSATZ") $object->set_length_unit("wandungsstaerke_einheit", $objectData['dimensions_separate_wall_thickness_unit']);
if (!empty($objectData['dimensions_separate_show_md']) and $objectData['dimensions_separate_show_md'] != "ERSATZ") $object->set_bool("mass2show_md", translateYNToBool($objectData['dimensions_separate_show_md']));
if (!empty($objectData['dimensions_separate_show_extern']) and $objectData['dimensions_separate_show_extern'] != "ERSATZ") $object->set_bool("mass2show_extern", translateYNToBool($objectData['dimensions_separate_show_extern']));
if (!empty($objectData['inscription'])) {
$object->set_string("beschriftung2", $objectData['inscription']);
if (!empty($objectData['inscription_md']) and $objectData['inscription_md'] == "y") {
$object->set_bool("beschriftung2show_md", true);
}
else $object->set_bool("beschriftung2show_md", false);
if (!empty($objectData['inscription_extern']) and $objectData['inscription_extern'] == "y") {
$object->set_bool("beschriftung2show_extern", true);
}
else $object->set_bool("beschriftung2show_extern", false);
}
//
/ Events
//
// Related place
if (!empty($objectData['related_place1'])) {
$searchTarget = "related_place";
$availableEntities = [];
foreach ($availableKeys as $key) {
if (substr($key, 0, strlen($searchTarget)) === $searchTarget) {
if (is_numeric(substr($key, strlen($searchTarget))))
$availableEntities[] = substr($key, strlen($searchTarget));
}
}
foreach ($availableEntities as $suffix) {
$event = new MDEvent($version['mainDB'], $version['nodaDB'], $version['language'], 22, $outputHandler);
if (!empty($objectData[$searchTarget . $suffix])) $event->set_orte_id($objectData[$searchTarget . $suffix]);
if (!empty($objectData[$searchTarget . "_sure" . $suffix])) $event->set_ereignis_orte_sicher(translateYNToBool($objectData[$searchTarget . "_sure" . $suffix]));
$object->appendEvent($event);
}
}
// Related actor
if (!empty($objectData['related_actor1'])) {
$searchTarget = "related_actor";
$availableEntities = [];
foreach ($availableKeys as $key) {
if (substr($key, 0, strlen($searchTarget)) === $searchTarget) {
if (is_numeric(substr($key, strlen($searchTarget))))
$availableEntities[] = substr($key, strlen($searchTarget));
}
}
foreach ($availableEntities as $suffix) {
$event = new MDEvent($version['mainDB'], $version['nodaDB'], $version['language'], 23, $outputHandler);
if (!empty($objectData[$searchTarget . $suffix])) $event->set_persinst_id($objectData[$searchTarget . $suffix]);
if (!empty($objectData[$searchTarget . "_sure" . $suffix])) $event->set_ereignis_persinst_sicher(translateYNToBool($objectData[$searchTarget . "_sure" . $suffix]));
$object->appendEvent($event);
}
}
//
/ Tags
//
if (!empty($objectData['tag1'])) {
$searchTarget = "tag";
$availableEntities = [];
foreach ($availableKeys as $key) {
if (substr($key, 0, strlen($searchTarget)) === $searchTarget) {
$availableEntities[] = substr($key, strlen($searchTarget));
}
}
foreach ($availableEntities as $suffix) {
if ($objectData[$searchTarget . $suffix] === "ERSATZ") continue;
$object->appendTagByName($objectData[$searchTarget . $suffix], "", $tagWriter);
}
}
//
// Literatur
//
if (!empty($objectData['literature_title1'])) {
$searchTarget = "literature_title";
$availableEntities = [];
foreach ($availableKeys as $key) {
if (substr($key, 0, strlen($searchTarget)) === $searchTarget) {
$availableEntities[] = substr($key, strlen($searchTarget));
}
}
foreach ($availableEntities as $suffix) {
if ($objectData[$searchTarget . $suffix] === "ERSATZ" || empty($objectData[$searchTarget . $suffix])) continue;
if (is_array($objectData[$searchTarget . $suffix])) continue;
if (!empty($objectData["literature_author" . $suffix]) and $objectData["literature_author" . $suffix] !== "ERSATZ") {
$literature_author = $objectData["literature_author" . $suffix];
}
else $literature_author = "";
if (!empty($objectData["literature_year" . $suffix]) and $objectData["literature_year" . $suffix] !== "ERSATZ") {
$literature_year = $objectData["literature_year" . $suffix];
}
else $literature_year = "";
if (!empty($objectData["literature_place" . $suffix]) and $objectData["literature_place" . $suffix] !== "ERSATZ") {
$literature_place = $objectData["literature_place" . $suffix];
}
else $literature_place = "";
if (!empty($objectData["literature_inlit" . $suffix]) and $objectData["literature_inlit" . $suffix] !== "ERSATZ") {
$literature_inlit = $objectData["literature_inlit" . $suffix];
}
else $literature_inlit = "";
$object->appendLiteratureByName($objectData[$searchTarget . $suffix], $literature_author, $literature_year, $literature_place, $literature_inlit, $literatureWriter);
}
}
//
// Serie
//
if (!empty($objectData['object_group_name1'])) {
$searchTarget = "object_group_name";
$availableEntities = [];
foreach ($availableKeys as $key) {
if (substr($key, 0, strlen($searchTarget)) === $searchTarget) {
$availableEntities[] = substr($key, strlen($searchTarget));
}
}
foreach ($availableEntities as $suffix) {
if (!empty($objectData[$searchTarget . $suffix]) and $objectData[$searchTarget . $suffix] != "ERSATZ") {
$series_name = $objectData["object_group_name" . $suffix];
$serie_beschreibung = $objectData["object_group_description" . $suffix];
$object->appendSeriesByName($series_name, $serie_beschreibung, $seriesWriter);
}
}
}
//
// Images
//
$mainResourceSet = false;
if ($importImages === true) {
// Images
$searchTarget = "image_name";
$availableEntities = [];
foreach ($availableKeys as $key) {
if (substr($key, 0, strlen($searchTarget)) === $searchTarget) {
if (is_numeric(substr($key, strlen($searchTarget))))
$availableEntities[] = substr($key, strlen($searchTarget));
}
}
$images = [];
foreach ($availableEntities as $suffix) {
$objectData["image_name" . $suffix] = str_replace("/", "-", $objectData["image_name" . $suffix]);
if (!file_exists(MD_IMPORTER_CONF::$import_dir_files . $dataFolder . "/" . $objectData["image_name" . $suffix])) {
continue;
}
$image = new MDImage($version['mainDB'], $objectData["object_title"], MD_IMPORTER_CONF::$import_dir_files . $dataFolder . "/" . $objectData["image_name" . $suffix]);
$image->set_image_owner($objectData["image_owner" . $suffix]);
if (isset($objectData["image_rights" . $suffix])) $image->set_image_rights($objectData["image_rights" . $suffix]);
if (isset($objectData["image_owner" . $suffix])) $image->set_image_owner($objectData["image_owner" . $suffix]);
if (isset($objectData["image_creator" . $suffix])) $image->set_image_creator($objectData["image_creator" . $suffix]);
if (isset($objectData["image_visible" . $suffix])) $image->set_visible(translateYNToBool($objectData["image_visible" . $suffix]));
if (isset($objectData["image_main" . $suffix])) {
if ($objectData["image_main" . $suffix] == "y") $mainResourceSet = true;
$image->set_main_image(translateYNToBool($objectData["image_main" . $suffix]));
}
$images[] = $image;
}
// Ressources
$searchTarget = "resource_name";
$availableEntities = [];
foreach ($availableKeys as $key) {
if (substr($key, 0, strlen($searchTarget)) === $searchTarget) {
if (is_numeric(substr($key, strlen($searchTarget))))
$availableEntities[] = substr($key, strlen($searchTarget));
}
}
$resources = [];
foreach ($availableEntities as $suffix) {
if (!file_exists(MD_IMPORTER_CONF::$import_dir_files . $dataFolder . "/" . $objectData["resource_name" . $suffix])) {
continue;
}
$resource = new MDResource($version['mainDB'], 0, MD_IMPORTER_CONF::$import_dir_files . $dataFolder . "/" . $objectData["resource_name" . $suffix], $objectData["resource_media_type" . $suffix]);
$locationdir = MD_IMPORTER_CONF::$target_filepath_base . $version['filepath'] . '/resources/documents/' . date("Ym") . '/';
if (!is_dir($locationdir)) mkdir($locationdir, 0755, true);
$resource->set_preview_real_folder($locationdir);
$resource->set_preview_folder('resources/documents/' . date("Ym"));
$resource->set_main_resource(false);
# if (!empty($objectData["image_visible" . $suffix])) $resource->set_resource_name($objectData["image_visible" . $suffix]);
# if (!empty($objectData["image_visible" . $suffix])) $resource->set_resource_name($objectData["image_visible" . $suffix]);
if (!empty($objectData["resource_owner" . $suffix])) $resource->set_owner($objectData["resource_owner" . $suffix]);
if (!empty($objectData["resource_creator" . $suffix])) $resource->set_creator($objectData["resource_creator" . $suffix]);
if (!empty($objectData["resource_rights" . $suffix])) $resource->set_rights($objectData["resource_rights" . $suffix]);
$resources[] = $resource;
}
if ($mainResourceSet === false and (!empty($images) or !empty($resources))) {
if (!empty($images)) $images[0]->set_main_image(true);
else if (!empty($resources)) $resources[0]->set_main_resource(true);
}
foreach ($images as $image) $object->appendImage($image);
foreach ($resources as $resources) $object->appendResource($resource);
}
*/
//
// Write it!
//
$object->set_objekt_publik($visibility);
$newObjectID = $objectWriter->writeObject($object, true, $insertOnly, $outputHandler);
}
}