From ca13f36c0d85212100f67daddd1144000e17a68f Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Mon, 7 Dec 2020 13:43:07 +0100 Subject: [PATCH] Add function to get tag IDs by their translated names --- src/NodaIDGetter.php | 66 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/src/NodaIDGetter.php b/src/NodaIDGetter.php index fce7f91..5d2f2fa 100644 --- a/src/NodaIDGetter.php +++ b/src/NodaIDGetter.php @@ -10,7 +10,6 @@ declare(strict_types = 1); * Contains static functions for getting IDs for noda entries by various means. */ final class NodaIDGetter { - /** * Returns persinst ID by entry in persinst name rewriting table. * @@ -171,6 +170,70 @@ final class NodaIDGetter { } + /** + * Returns tag ID by entry in tag translations 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 integer + */ + public static function getTagIDByTransName(MDMysqli $mysqli_noda, string $lang, string $name):int { + + if (empty($name)) return 0; + + $tagByTLNameResult = $mysqli_noda->query_by_stmt(" + SELECT `tag_id` + FROM `tag_translation` + WHERE `trans_name` = ? + AND `trans_language` = ? + LIMIT 2", "ss", $name, $lang); + + if ($tagByTlData = $tagByTLNameResult->fetch_row()) { + $output = $tagByTlData[0]; + } + else $output = 0; + + $tagByTLNameResult->close(); + $tagByTLNameResult = null; + + return $output; + + } + + /** + * Returns tag ID by entry in tag noda table. + * + * @param MDMysqli $mysqli_noda Database connection. + * @param string $noda_source Language to check in. + * @param string $noda_nrinsource Name of the tag to search for. + * + * @return integer + */ + public static function getTagIDByNodaLink(MDMysqli $mysqli_noda, string $noda_source, string $noda_nrinsource):int { + + if (empty($noda_nrinsource)) return 0; + + $tagByNodaResult = $mysqli_noda->query_by_stmt(" + SELECT `tag_id` + FROM `noda_tag` + WHERE `noda_source` = ? + AND `noda_nrinsource` = ? + LIMIT 2", "ss", $noda_source, $noda_nrinsource); + + if ($tagByNodaData = $tagByNodaResult->fetch_row()) { + $output = $tagByNodaData[0]; + } + else $output = 0; + + $tagByNodaResult->close(); + $tagByNodaResult = null; + + return $output; + + } + /** * Returns tag ID by entry in tag name rewriting table. * @@ -202,5 +265,4 @@ final class NodaIDGetter { return $output; } - }