From 9f67d253da67464192424b7fef4307a69f5bcb56 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Mon, 4 Jan 2021 22:50:26 +0100 Subject: [PATCH] Add functions to get actor and place IDs by import logs --- src/NodaIDGetter.php | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/NodaIDGetter.php b/src/NodaIDGetter.php index 125aeb4..3651033 100644 --- a/src/NodaIDGetter.php +++ b/src/NodaIDGetter.php @@ -74,6 +74,43 @@ final class NodaIDGetter { } + /** + * 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. * @@ -170,6 +207,40 @@ final class NodaIDGetter { } + /** + * 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. *