Respect diacritics when looking up tag, actor, .. IDs
This commit is contained in:
@ -10,6 +10,30 @@ declare(strict_types = 1);
|
||||
* Contains static functions for getting IDs for noda entries by various means.
|
||||
*/
|
||||
final class NodaIDGetter {
|
||||
/**
|
||||
* Comparison operation that allows for equality but also returns true
|
||||
* if capitalization differs. If diacritics are available in one case
|
||||
* and not in the other, there will be no match.
|
||||
* This is needed to identify sufficiently exact matches despite a table
|
||||
* collation of *_ci in MySQL.
|
||||
*
|
||||
* @param string $string_one First string in comparison.
|
||||
* @param string $string_two Second string in comparison.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private static function _stri_matches(string $string_one, string $string_two):bool {
|
||||
|
||||
if ($string_one === $string_two) {
|
||||
return true;
|
||||
}
|
||||
if (\strtolower($string_one) === \strtolower($string_two)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Actors
|
||||
@ -80,21 +104,22 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$persinstRewriteResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_id`, `input_name`
|
||||
FROM `persinst_rewriting`
|
||||
WHERE `language` = ?
|
||||
AND `input_name` = ?
|
||||
LIMIT 1", "ss", $lang, $name);
|
||||
|
||||
if ($persinstRewriteData = $persinstRewriteResult->fetch_row()) {
|
||||
$output = $persinstRewriteData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($cur[1], $name)) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$persinstRewriteResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -111,21 +136,22 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$persinstByTLNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_id`, `trans_name`
|
||||
FROM `persinst_translation`
|
||||
WHERE `trans_name` = ?
|
||||
AND `trans_language` = ?
|
||||
LIMIT 2", "ss", $name, $lang);
|
||||
|
||||
if ($persinstByTlData = $persinstByTLNameResult->fetch_row()) {
|
||||
$output = $persinstByTlData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($cur[1], $name)) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$persinstByTLNameResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -145,8 +171,8 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$persinstByTLNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_translation`.`persinst_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_translation`.`persinst_id`, `trans_name`
|
||||
FROM `persinst_translation`, `persinst`
|
||||
WHERE `persinst_translation`.`persinst_id` = `persinst`.`persinst_id`
|
||||
AND `trans_name` = ?
|
||||
@ -155,14 +181,15 @@ final class NodaIDGetter {
|
||||
AND `persinst_sterbejahr` = ?
|
||||
LIMIT 2", "ssss", $name, $lang, $birth, $death);
|
||||
|
||||
if ($persinstByTlData = $persinstByTLNameResult->fetch_row()) {
|
||||
$output = $persinstByTlData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($cur[1], $name)) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$persinstByTLNameResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -178,22 +205,23 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$persinstByBaseNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_id`, `persinst_anzeigename`, `persinst_name`, CONCAT(`persinst_name`, ' (', `persinst_geburtsjahr`, '-', `persinst_sterbejahr`, ')')
|
||||
FROM `persinst`
|
||||
WHERE `persinst_anzeigename` = ?
|
||||
OR `persinst_name` = ?
|
||||
OR CONCAT(`persinst_name`, ' (', `persinst_geburtsjahr`, '-', `persinst_sterbejahr`, ')') = ?
|
||||
LIMIT 2", "sss", $name, $name, $name);
|
||||
|
||||
if ($persinstByBaseData = $persinstByBaseNameResult->fetch_row()) {
|
||||
$output = $persinstByBaseData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($cur[1], $name) || self::_stri_matches($cur[2], $name) || self::_stri_matches($cur[3], $name)) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$persinstByBaseNameResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -211,8 +239,8 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$persinstByBaseNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_id`, `persinst_anzeigename`, `persinst_name`, CONCAT(`persinst_name`, ' (', `persinst_geburtsjahr`, '-', `persinst_sterbejahr`, ')')
|
||||
FROM `persinst`
|
||||
WHERE (
|
||||
`persinst_anzeigename` = ?
|
||||
@ -223,14 +251,15 @@ final class NodaIDGetter {
|
||||
AND `persinst_sterbejahr` = ?
|
||||
LIMIT 2", "sssss", $name, $name, $name, $birth, $death);
|
||||
|
||||
if ($persinstByBaseData = $persinstByBaseNameResult->fetch_row()) {
|
||||
$output = $persinstByBaseData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($cur[1], $name) || self::_stri_matches($cur[2], $name) || self::_stri_matches($cur[3], $name)) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$persinstByBaseNameResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -284,22 +313,23 @@ final class NodaIDGetter {
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$lookUpName = $name . $birthYear . $deathYear;
|
||||
$persinstByImportLogResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_id`, `input_string`
|
||||
FROM `persinst_logged_imports`
|
||||
WHERE `instance` = ?
|
||||
AND `institution_id` = ?
|
||||
AND `input_string` = ?
|
||||
LIMIT 2", "sis", $instance, $institution_id, $lookUpName);
|
||||
|
||||
if ($persinstByImportLogData = $persinstByImportLogResult->fetch_row()) {
|
||||
$output = $persinstByImportLogData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($cur[1], $lookUpName)) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$persinstByImportLogResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -345,21 +375,22 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$placeRewriteResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `ort_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `ort_id`, `input_name`
|
||||
FROM `ort_rewriting`
|
||||
WHERE `language` = ?
|
||||
AND `input_name` = ?
|
||||
LIMIT 1", "ss", $lang, $name);
|
||||
|
||||
if ($placeRewriteData = $placeRewriteResult->fetch_row()) {
|
||||
$output = $placeRewriteData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($cur[1], $name)) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$placeRewriteResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -375,20 +406,21 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$placeByBaseNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `ort_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `ort_id`, `ort_name`
|
||||
FROM `orte`
|
||||
WHERE `ort_name` = ?
|
||||
LIMIT 2", "s", $name);
|
||||
|
||||
if ($placeByBaseData = $placeByBaseNameResult->fetch_row()) {
|
||||
$output = $placeByBaseData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($cur[1], $name)) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$placeByBaseNameResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -405,21 +437,22 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$placeByTLNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `ort_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `ort_id`, `trans_name`
|
||||
FROM `ort_translation`
|
||||
WHERE `trans_name` = ?
|
||||
AND `trans_language` = ?
|
||||
LIMIT 2", "ss", $name, $lang);
|
||||
|
||||
if ($placeByTlData = $placeByTLNameResult->fetch_row()) {
|
||||
$output = $placeByTlData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($cur[1], $name)) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$placeByTLNameResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -470,22 +503,23 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$placeByImportLogResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `ort_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `ort_id`, `input_string`
|
||||
FROM `orte_logged_imports`
|
||||
WHERE `instance` = ?
|
||||
AND `institution_id` = ?
|
||||
AND `input_string` = ?
|
||||
LIMIT 2", "sis", $instance, $institution_id, $name);
|
||||
|
||||
if ($placeByImportLogData = $placeByImportLogResult->fetch_row()) {
|
||||
$output = $placeByImportLogData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($cur[1], $name)) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$placeByImportLogResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -533,17 +567,19 @@ final class NodaIDGetter {
|
||||
|
||||
$output = [];
|
||||
|
||||
$tagRewriteResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `tag_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `tag_id`, `input_name`
|
||||
FROM `tag_rewriting`
|
||||
WHERE `tag_language` = ?
|
||||
AND `input_name` = ?", "ss", $lang, $name);
|
||||
|
||||
while ($tagRewriteData = $tagRewriteResult->fetch_row()) {
|
||||
$output[] = $tagRewriteData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($name, $cur[1])) {
|
||||
$output[] = $cur[0];
|
||||
}
|
||||
}
|
||||
|
||||
$tagRewriteResult->close();
|
||||
$result->close();
|
||||
|
||||
return $output;
|
||||
|
||||
@ -561,20 +597,21 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$tagByBaseNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `tag_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `tag_id`, `tag_name`
|
||||
FROM `tag`
|
||||
WHERE `tag_name` = ?
|
||||
LIMIT 2", "s", $name);
|
||||
|
||||
if ($tagByBaseData = $tagByBaseNameResult->fetch_row()) {
|
||||
$output = $tagByBaseData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($name, $cur[1])) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$tagByBaseNameResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -591,21 +628,22 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$tagByTLNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `tag_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `tag_id`, `trans_name`
|
||||
FROM `tag_translation`
|
||||
WHERE `trans_name` = ?
|
||||
AND `trans_language` = ?
|
||||
LIMIT 2", "ss", $name, $lang);
|
||||
|
||||
if ($tagByTlData = $tagByTLNameResult->fetch_row()) {
|
||||
$output = $tagByTlData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($name, $cur[1])) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$tagByTLNameResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -656,22 +694,23 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$tagByImportLogResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `tag_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `tag_id`, `input_string`
|
||||
FROM `tag_logged_imports`
|
||||
WHERE `instance` = ?
|
||||
AND `institution_id` = ?
|
||||
AND `input_string` = ?
|
||||
LIMIT 2", "sis", $instance, $institution_id, $name);
|
||||
|
||||
if ($tagByImportLogData = $tagByImportLogResult->fetch_row()) {
|
||||
$output = $tagByImportLogData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($name, $cur[1])) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$tagByImportLogResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -719,20 +758,21 @@ final class NodaIDGetter {
|
||||
|
||||
$output = [];
|
||||
|
||||
$timeRewriteResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `zeit_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `zeit_id`, `input_name`
|
||||
FROM `zeit_rewriting`
|
||||
WHERE `language` = ?
|
||||
AND `input_name` = ?", "ss", $lang, $name);
|
||||
|
||||
if ($timeRewriteData = $timeRewriteResult->fetch_row()) {
|
||||
$output = (int)$timeRewriteData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($name, $cur[1])) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$timeRewriteResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -748,20 +788,21 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$timeByBaseNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `zeit_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `zeit_id`, `zeit_name`
|
||||
FROM `zeiten`
|
||||
WHERE `zeit_name` = ?
|
||||
LIMIT 2", "s", $name);
|
||||
|
||||
if ($timeByBaseData = $timeByBaseNameResult->fetch_row()) {
|
||||
$output = $timeByBaseData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($name, $cur[1])) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$timeByBaseNameResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -778,21 +819,22 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$timeByTLNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `zeit_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `zeit_id`, `trans_name`
|
||||
FROM `zeit_translation`
|
||||
WHERE `trans_name` = ?
|
||||
AND `trans_language` = ?
|
||||
LIMIT 2", "ss", $name, $lang);
|
||||
|
||||
if ($timeByTlData = $timeByTLNameResult->fetch_row()) {
|
||||
$output = $timeByTlData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($name, $cur[1])) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$timeByTLNameResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@ -810,22 +852,23 @@ final class NodaIDGetter {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$timeByImportLogResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `zeit_id`
|
||||
$result = $mysqli_noda->query_by_stmt("
|
||||
SELECT `zeit_id`, `input_string`
|
||||
FROM `zeiten_logged_imports`
|
||||
WHERE `instance` = ?
|
||||
AND `institution_id` = ?
|
||||
AND `input_string` = ?
|
||||
LIMIT 2", "sis", $instance, $institution_id, $name);
|
||||
|
||||
if ($timeByImportLogData = $timeByImportLogResult->fetch_row()) {
|
||||
$output = $timeByImportLogData[0];
|
||||
while ($cur = $result->fetch_row()) {
|
||||
if (self::_stri_matches($name, $cur[1])) {
|
||||
$result->close();
|
||||
return (int)$cur[0];
|
||||
}
|
||||
}
|
||||
else $output = 0;
|
||||
$result->close();
|
||||
|
||||
$timeByImportLogResult->close();
|
||||
|
||||
return $output;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user