From 09518a0a6e3879f93abc3b9af56f4bfa2650c223 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Tue, 30 Jan 2024 00:07:31 +0100 Subject: [PATCH] Add function for getting time ID by stored rewrite --- src/NodaIDGetter.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/NodaIDGetter.php b/src/NodaIDGetter.php index a865209..4aafa6f 100644 --- a/src/NodaIDGetter.php +++ b/src/NodaIDGetter.php @@ -704,6 +704,37 @@ final class NodaIDGetter { } + /** + * Returns time ID by entry in time name rewriting 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 array + */ + public static function getTimeIDByRewrite(MDMysqli $mysqli_noda, string $lang, string $name):array { + + if (empty($name)) return []; + + $output = []; + + $timeRewriteResult = $mysqli_noda->query_by_stmt(" + SELECT `zeit_id` + FROM `zeit_rewriting` + WHERE `language` = ? + AND `input_name` = ?", "ss", $lang, $name); + + while ($timeRewriteData = $timeRewriteResult->fetch_row()) { + $output[] = $timeRewriteData[0]; + } + + $timeRewriteResult->close(); + + return $output; + + } + /** * Returns time ID by base name. * @@ -911,6 +942,10 @@ final class NodaIDGetter { return $timeIdByName; } + if (!empty($timeIdByRewrite = self::getTimeIDByRewrite($mysqli_noda, $lang, $name))) { + return end($timeIdByRewrite); + } + if ($instance !== "") { if (($timeIdByImportLog = self::getTimeIDByImportLog($mysqli_noda, $instance, $institution_id, $name)) !== 0) { return $timeIdByImportLog;