|
|
|
@@ -11,7 +11,7 @@ declare(strict_types = 1);
|
|
|
|
|
*/
|
|
|
|
|
final class NodaValidationHelper {
|
|
|
|
|
|
|
|
|
|
const ACTOR_DESCRIPTION_REQUIRED_DISTINCT_CHARS = 3;
|
|
|
|
|
private const ACTOR_DESCRIPTION_REQUIRED_DISTINCT_CHARS = 3;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validates an actor description for completeness. Of course, only an informed
|
|
|
|
@@ -120,4 +120,93 @@ final class NodaValidationHelper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if an actor name is valid.
|
|
|
|
|
* Returns 0 if the actor can be added as a new one / actor name can be used as a new one.
|
|
|
|
|
* Returns the ID for already known actors.
|
|
|
|
|
* Throws an exception if the actor is blacklisted.
|
|
|
|
|
*
|
|
|
|
|
* @param MDMysqli $mysqli_noda DB connection to vocabulary.
|
|
|
|
|
* @param string $lang User language.
|
|
|
|
|
* @param string $persinst_name Actor name.
|
|
|
|
|
* @param string $persinst_name_en Actor name (short).
|
|
|
|
|
* @param string $persinst_geburtsjahr Birth year.
|
|
|
|
|
* @param string $persinst_sterbejahr Death year.
|
|
|
|
|
* @param string $context_identifier Context / instance identifier.
|
|
|
|
|
* @param integer $institution_id Institution ID.
|
|
|
|
|
*
|
|
|
|
|
* @return integer
|
|
|
|
|
*/
|
|
|
|
|
public static function checkPersinstNameIsUsable(MDMysqli $mysqli_noda, string $lang, string $persinst_name, string $persinst_name_en, string $persinst_geburtsjahr, string $persinst_sterbejahr, string $context_identifier, int $institution_id):int {
|
|
|
|
|
|
|
|
|
|
if ($storedType = NodaDistinctlyTypedStrings::lookup($mysqli_noda, $lang, $persinst_name_en)) {
|
|
|
|
|
|
|
|
|
|
if ($storedType !== 'persinst') {
|
|
|
|
|
throw new MDpageParameterMissingException("This term is marked to be distinctly a " . $storedType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Special case: ? or "unbekannt" as a given name.
|
|
|
|
|
if (str_starts_with($persinst_name_en, '? ') || str_starts_with(strtolower($persinst_name_en), 'unbekannt ') ) {
|
|
|
|
|
throw new MDBlacklistedInputException("Term is blacklisted");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if the place name is in the current language's blacklist.
|
|
|
|
|
if (NodaBlacklistedTerms::checkPersinstBlacklistedInDb($mysqli_noda, $lang, $persinst_name) === true) {
|
|
|
|
|
throw new MDBlacklistedInputException("Term is blacklisted");
|
|
|
|
|
}
|
|
|
|
|
if (NodaBlacklistedTerms::checkPersinstBlacklistedInDb($mysqli_noda, $lang, $persinst_name_en) === true) {
|
|
|
|
|
throw new MDBlacklistedInputException("Term is blacklisted");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($existingPersinstId = NodaIDGetter::getPersinstIDByNamesAndRewrites($mysqli_noda, $lang, $persinst_name_en, $persinst_geburtsjahr, $persinst_sterbejahr, $context_identifier, $institution_id)) {
|
|
|
|
|
return $existingPersinstId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($existingPersinstId = NodaIDGetter::getPersinstIDByNamesAndRewrites($mysqli_noda, $lang, $persinst_name, $persinst_geburtsjahr, $persinst_sterbejahr, $context_identifier, $institution_id)) {
|
|
|
|
|
return $existingPersinstId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if an place name is valid.
|
|
|
|
|
* Returns 0 if the place can be added as a new one / place name can be used as a new one.
|
|
|
|
|
* Returns the ID for already known places.
|
|
|
|
|
* Throws an exception if the place is blacklisted.
|
|
|
|
|
*
|
|
|
|
|
* @param MDMysqli $mysqli_noda DB connection to vocabulary.
|
|
|
|
|
* @param string $lang User language.
|
|
|
|
|
* @param string $place_name Place name.
|
|
|
|
|
* @param string $context_identifier Context / instance identifier.
|
|
|
|
|
* @param integer $institution_id Institution ID.
|
|
|
|
|
*
|
|
|
|
|
* @return integer
|
|
|
|
|
*/
|
|
|
|
|
public static function checkPlaceNameIsUsable(MDMysqli $mysqli_noda, string $lang, string $place_name, string $context_identifier, int $institution_id):int {
|
|
|
|
|
|
|
|
|
|
if ($storedType = NodaDistinctlyTypedStrings::lookup($mysqli_noda, $lang, $place_name)) {
|
|
|
|
|
|
|
|
|
|
if ($storedType !== 'orte') {
|
|
|
|
|
throw new MDpageParameterMissingException("This term is marked to be distinctly a " . $storedType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if the place name is in the current language's blacklist.
|
|
|
|
|
if (NodaBlacklistedTerms::checkPlaceBlacklistedInDb($mysqli_noda, $lang, $place_name) === true) {
|
|
|
|
|
throw new MDBlacklistedInputException("Term is blacklisted");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($existingPlaceId = NodaIDGetter::getPlaceIDByNamesAndRewrites($mysqli_noda, $lang, $place_name, $context_identifier, $institution_id)) {
|
|
|
|
|
return $existingPlaceId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|