From 5c6a28df53350016b2827a7c91e9b95e7200e3c0 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Sun, 13 Jul 2025 18:11:38 +0200 Subject: [PATCH] up labourage long noms --- src/Entity/Place.php | 60 +++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/src/Entity/Place.php b/src/Entity/Place.php index 86557f0..235f68c 100644 --- a/src/Entity/Place.php +++ b/src/Entity/Place.php @@ -170,7 +170,7 @@ class Place return $this; } - + public function getCompletionPercentage(): ?int { @@ -222,15 +222,15 @@ class Place if (!isset($overpass_data['tags']) || $overpass_data['tags'] == null) { return; } - + $tags = $overpass_data['tags']; - + // Setters for basic properties from top-level of overpass data $this->setOsmId($overpass_data['id']) ->setOsmKind($overpass_data['type']) ->setLat((float) ($overpass_data['lat'] ?? 0)) ->setLon((float) ($overpass_data['lon'] ?? 0)); - + // Setters for metadata if (isset($overpass_data['timestamp'])) { try { @@ -243,7 +243,7 @@ class Place $this->setOsmVersion($overpass_data['version']); } if (isset($overpass_data['user'])) { - $this->setOsmUser($overpass_data['user']); + $this->setOsmUser($this->truncateString($overpass_data['user'], 255)); } if (isset($overpass_data['uid'])) { $this->setOsmUid($overpass_data['uid']); @@ -251,41 +251,41 @@ class Place if (isset($overpass_data['changeset'])) { $this->setOsmChangeset($overpass_data['changeset']); } - + // Guess main tag $main_tag = $this->guess_main_tag($tags); if ($main_tag) { $this->setMainTag($main_tag); } - + // Setters from tags - $this->setName($tags['name'] ?? null); - + $this->setName($this->truncateString($tags['name'] ?? null, 255)); + $street = isset($tags['addr:street']) ? $tags['addr:street'] : (isset($tags['contact:street']) ? $tags['contact:street'] : null); - $this->setStreet($street); + $this->setStreet($this->truncateString($street, 255)); $housenumber = isset($tags['addr:housenumber']) ? $tags['addr:housenumber'] : (isset($tags['contact:housenumber']) ? $tags['contact:housenumber'] : null); - $this->setHousenumber($housenumber); + $this->setHousenumber($this->truncateString($housenumber, 255)); if (isset($tags['addr:postcode'])) { $this->setZipCode(intval($tags['addr:postcode'])); } - + $email = isset($tags['contact:email']) ? $tags['contact:email'] : (isset($tags['email']) ? $tags['email'] : null); - $this->setEmail($email); - + $this->setEmail($this->truncateString($email, 255)); + $siret = isset($tags['ref:FR:SIRET']) ? $tags['ref:FR:SIRET'] : null; - $this->setSiret($siret); - + $this->setSiret($this->truncateString($siret, 255)); + // Boolean "has" properties $this->setHasOpeningHours(!empty($tags['opening_hours'])); $this->setHasWheelchair(!empty($tags['wheelchair'])); - + // has address logic $this->setHasAddress(!empty($this->getStreet()) && !empty($this->getHousenumber()) | (isset($tags['addr:street']) && isset($tags['addr:housenumber'])) ); - + // has website logic (with multiple possible tags) $websiteTags = ['website', 'contact:website', 'url', 'contact:url']; $hasWebsite = false; @@ -297,7 +297,7 @@ class Place } $this->setHasWebsite($hasWebsite); - + // has note logic $noteContent = ''; $hasNote = false; @@ -312,7 +312,7 @@ class Place $noteContent .= "FIXME: " . $tags['fixme']; $hasNote = true; } - $this->setNoteContent($noteContent ? $noteContent : null); + $this->setNoteContent($this->truncateString($noteContent ? $noteContent : null, 255)); $this->setHasNote($hasNote); $this->setNote($noteContent); } @@ -753,6 +753,26 @@ class Place return $this; } + /** + * Helper method to truncate strings to a maximum length + * + * @param string|null $string The string to truncate + * @param int $maxLength The maximum length + * @return string|null The truncated string or null if input was null + */ + private function truncateString(?string $string, int $maxLength): ?string + { + if ($string === null) { + return null; + } + + if (mb_strlen($string) <= $maxLength) { + return $string; + } + + return mb_substr($string, 0, $maxLength); + } + public function toArray(): array { return [