From d6c514c208f3f2771316c58f4c340bee809e9d7e Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Mon, 20 Nov 2023 13:43:05 +0100 Subject: [PATCH] Add functions to check for actor IDs by name while including their life dates --- src/NodaIDGetter.php | 101 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/src/NodaIDGetter.php b/src/NodaIDGetter.php index 206a1b9..a865209 100644 --- a/src/NodaIDGetter.php +++ b/src/NodaIDGetter.php @@ -40,6 +40,33 @@ final class NodaIDGetter { } + /** + * 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. + * @param string $birth Birth year. + * @param string $death Death year. + * + * @return integer + */ + public static function getPersinstIDByNamePlusYears(MDMysqli $mysqli_noda, string $lang, string $name, string $birth, string $death):int { + + if (empty($name)) return 0; + + if ($persinstByTransName = self::getPersinstIDByTransNamePlusYears($mysqli_noda, $lang, $name, $birth, $death)) { + return $persinstByTransName; + } + + if ($persinstByBaseName = self::getPersinstIDByBaseNamePlusYears($mysqli_noda, $name, $birth, $death)) { + return $persinstByBaseName; + } + + return 0; + + } + /** * Returns persinst ID by entry in persinst name rewriting table. * @@ -102,6 +129,43 @@ final class NodaIDGetter { } + /** + * Returns persinst ID by entry in persinst translations table + * plus birth and death. + * + * @param MDMysqli $mysqli_noda Database connection. + * @param string $lang Language to check in. + * @param string $name Name of the persinst to search for. + * @param string $birth Birth year. + * @param string $death Death year. + * + * @return integer + */ + public static function getPersinstIDByTransNamePlusYears(MDMysqli $mysqli_noda, string $lang, string $name, string $birth, string $death):int { + + if (empty($name)) return 0; + + $persinstByTLNameResult = $mysqli_noda->query_by_stmt(" + SELECT `persinst_translation`.`persinst_id` + FROM `persinst_translation`, `persinst` + WHERE `persinst_translation`.`persinst_id` = `persinst`.`persinst_id` + AND `trans_name` = ? + AND `trans_language` = ? + AND `persinst_geburtsjahr` = ? + AND `persinst_sterbejahr` = ? + LIMIT 2", "ssss", $name, $lang, $birth, $death); + + if ($persinstByTlData = $persinstByTLNameResult->fetch_row()) { + $output = $persinstByTlData[0]; + } + else $output = 0; + + $persinstByTLNameResult->close(); + + return $output; + + } + /** * Returns persinst ID by base name. * @@ -133,6 +197,43 @@ 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. + * @param string $birth Birth year. + * @param string $death Death year. + * + * @return integer + */ + public static function getPersinstIDByBaseNamePlusYears(MDMysqli $mysqli_noda, string $name, string $birth, string $death):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`, ')') = ? + ) + AND `persinst_geburtsjahr` = ? + AND `persinst_sterbejahr` = ? + LIMIT 2", "sssss", $name, $name, $name, $birth, $death); + + if ($persinstByBaseData = $persinstByBaseNameResult->fetch_row()) { + $output = $persinstByBaseData[0]; + } + else $output = 0; + + $persinstByBaseNameResult->close(); + + return $output; + + } + /** * Returns place ID by entry in place noda table. *