up labourage long noms

This commit is contained in:
Tykayn 2025-07-13 18:11:38 +02:00 committed by tykayn
parent 5b18e4fb08
commit 5c6a28df53

View file

@ -243,7 +243,7 @@ class Place
$this->setOsmVersion($overpass_data['version']); $this->setOsmVersion($overpass_data['version']);
} }
if (isset($overpass_data['user'])) { if (isset($overpass_data['user'])) {
$this->setOsmUser($overpass_data['user']); $this->setOsmUser($this->truncateString($overpass_data['user'], 255));
} }
if (isset($overpass_data['uid'])) { if (isset($overpass_data['uid'])) {
$this->setOsmUid($overpass_data['uid']); $this->setOsmUid($overpass_data['uid']);
@ -259,23 +259,23 @@ class Place
} }
// Setters from tags // 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); $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); $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'])) { if (isset($tags['addr:postcode'])) {
$this->setZipCode(intval($tags['addr:postcode'])); $this->setZipCode(intval($tags['addr:postcode']));
} }
$email = isset($tags['contact:email']) ? $tags['contact:email'] : (isset($tags['email']) ? $tags['email'] : null); $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; $siret = isset($tags['ref:FR:SIRET']) ? $tags['ref:FR:SIRET'] : null;
$this->setSiret($siret); $this->setSiret($this->truncateString($siret, 255));
// Boolean "has" properties // Boolean "has" properties
$this->setHasOpeningHours(!empty($tags['opening_hours'])); $this->setHasOpeningHours(!empty($tags['opening_hours']));
@ -312,7 +312,7 @@ class Place
$noteContent .= "FIXME: " . $tags['fixme']; $noteContent .= "FIXME: " . $tags['fixme'];
$hasNote = true; $hasNote = true;
} }
$this->setNoteContent($noteContent ? $noteContent : null); $this->setNoteContent($this->truncateString($noteContent ? $noteContent : null, 255));
$this->setHasNote($hasNote); $this->setHasNote($hasNote);
$this->setNote($noteContent); $this->setNote($noteContent);
} }
@ -753,6 +753,26 @@ class Place
return $this; 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 public function toArray(): array
{ {
return [ return [