Add class for loading info from distinctly_typed_strings table
This commit is contained in:
parent
c9b0e7085f
commit
54a30e683e
44
src/NodaDistinctlyTypedStrings.php
Normal file
44
src/NodaDistinctlyTypedStrings.php
Normal 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];
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user