Add functions for getting main synonym in list of synonyms

This commit is contained in:
Joshua Ramon Enslin 2023-08-31 03:28:38 +02:00
parent 05fb965d8c
commit 98f89762ff
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -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;
}
}