Add exception mode to redirect from object-tag relation type to

object-event relation (generic, e.g. if the tag is actually a time)
This commit is contained in:
2025-06-26 14:34:18 +02:00
parent b7330634d7
commit 1635d4130a
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,9 @@
<?PHP
declare(strict_types = 1);
/**
* Exception thrown in case a name entered for the relation between tag
* and object is actually an event type.
*/
final class MDImporterTagRelationTypeIsEventType extends Exception {
}

View File

@ -23,6 +23,8 @@ final class MDConcObjectTagRelTypes implements MDImporterConcordanceListInterfac
'description' => 'tag',
'emotion' => 'tag',
'atmosphäre' => 'tag',
'schlagwort hist.ereignis' => 'tag',
'schlagwort thema' => 'tag',
"motive" => "display_subject",
"motiv" => "display_subject",
@ -36,6 +38,31 @@ final class MDConcObjectTagRelTypes implements MDImporterConcordanceListInterfac
];
// Maps to event type
private const RELATION_TYPES_MAPPED_TO_EVENTS = [
'\'datierung\'' => ['event_type' => 24, 'target_section' => 'time'],
'datierung' => ['event_type' => 24, 'target_section' => 'time'],
'schlagwort zeitraum' => ['event_type' => 24, 'target_section' => 'time'],
];
/**
* Returns the mapped event type and event type target
* of a supposed tag-object relationship name.
*
* @param string $input Input string (relation type name).
*
* @return array{event_type: int, target_section: 'time'|'actor'|'place'}
*/
public static function getMappedEventType(string $input):array {
if (isset(self::RELATION_TYPES_MAPPED_TO_EVENTS[strtolower($input)])) {
return self::RELATION_TYPES_MAPPED_TO_EVENTS[strtolower($input)];
}
throw new MDImporterMissingConcordance("Unknown object-tag relationship type: " . $input);
}
/**
* Require a function for getting the concordance target.
*
@ -52,6 +79,10 @@ final class MDConcObjectTagRelTypes implements MDImporterConcordanceListInterfac
return self::RELATION_TYPE_NAMES[strtolower($input)];
}
if (isset(self::RELATION_TYPES_MAPPED_TO_EVENTS[strtolower($input)])) {
throw new MDImporterTagRelationTypeIsEventType("Tag-object relationship type is signifies not tags, but an event component.");
}
throw new MDImporterMissingConcordance("Unknown object-tag relationship type: " . $input);
}