Add class NodaIDGetter for collecting functions to identify noda

entities by available attributes
This commit is contained in:
Joshua Ramon Enslin 2020-09-20 22:40:40 +02:00 committed by Stefan Rohde-Enslin
parent 8f7df866d7
commit 7bbd50a586

174
src/NodaIDGetter.php Normal file
View File

@ -0,0 +1,174 @@
<?PHP
/**
* Contains class NodaIDGetter.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
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.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $lang Language to check in.
* @param string $name Name of the persinst to search for.
*
* @return integer
*/
public static function getPersinstIDByRewrite(MDMysqli $mysqli_noda, string $lang, string $name):int {
if (empty($name)) return 0;
$persinstRewriteResult = $mysqli_noda->query_by_stmt("
SELECT `persinst_id`
FROM `persinst_rewriting`
WHERE `language` = ?
AND `input_name` = ?
LIMIT 1", "ss", $lang, $name);
if ($persinstRewriteData = $persinstRewriteResult->fetch_row()) {
$output = $persinstRewriteData[0];
}
else $output = 0;
$persinstRewriteResult->close();
$persinstRewriteResult = null;
return $output;
}
/**
* Returns persinst ID by entry in persinst translations table.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $lang Language to check in.
* @param string $name Name of the persinst to search for.
*
* @return integer
*/
public static function getPersinstIDByTransName(MDMysqli $mysqli_noda, string $lang, string $name):int {
if (empty($name)) return 0;
$persinstByTLNameResult = $mysqli_noda->query_by_stmt("
SELECT `persinst_id`
FROM `persinst_translation`
WHERE `trans_name` = ?
AND `trans_language` = ?
LIMIT 2", "ss", $name, $lang);
if ($persinstByTlData = $persinstByTLNameResult->fetch_row()) {
$output = $persinstByTlData[0];
}
else $output = 0;
$persinstByTLNameResult->close();
$persinstByTLNameResult = null;
return $output;
}
/**
* Returns place ID by entry in place name rewriting table.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $lang Language to check in.
* @param string $name Name of the place to search for.
*
* @return integer
*/
public static function getPlaceIDByRewrite(MDMysqli $mysqli_noda, string $lang, string $name):int {
if (empty($name)) return 0;
$placeRewriteResult = $mysqli_noda->query_by_stmt("
SELECT `ort_id`
FROM `ort_rewriting`
WHERE `language` = ?
AND `input_name` = ?
LIMIT 1", "ss", $lang, $name);
if ($placeRewriteData = $placeRewriteResult->fetch_row()) {
$output = $placeRewriteData[0];
}
else $output = 0;
$placeRewriteResult->close();
$placeRewriteResult = null;
return $output;
}
/**
* Returns place ID by entry in place translations table.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $lang Language to check in.
* @param string $name Name of the place to search for.
*
* @return integer
*/
public static function getPlaceIDByTransName(MDMysqli $mysqli_noda, string $lang, string $name):int {
if (empty($name)) return 0;
$placeByTLNameResult = $mysqli_noda->query_by_stmt("
SELECT `ort_id`
FROM `ort_translation`
WHERE `trans_name` = ?
AND `trans_language` = ?
LIMIT 2", "ss", $name, $lang);
if ($placeByTlData = $placeByTLNameResult->fetch_row()) {
$output = $placeByTlData[0];
}
else $output = 0;
$placeByTLNameResult->close();
$placeByTLNameResult = null;
return $output;
}
/**
* Returns tag ID by entry in tag name rewriting 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 getTagIDByRewrite(MDMysqli $mysqli_noda, string $lang, string $name):int {
if (empty($name)) return 0;
$tagRewriteResult = $mysqli_noda->query_by_stmt("
SELECT `tag_id`
FROM `tag_rewriting`
WHERE `tag_language` = ?
AND `input_name` = ?
LIMIT 1", "ss", $lang, $name);
if ($tagRewriteData = $tagRewriteResult->fetch_row()) {
$output = $tagRewriteData[0];
}
else $output = 0;
$tagRewriteResult->close();
$tagRewriteResult = null;
return $output;
}
}