From 0b5d5bdd120dcafda6bc6f2b0f7ee8c02f877d0a Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Thu, 31 Aug 2023 03:28:38 +0200 Subject: [PATCH] Add functions for getting main synonym in list of synonyms --- src/NodaLinkedEntityGetter.php | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/NodaLinkedEntityGetter.php b/src/NodaLinkedEntityGetter.php index 9caca00..a4bf4d5 100644 --- a/src/NodaLinkedEntityGetter.php +++ b/src/NodaLinkedEntityGetter.php @@ -117,4 +117,60 @@ final class NodaLinkedEntityGetter { return array_keys($output); } + + /** + * Returns the main synonym of a tag (or the tag ID itself, if there are + * no synonyms). + * + * @param MDMysqli $mysqli_noda DB connection. + * @param integer $tag_id ID of the tag to check. + * + * @return integer + */ + public static function getMainTagSynonymId(MDMysqli $mysqli_noda, int $tag_id):int { + + $result = $mysqli_noda->query_by_stmt("SELECT `tag_syn_main` + FROM `tag_syn` + WHERE `tag_syn_sub` = ? + LIMIT 1", "i", $tag_id); + + if ($cur = $result->fetch_row()) { + $output = MD_STD_IN::sanitize_id($cur[0]); + } + else { + $output = $tag_id; + } + $result->close(); + + return $output; + + } + + /** + * Returns the main synonym of a place (or the place ID itself, if there are + * no synonyms). + * + * @param MDMysqli $mysqli_noda DB connection. + * @param integer $place_id ID of the place to check. + * + * @return integer + */ + public static function getMainPlaceSynonymId(MDMysqli $mysqli_noda, int $place_id):int { + + $result = $mysqli_noda->query_by_stmt("SELECT `ort_syn_main` + FROM `ort_syn` + WHERE `ort_syn_sub` = ? + LIMIT 1", "i", $place_id); + + if ($cur = $result->fetch_row()) { + $output = MD_STD_IN::sanitize_id($cur[0]); + } + else { + $output = $place_id; + } + $result->close(); + + return $output; + + } }