Add class for loading info from distinctly_typed_strings table

This commit is contained in:
Joshua Ramon Enslin 2023-11-13 00:11:56 +01:00
parent c9b0e7085f
commit 54a30e683e
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -0,0 +1,44 @@
<?PHP
/**
* Checks the distinctly_typed_strings table for whether it
* contains a string.
*/
declare(strict_types = 1);
/**
* Checks the distinctly_typed_strings table for whether it
* contains a string.
*/
final class NodaDistinctlyTypedStrings {
/**
* Checks the vocabulary database whether it contains a given string.
*
* @param MDMysqli $mysqli_noda DB connection.
* @param string $lang Language to check in.
* @param string $search_term Search term.
*
* @return 'persinst'|'zeiten'|'orte'|'tag'|''
*/
public static function lookup(MDMysqli $mysqli_noda, string $lang, string $search_term):string {
$result = $mysqli_noda->query_by_stmt("SELECT `type`
FROM `distinctly_typed_strings`
WHERE `input_string` = ?
AND `language` = ?", "ss", $search_term, $lang);
if (!($cur = $result->fetch_row())) {
$result->close();
return '';
}
$result->close();
if (!in_array($cur[0], ['persinst', 'zeiten', 'orte', 'tag', ''], true)) {
throw new Exception("Distinctly typed string of unknown type: " . $cur[0]);
}
return $cur[0];
}
}