Add search function for getting entries in NodaIDGetter across vocabs
This commit is contained in:
parent
a621534136
commit
9bf14d7d91
@ -999,4 +999,63 @@ final class NodaIDGetter {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks each string in a list of strings for its existence as a tag name.
|
||||||
|
*
|
||||||
|
* @param MDMysqli $mysqli_noda Database connection.
|
||||||
|
* @param string $lang Language to check in.
|
||||||
|
* @param non-empty-array<string> $phrases List of phrases to check.
|
||||||
|
*
|
||||||
|
* @return array{count: int, tag: integer[], actor: integer[], time: integer[], place: integer[]}
|
||||||
|
*/
|
||||||
|
public static function searchEntryNamesByList(MDMysqli $mysqli_noda, string $lang, array $phrases):array {
|
||||||
|
|
||||||
|
$output = [
|
||||||
|
'count' => 0,
|
||||||
|
'tag' => [],
|
||||||
|
'actor' => [],
|
||||||
|
'time' => [],
|
||||||
|
'place' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($phrases as $phrase) {
|
||||||
|
|
||||||
|
if (($tag_id = NodaIDGetter::getTagIDByNamesAndRewrites($mysqli_noda, $lang, $phrase)) !== 0 && !in_array($tag_id, $output['tag'], true)) {
|
||||||
|
$output['tag'][] = $tag_id;
|
||||||
|
++$output['count'];
|
||||||
|
}
|
||||||
|
else if (($place_id = NodaIDGetter::getPlaceIDByNamesAndRewrites($mysqli_noda, $lang, $phrase)) !== 0 && !in_array($place_id, $output['place'], true)) {
|
||||||
|
$output['place'][] = $place_id;
|
||||||
|
++$output['count'];
|
||||||
|
}
|
||||||
|
else if (($persinst_id = NodaIDGetter::getPersinstIDByNamesAndRewrites($mysqli_noda, $lang, $phrase, '', '')) !== 0 && !in_array($persinst_id, $output['actor'], true)) {
|
||||||
|
$output['actor'][] = $persinst_id;
|
||||||
|
++$output['count'];
|
||||||
|
}
|
||||||
|
else if (($time_id = NodaIDGetter::getTimeIDByNamesAndRewrites($mysqli_noda, $lang, $phrase)) !== 0 && !in_array($time_id, $output['time'], true)) {
|
||||||
|
$output['time'][] = $time_id;
|
||||||
|
++$output['count'];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($phrases) !== $output['count']) {
|
||||||
|
return [
|
||||||
|
'count' => 0,
|
||||||
|
'tag' => [],
|
||||||
|
'actor' => [],
|
||||||
|
'time' => [],
|
||||||
|
'place' => [],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($output['tag'])) sort($output['tag']);
|
||||||
|
if (!empty($output['actor'])) sort($output['actor']);
|
||||||
|
if (!empty($output['time'])) sort($output['time']);
|
||||||
|
if (!empty($output['place'])) sort($output['place']);
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user