Add functions for getting IDs by any translated entry irrespective of

the language
This commit is contained in:
Joshua Ramon Enslin 2025-02-12 17:15:19 +01:00
parent 1cf0f9858a
commit 18438251a7
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -155,6 +155,37 @@ final class NodaIDGetter {
}
/**
* Returns persinst ID by entry in persinst translations table,
* irrespective of language.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $name Name of the persinst to search for.
*
* @return integer
*/
public static function getPersinstIDByAnyTransName(MDMysqli $mysqli_noda, string $name):int {
if (empty($name)) return 0;
$result = $mysqli_noda->query_by_stmt("
SELECT `persinst_id`, `trans_name`
FROM `persinst_translation`
WHERE `trans_name` = ?
LIMIT 2", "s", $name);
while ($cur = $result->fetch_row()) {
if (self::_stri_matches($cur[1], $name)) {
$result->close();
return (int)$cur[0];
}
}
$result->close();
return 0;
}
/**
* Returns persinst ID by entry in persinst translations table
* plus birth and death.
@ -456,6 +487,37 @@ final class NodaIDGetter {
}
/**
* Returns place ID by entry in place translations table, irrespective of
* language.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $name Name of the place to search for.
*
* @return integer
*/
public static function getPlaceIDByAnyTransName(MDMysqli $mysqli_noda, string $name):int {
if (empty($name)) return 0;
$result = $mysqli_noda->query_by_stmt("
SELECT `ort_id`, `trans_name`
FROM `ort_translation`
WHERE `trans_name` = ?
LIMIT 2", "s", $name);
while ($cur = $result->fetch_row()) {
if (self::_stri_matches($cur[1], $name)) {
$result->close();
return (int)$cur[0];
}
}
$result->close();
return 0;
}
/**
* Returns place ID by entry in place noda table.
*
@ -647,6 +709,37 @@ final class NodaIDGetter {
}
/**
* Returns tag ID by entry in tag translations table,
* irrespective of language.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $name Name of the tag to search for.
*
* @return integer
*/
public static function getTagIDByAnyTransName(MDMysqli $mysqli_noda, string $name):int {
if (empty($name)) return 0;
$result = $mysqli_noda->query_by_stmt("
SELECT `tag_id`, `trans_name`
FROM `tag_translation`
WHERE `trans_name` = ?
LIMIT 2", "s", $name);
while ($cur = $result->fetch_row()) {
if (self::_stri_matches($name, $cur[1])) {
$result->close();
return (int)$cur[0];
}
}
$result->close();
return 0;
}
/**
* Returns tag ID by entry in tag noda table.
*
@ -838,6 +931,36 @@ final class NodaIDGetter {
}
/**
* Returns time ID by entry in time translations table.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $name Name of the time to search for.
*
* @return integer
*/
public static function getTimeIDByAnyTransName(MDMysqli $mysqli_noda, string $name):int {
if (empty($name)) return 0;
$result = $mysqli_noda->query_by_stmt("
SELECT `zeit_id`, `trans_name`
FROM `zeit_translation`
WHERE `trans_name` = ?
LIMIT 2", "s", $name);
while ($cur = $result->fetch_row()) {
if (self::_stri_matches($name, $cur[1])) {
$result->close();
return (int)$cur[0];
}
}
$result->close();
return 0;
}
/**
* Returns time ID by entry in time translations table.
*
@ -1025,18 +1148,34 @@ final class NodaIDGetter {
$output['tag'][] = $tag_id;
++$output['count'];
}
else if (($tag_id_by_tl = NodaIDGetter::getTagIDByAnyTransName($mysqli_noda, $phrase)) !== 0 && !in_array($tag_id_by_tl, $output['tag'], true)) {
$output['tag'][] = $tag_id_by_tl;
++$output['count'];
}
else if (($place_id = NodaIDGetter::getPlaceIDByNamesAndRewrites($mysqli_noda, $lang, $phrase)) !== 0 && !in_array($place_id, $output['place'], true)) {
$output['place'][] = $place_id;
++$output['count'];
}
else if (($place_id = NodaIDGetter::getPlaceIDByAnyTransName($mysqli_noda, $phrase)) !== 0 && !in_array($place_id, $output['place'], true)) {
$output['place'][] = $place_id;
++$output['count'];
}
else if (($persinst_id = NodaIDGetter::getPersinstIDByNamesAndRewrites($mysqli_noda, $lang, $phrase, '', '')) !== 0 && !in_array($persinst_id, $output['actor'], true)) {
$output['actor'][] = $persinst_id;
++$output['count'];
}
else if (($persinst_id = NodaIDGetter::getPersinstIDByAnyTransName($mysqli_noda, $phrase, '', '')) !== 0 && !in_array($persinst_id, $output['actor'], true)) {
$output['actor'][] = $persinst_id;
++$output['count'];
}
else if (($time_id = NodaIDGetter::getTimeIDByNamesAndRewrites($mysqli_noda, $lang, $phrase)) !== 0 && !in_array($time_id, $output['time'], true)) {
$output['time'][] = $time_id;
++$output['count'];
}
else if (($time_id = NodaIDGetter::getTimeIDByAnyTransName($mysqli_noda, $phrase)) !== 0 && !in_array($time_id, $output['time'], true)) {
$output['time'][] = $time_id;
++$output['count'];
}
}