Add logically missing functions to NodaIDGetter
This commit is contained in:
parent
b7a49eb9b4
commit
1b702bfe31
@ -10,6 +10,36 @@ declare(strict_types = 1);
|
||||
* Contains static functions for getting IDs for noda entries by various means.
|
||||
*/
|
||||
final class NodaIDGetter {
|
||||
|
||||
//
|
||||
// Actors
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns persinst ID by name, checking the different options for it.
|
||||
*
|
||||
* @param MDMysqli $mysqli_noda Database connection.
|
||||
* @param string $lang Language to check in.
|
||||
* @param string $name Name of the persinst to search for.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getPersinstIDByName(MDMysqli $mysqli_noda, string $lang, string $name):int {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
if ($persinstByTransName = self::getPersinstIDByTransName($mysqli_noda, $lang, $name)) {
|
||||
return $persinstByTransName;
|
||||
}
|
||||
|
||||
if ($persinstByBaseName = self::getPersinstIDByBaseName($mysqli_noda, $name)) {
|
||||
return $persinstByBaseName;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns persinst ID by entry in persinst name rewriting table.
|
||||
*
|
||||
@ -74,6 +104,38 @@ final class NodaIDGetter {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns persinst ID by base name.
|
||||
*
|
||||
* @param MDMysqli $mysqli_noda Database connection.
|
||||
* @param string $name Name of the persinst to search for.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getPersinstIDByBaseName(MDMysqli $mysqli_noda, string $name):int {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$persinstByBaseNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `persinst_id`
|
||||
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];
|
||||
}
|
||||
else $output = 0;
|
||||
|
||||
$persinstByBaseNameResult->close();
|
||||
$persinstByBaseNameResult = null;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns place ID by entry in place noda table.
|
||||
*
|
||||
@ -143,6 +205,35 @@ final class NodaIDGetter {
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Places
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns place ID by name, checking the different options for it.
|
||||
*
|
||||
* @param MDMysqli $mysqli_noda Database connection.
|
||||
* @param string $lang Language to check in.
|
||||
* @param string $name Name of the place to search for.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getPlaceIDByName(MDMysqli $mysqli_noda, string $lang, string $name):int {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
if ($placeByTransName = self::getPlaceIDByTransName($mysqli_noda, $lang, $name)) {
|
||||
return $placeByTransName;
|
||||
}
|
||||
|
||||
if ($placeByBaseName = self::getPlaceIDByBaseName($mysqli_noda, $name)) {
|
||||
return $placeByBaseName;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns place ID by entry in place name rewriting table.
|
||||
*
|
||||
@ -303,6 +394,67 @@ final class NodaIDGetter {
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Tags
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns tag ID by name, checking the different options for it.
|
||||
*
|
||||
* @param MDMysqli $mysqli_noda Database connection.
|
||||
* @param string $lang Language to check in.
|
||||
* @param string $name Name of the tag to search for.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getTagIDByName(MDMysqli $mysqli_noda, string $lang, string $name):int {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
if ($tagByTransName = self::getTagIDByTransName($mysqli_noda, $lang, $name)) {
|
||||
return $tagByTransName;
|
||||
}
|
||||
|
||||
if ($tagByBaseName = self::getTagIDByBaseName($mysqli_noda, $name)) {
|
||||
return $tagByBaseName;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns tag ID by entry in tag name rewriting table.
|
||||
*
|
||||
* @param MDMysqli $mysqli_noda Database connection.
|
||||
* @param string $lang Language to check in.
|
||||
* @param string $name Name of the tag to search for.
|
||||
*
|
||||
* @return array<integer>
|
||||
*/
|
||||
public static function getTagIDByRewrite(MDMysqli $mysqli_noda, string $lang, string $name):array {
|
||||
|
||||
if (empty($name)) return [];
|
||||
|
||||
$output = [];
|
||||
|
||||
$tagRewriteResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `tag_id`
|
||||
FROM `tag_rewriting`
|
||||
WHERE `tag_language` = ?
|
||||
AND `input_name` = ?", "ss", $lang, $name);
|
||||
|
||||
while ($tagRewriteData = $tagRewriteResult->fetch_row()) {
|
||||
$output[] = $tagRewriteData[0];
|
||||
}
|
||||
|
||||
$tagRewriteResult->close();
|
||||
$tagRewriteResult = null;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns tag ID by entry in tag translations table.
|
||||
*
|
||||
@ -397,38 +549,6 @@ final class NodaIDGetter {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns tag ID by entry in tag name rewriting table.
|
||||
*
|
||||
* @param MDMysqli $mysqli_noda Database connection.
|
||||
* @param string $lang Language to check in.
|
||||
* @param string $name Name of the tag to search for.
|
||||
*
|
||||
* @return array<integer>
|
||||
*/
|
||||
public static function getTagIDByRewrite(MDMysqli $mysqli_noda, string $lang, string $name):array {
|
||||
|
||||
if (empty($name)) return [];
|
||||
|
||||
$output = [];
|
||||
|
||||
$tagRewriteResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `tag_id`
|
||||
FROM `tag_rewriting`
|
||||
WHERE `tag_language` = ?
|
||||
AND `input_name` = ?", "ss", $lang, $name);
|
||||
|
||||
while ($tagRewriteData = $tagRewriteResult->fetch_row()) {
|
||||
$output[] = $tagRewriteData[0];
|
||||
}
|
||||
|
||||
$tagRewriteResult->close();
|
||||
$tagRewriteResult = null;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns tag ID by entry in tag translations table.
|
||||
*
|
||||
@ -463,6 +583,97 @@ final class NodaIDGetter {
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Times
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns time ID by name, checking the different options for it.
|
||||
*
|
||||
* @param MDMysqli $mysqli_noda Database connection.
|
||||
* @param string $lang Language to check in.
|
||||
* @param string $name Name of the time to search for.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getTimeIDByName(MDMysqli $mysqli_noda, string $lang, string $name):int {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
if ($timeByTransName = self::getTimeIDByTransName($mysqli_noda, $lang, $name)) {
|
||||
return $timeByTransName;
|
||||
}
|
||||
|
||||
if ($timeByBaseName = self::getTimeIDByBaseName($mysqli_noda, $name)) {
|
||||
return $timeByBaseName;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns time ID by base name.
|
||||
*
|
||||
* @param MDMysqli $mysqli_noda Database connection.
|
||||
* @param string $name Name of the time to search for.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getTimeIDByBaseName(MDMysqli $mysqli_noda, string $name):int {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$timeByBaseNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `zeit_id`
|
||||
FROM `zeiten`
|
||||
WHERE `zeit_name` = ?
|
||||
LIMIT 2", "s", $name);
|
||||
|
||||
if ($timeByBaseData = $timeByBaseNameResult->fetch_row()) {
|
||||
$output = $timeByBaseData[0];
|
||||
}
|
||||
else $output = 0;
|
||||
|
||||
$timeByBaseNameResult->close();
|
||||
$timeByBaseNameResult = null;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns time ID by entry in time translations table.
|
||||
*
|
||||
* @param MDMysqli $mysqli_noda Database connection.
|
||||
* @param string $lang Language to check in.
|
||||
* @param string $name Name of the time to search for.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getTimeIDByTransName(MDMysqli $mysqli_noda, string $lang, string $name):int {
|
||||
|
||||
if (empty($name)) return 0;
|
||||
|
||||
$timeByTLNameResult = $mysqli_noda->query_by_stmt("
|
||||
SELECT `zeit_id`
|
||||
FROM `zeit_translation`
|
||||
WHERE `trans_name` = ?
|
||||
AND `trans_language` = ?
|
||||
LIMIT 2", "ss", $name, $lang);
|
||||
|
||||
if ($timeByTlData = $timeByTLNameResult->fetch_row()) {
|
||||
$output = $timeByTlData[0];
|
||||
}
|
||||
else $output = 0;
|
||||
|
||||
$timeByTLNameResult->close();
|
||||
$timeByTLNameResult = null;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns time ID by entry in time translations table.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user