2020-09-20 22:40:40 +02:00
|
|
|
<?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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-04 22:50:26 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-20 22:40:40 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-01 12:53:27 +02:00
|
|
|
/**
|
|
|
|
* 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 {
|
|
|
|
|
2020-10-05 12:05:48 +02:00
|
|
|
if (empty($noda_nrinsource)) return 0;
|
2020-10-01 12:53:27 +02:00
|
|
|
|
|
|
|
$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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-04 22:50:26 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-26 22:36:02 +02:00
|
|
|
/**
|
|
|
|
* Returns tag ID by entry in tag translations table.
|
|
|
|
*
|
|
|
|
* @param MDMysqli $mysqli_noda Database connection.
|
|
|
|
* @param string $name Name of the tag to search for.
|
|
|
|
*
|
|
|
|
* @return integer
|
|
|
|
*/
|
|
|
|
public static function getTagIDByBaseName(MDMysqli $mysqli_noda, string $name):int {
|
|
|
|
|
|
|
|
if (empty($name)) return 0;
|
|
|
|
|
|
|
|
$tagByBaseNameResult = $mysqli_noda->query_by_stmt("
|
|
|
|
SELECT `tag_id`
|
2021-05-27 00:34:56 +02:00
|
|
|
FROM `tag`
|
2021-05-26 22:36:02 +02:00
|
|
|
WHERE `tag_name` = ?
|
|
|
|
LIMIT 2", "s", $name);
|
|
|
|
|
|
|
|
if ($tagByBaseData = $tagByBaseNameResult->fetch_row()) {
|
|
|
|
$output = $tagByBaseData[0];
|
|
|
|
}
|
|
|
|
else $output = 0;
|
|
|
|
|
|
|
|
$tagByBaseNameResult->close();
|
|
|
|
$tagByBaseNameResult = null;
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-12-07 13:43:07 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-20 22:40:40 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2020-12-20 23:24:08 +01:00
|
|
|
* @return array<integer>
|
2020-09-20 22:40:40 +02:00
|
|
|
*/
|
2020-12-20 23:24:08 +01:00
|
|
|
public static function getTagIDByRewrite(MDMysqli $mysqli_noda, string $lang, string $name):array {
|
2020-09-20 22:40:40 +02:00
|
|
|
|
2020-12-20 23:24:08 +01:00
|
|
|
if (empty($name)) return [];
|
|
|
|
|
|
|
|
$output = [];
|
2020-09-20 22:40:40 +02:00
|
|
|
|
|
|
|
$tagRewriteResult = $mysqli_noda->query_by_stmt("
|
|
|
|
SELECT `tag_id`
|
|
|
|
FROM `tag_rewriting`
|
|
|
|
WHERE `tag_language` = ?
|
2020-12-20 23:24:08 +01:00
|
|
|
AND `input_name` = ?", "ss", $lang, $name);
|
2020-09-20 22:40:40 +02:00
|
|
|
|
2020-12-20 23:24:08 +01:00
|
|
|
while ($tagRewriteData = $tagRewriteResult->fetch_row()) {
|
|
|
|
$output[] = $tagRewriteData[0];
|
2020-09-20 22:40:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$tagRewriteResult->close();
|
|
|
|
$tagRewriteResult = null;
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
|
|
|
|
}
|
2021-01-04 23:06:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
}
|
2020-09-20 22:40:40 +02:00
|
|
|
}
|