Add function for getting actors' names including life dates in batch
This commit is contained in:
parent
c650e57eda
commit
96ba020514
|
@ -143,6 +143,54 @@ final class NodaNameGetter {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Static function for getting persinst names in bulk.
|
||||
*
|
||||
* @param MDMysqli $mysqli_noda DB connection.
|
||||
* @param string $lang Language.
|
||||
* @param array<integer> $persinst_ids Persinst IDs.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getBatchPersinstNamesWithLifeDates(MDMysqli $mysqli_noda, string $lang, array $persinst_ids):array {
|
||||
|
||||
$output = [];
|
||||
|
||||
// Get translations
|
||||
$result = $mysqli_noda->do_read_query("SELECT `persinst`.`persinst_id`, `trans_name`, `persinst_geburtsjahr`, `persinst_sterbejahr`
|
||||
FROM `persinst_translation`, `persinst`
|
||||
WHERE `trans_language` = '" . $mysqli_noda->escape_string($lang) . "'
|
||||
AND `persinst`.`persinst_id` = `persinst_translation`.`persinst_id`
|
||||
AND `persinst`.`persinst_id` IN (" . implode(', ', $persinst_ids) . ")");
|
||||
|
||||
while ($cur = $result->fetch_row()) {
|
||||
$name = (string)$cur[1];
|
||||
if (!empty($cur[2]) || !empty($cur[3])) {
|
||||
$name .= ' (' . $cur[2] . '-' . $cur[3] . ')';
|
||||
}
|
||||
$output[(int)$cur[0]] = $name;
|
||||
}
|
||||
$result->close();
|
||||
|
||||
if (!empty($persinst_ids_left = array_diff($persinst_ids, array_keys($output)))) {
|
||||
$result = $mysqli_noda->do_read_query("SELECT `persinst_id`, `persinst_anzeigename`
|
||||
FROM `persinst`
|
||||
WHERE `persinst_id` IN (" . implode(', ', $persinst_ids_left) . ")");
|
||||
|
||||
while ($cur = $result->fetch_row()) {
|
||||
$output[(int)$cur[0]] = (string)$cur[1];
|
||||
}
|
||||
$result->close();
|
||||
}
|
||||
|
||||
if (count($output) > 1) {
|
||||
asort($output);
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Static function for getting time names in bulk.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user