Extend NodaNameGetter with functions for getting single entries' correct

place, tag, time, and actor names
This commit is contained in:
Joshua Ramon Enslin 2022-02-06 23:30:22 +01:00
parent a4be5e876c
commit c52550c789
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -195,4 +195,154 @@ final class NodaNameGetter {
return $output;
}
/**
* Static function for getting single tag names by ID.
*
* @param MDMysqli $mysqli_noda DB connection.
* @param string $lang Language.
* @param integer $tag_id Tag IDs.
*
* @return string
*/
public static function getTagName(MDMysqli $mysqli_noda, string $lang, int $tag_id):string {
$output = [];
// Get translations
$result = $mysqli_noda->query_by_stmt("SELECT `trans_name`
FROM `tag_translation`
WHERE `trans_language` = '" . $mysqli_noda->escape_string($lang) . "'
AND `tag_id` = ?", "i", $tag_id);
if ($cur = $result->fetch_row()) {
$result->close();
return MD_STD_IN::sanitize_text($cur[0]);
}
$result->close();
$result = $mysqli_noda->query_by_stmt("SELECT `tag_name`
FROM `tag`
WHERE `tag_id` = ?", "i", $tag_id);
if ($cur = $result->fetch_row()) {
$result->close();
return MD_STD_IN::sanitize_text($cur[0]);
}
$result->close();
return "";
}
/**
* Static function for getting single actor names by ID.
*
* @param MDMysqli $mysqli_noda DB connection.
* @param string $lang Language.
* @param integer $persinst_id Actor IDs.
*
* @return string
*/
public static function getPersinstName(MDMysqli $mysqli_noda, string $lang, int $persinst_id):string {
// Get translations
$result = $mysqli_noda->query_by_stmt("SELECT `trans_name`
FROM `persinst_translation`
WHERE `trans_language` = '" . $mysqli_noda->escape_string($lang) . "'
AND `persinst_id` = ?", "i", $persinst_id);
if ($cur = $result->fetch_row()) {
$result->close();
return MD_STD_IN::sanitize_text($cur[0]);
}
$result->close();
$result = $mysqli_noda->query_by_stmt("SELECT `persinst_name_en`
FROM `persinst`
WHERE `persinst_id` = ?", "i", $persinst_id);
if ($cur = $result->fetch_row()) {
$result->close();
return MD_STD_IN::sanitize_text($cur[0]);
}
$result->close();
return "";
}
/**
* Static function for getting single place names by ID.
*
* @param MDMysqli $mysqli_noda DB connection.
* @param string $lang Language.
* @param integer $place_id Place IDs.
*
* @return string
*/
public static function getPlaceName(MDMysqli $mysqli_noda, string $lang, int $place_id):string {
// Get translations
$result = $mysqli_noda->query_by_stmt("SELECT `trans_name`
FROM `ort_translation`
WHERE `trans_language` = '" . $mysqli_noda->escape_string($lang) . "'
AND `ort_id` = ?", "i", $place_id);
if ($cur = $result->fetch_row()) {
$result->close();
return MD_STD_IN::sanitize_text($cur[0]);
}
$result->close();
$result = $mysqli_noda->query_by_stmt("SELECT `ort_name`
FROM `orte`
WHERE `ort_id` = ?", "i", $place_id);
if ($cur = $result->fetch_row()) {
$result->close();
return MD_STD_IN::sanitize_text($cur[0]);
}
$result->close();
return "";
}
/**
* Static function for getting single time names by ID.
*
* @param MDMysqli $mysqli_noda DB connection.
* @param string $lang Language.
* @param integer $time_id Time IDs.
*
* @return string
*/
public static function getTimeName(MDMysqli $mysqli_noda, string $lang, int $time_id):string {
// Get translations
$result = $mysqli_noda->query_by_stmt("SELECT `trans_name`
FROM `zeit_translation`
WHERE `trans_language` = '" . $mysqli_noda->escape_string($lang) . "'
AND `zeit_id` = ?", "i", $time_id);
if ($cur = $result->fetch_row()) {
$result->close();
return MD_STD_IN::sanitize_text($cur[0]);
}
$result->close();
$result = $mysqli_noda->query_by_stmt("SELECT `zeit_name`
FROM `zeiten`
WHERE `zeit_id` = ?", "i", $time_id);
if ($cur = $result->fetch_row()) {
$result->close();
return MD_STD_IN::sanitize_text($cur[0]);
}
$result->close();
return "";
}
}