From fff24136a1bc511f1924a591540543d983045354 Mon Sep 17 00:00:00 2001 From: Matt Way Date: Mon, 23 Sep 2024 23:06:18 +1000 Subject: [PATCH] Improve logic for identifying photos in csv-normaliser --- csv-normaliser/main.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/csv-normaliser/main.php b/csv-normaliser/main.php index df4e991..a3e39d7 100644 --- a/csv-normaliser/main.php +++ b/csv-normaliser/main.php @@ -96,19 +96,23 @@ if (($handle = fopen($inputFile, "r")) !== FALSE) { //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 = [ - implode(".*", $name_split), - implode(".*", array_reverse($name_split)), + ".*" . implode(".*", $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"; $picture = ""; foreach ($mediaFiles as $mediaFile) { + if ($mediaFile == ".") continue; + if ($mediaFile == "..") continue; if (preg_match($regex_pattern, $mediaFile)) { $picture = $mediaFile; break;