Improve logic for identifying photos in csv-normaliser
This commit is contained in:
@@ -96,19 +96,23 @@ if (($handle = fopen($inputFile, "r")) !== FALSE) {
|
|||||||
|
|
||||||
//print("Adding candidate " . $candidateName . " to ". $currentWard . "\n");
|
//print("Adding candidate " . $candidateName . " to ". $currentWard . "\n");
|
||||||
|
|
||||||
$name_split = explode(" ", str_replace(",", "", str_replace("'", "_", $data[1])));
|
$name_split = array_values(array_filter(explode(" ", str_replace(",", "", str_replace("'", "_", $data[1]))), function($value) { return !is_null($value) && $value !== ''; }));
|
||||||
|
|
||||||
$name_patterns = [
|
$name_patterns = [
|
||||||
implode(".*", $name_split),
|
".*" . implode(".*", $name_split) . ".*",
|
||||||
implode(".*", array_reverse($name_split)),
|
".*" . implode(".*", array_reverse($name_split)) . ".*",
|
||||||
|
"^" . $name_split[array_key_last($name_split)] . ".*",
|
||||||
|
"^" . $name_split[0] . ".*"
|
||||||
];
|
];
|
||||||
|
|
||||||
$regex_groups = array_map(function($x) { return "(?:.*" . $x . ".*)"; }, $name_patterns);
|
$regex_groups = array_map(function($x) { return "(?:" . $x . ")"; }, $name_patterns);
|
||||||
|
|
||||||
$regex_pattern = "/" . implode("|", $regex_groups) . "/i";
|
$regex_pattern = "/" . implode("|", $regex_groups) . "/i";
|
||||||
|
|
||||||
$picture = "";
|
$picture = "";
|
||||||
foreach ($mediaFiles as $mediaFile) {
|
foreach ($mediaFiles as $mediaFile) {
|
||||||
|
if ($mediaFile == ".") continue;
|
||||||
|
if ($mediaFile == "..") continue;
|
||||||
if (preg_match($regex_pattern, $mediaFile)) {
|
if (preg_match($regex_pattern, $mediaFile)) {
|
||||||
$picture = $mediaFile;
|
$picture = $mediaFile;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user