MDNodaHelpers/src/NodaIDGetter.php

374 lines
11 KiB
PHP

<?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 persinst ID by entry in persinst translations table.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $instance Instance in which the import was run.
* @param integer $institution_id ID of the importing institution.
* @param string $name Name of the persinst to search for.
* @param string $birthYear Year of birth. Optional.
* @param string $deathYear Year of death. Optional.
*
* @return integer
*/
public static function getPersinstIDByImportLog(MDMysqli $mysqli_noda, string $instance, int $institution_id, string $name, string $birthYear = "", string $deathYear = ""):int {
if (empty($name)) return 0;
$lookUpName = $name . $birthYear . $deathYear;
$persinstByImportLogResult = $mysqli_noda->query_by_stmt("
SELECT `persinst_id`
FROM `persinst_logged_imports`
WHERE `instance` = ?
AND `institution_id` = ?
AND `input_string` = ?
LIMIT 2", "sis", $instance, $institution_id, $lookUpName);
if ($persinstByImportLogData = $persinstByImportLogResult->fetch_row()) {
$output = $persinstByImportLogData[0];
}
else $output = 0;
$persinstByImportLogResult->close();
$persinstByImportLogResult = 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 place ID by entry in place noda table.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $noda_source Language to check in.
* @param string $noda_nrinsource Name of the place to search for.
*
* @return integer
*/
public static function getPlaceIDByNodaLink(MDMysqli $mysqli_noda, string $noda_source, string $noda_nrinsource):int {
if (empty($noda_nrinsource)) return 0;
$placeByNodaResult = $mysqli_noda->query_by_stmt("
SELECT `ort_id`
FROM `noda_orte`
WHERE `noda_source` = ?
AND `noda_nrinsource` = ?
LIMIT 2", "ss", $noda_source, $noda_nrinsource);
if ($placeByNodaData = $placeByNodaResult->fetch_row()) {
$output = $placeByNodaData[0];
}
else $output = 0;
$placeByNodaResult->close();
$placeByNodaResult = null;
return $output;
}
/**
* Returns place ID by entry in place translations table.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $instance Instance in which the import was run.
* @param integer $institution_id ID of the importing institution.
* @param string $name Name of the place to search for.
*
* @return integer
*/
public static function getPlaceIDByImportLog(MDMysqli $mysqli_noda, string $instance, int $institution_id, string $name):int {
if (empty($name)) return 0;
$placeByImportLogResult = $mysqli_noda->query_by_stmt("
SELECT `ort_id`
FROM `orte_logged_imports`
WHERE `instance` = ?
AND `institution_id` = ?
AND `input_string` = ?
LIMIT 2", "sis", $instance, $institution_id, $name);
if ($placeByImportLogData = $placeByImportLogResult->fetch_row()) {
$output = $placeByImportLogData[0];
}
else $output = 0;
$placeByImportLogResult->close();
$placeByImportLogResult = null;
return $output;
}
/**
* Returns tag ID by entry in tag translations 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 getTagIDByTransName(MDMysqli $mysqli_noda, string $lang, string $name):int {
if (empty($name)) return 0;
$tagByTLNameResult = $mysqli_noda->query_by_stmt("
SELECT `tag_id`
FROM `tag_translation`
WHERE `trans_name` = ?
AND `trans_language` = ?
LIMIT 2", "ss", $name, $lang);
if ($tagByTlData = $tagByTLNameResult->fetch_row()) {
$output = $tagByTlData[0];
}
else $output = 0;
$tagByTLNameResult->close();
$tagByTLNameResult = null;
return $output;
}
/**
* Returns tag ID by entry in tag noda table.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $noda_source Language to check in.
* @param string $noda_nrinsource Name of the tag to search for.
*
* @return integer
*/
public static function getTagIDByNodaLink(MDMysqli $mysqli_noda, string $noda_source, string $noda_nrinsource):int {
if (empty($noda_nrinsource)) return 0;
$tagByNodaResult = $mysqli_noda->query_by_stmt("
SELECT `tag_id`
FROM `noda_tag`
WHERE `noda_source` = ?
AND `noda_nrinsource` = ?
LIMIT 2", "ss", $noda_source, $noda_nrinsource);
if ($tagByNodaData = $tagByNodaResult->fetch_row()) {
$output = $tagByNodaData[0];
}
else $output = 0;
$tagByNodaResult->close();
$tagByNodaResult = 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 array<integer>
*/
public static function getTagIDByRewrite(MDMysqli $mysqli_noda, string $lang, string $name):array {
if (empty($name)) return [];
$output = [];
$tagRewriteResult = $mysqli_noda->query_by_stmt("
SELECT `tag_id`
FROM `tag_rewriting`
WHERE `tag_language` = ?
AND `input_name` = ?", "ss", $lang, $name);
while ($tagRewriteData = $tagRewriteResult->fetch_row()) {
$output[] = $tagRewriteData[0];
}
$tagRewriteResult->close();
$tagRewriteResult = null;
return $output;
}
/**
* Returns tag ID by entry in tag translations table.
*
* @param MDMysqli $mysqli_noda Database connection.
* @param string $instance Instance in which the import was run.
* @param integer $institution_id ID of the importing institution.
* @param string $name Name of the tag to search for.
*
* @return integer
*/
public static function getTagIDByImportLog(MDMysqli $mysqli_noda, string $instance, int $institution_id, string $name):int {
if (empty($name)) return 0;
$tagByImportLogResult = $mysqli_noda->query_by_stmt("
SELECT `tag_id`
FROM `tag_logged_imports`
WHERE `instance` = ?
AND `institution_id` = ?
AND `input_string` = ?
LIMIT 2", "sis", $instance, $institution_id, $name);
if ($tagByImportLogData = $tagByImportLogResult->fetch_row()) {
$output = $tagByImportLogData[0];
}
else $output = 0;
$tagByImportLogResult->close();
$tagByImportLogResult = null;
return $output;
}
}