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

@ -170,7 +170,7 @@ class Place
return $this; return $this;
} }
public function getCompletionPercentage(): ?int public function getCompletionPercentage(): ?int
{ {
@ -222,15 +222,15 @@ class Place
if (!isset($overpass_data['tags']) || $overpass_data['tags'] == null) { if (!isset($overpass_data['tags']) || $overpass_data['tags'] == null) {
return; return;
} }
$tags = $overpass_data['tags']; $tags = $overpass_data['tags'];
// Setters for basic properties from top-level of overpass data // Setters for basic properties from top-level of overpass data
$this->setOsmId($overpass_data['id']) $this->setOsmId($overpass_data['id'])
->setOsmKind($overpass_data['type']) ->setOsmKind($overpass_data['type'])
->setLat((float) ($overpass_data['lat'] ?? 0)) ->setLat((float) ($overpass_data['lat'] ?? 0))
->setLon((float) ($overpass_data['lon'] ?? 0)); ->setLon((float) ($overpass_data['lon'] ?? 0));
// Setters for metadata // Setters for metadata
if (isset($overpass_data['timestamp'])) { if (isset($overpass_data['timestamp'])) {
try { try {
@ -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']);
@ -251,41 +251,41 @@ class Place
if (isset($overpass_data['changeset'])) { if (isset($overpass_data['changeset'])) {
$this->setOsmChangeset($overpass_data['changeset']); $this->setOsmChangeset($overpass_data['changeset']);
} }
// Guess main tag // Guess main tag
$main_tag = $this->guess_main_tag($tags); $main_tag = $this->guess_main_tag($tags);
if ($main_tag) { if ($main_tag) {
$this->setMainTag($main_tag); $this->setMainTag($main_tag);
} }
// 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']));
$this->setHasWheelchair(!empty($tags['wheelchair'])); $this->setHasWheelchair(!empty($tags['wheelchair']));
// has address logic // has address logic
$this->setHasAddress(!empty($this->getStreet()) && !empty($this->getHousenumber()) $this->setHasAddress(!empty($this->getStreet()) && !empty($this->getHousenumber())
| (isset($tags['addr:street']) && isset($tags['addr:housenumber'])) ); | (isset($tags['addr:street']) && isset($tags['addr:housenumber'])) );
// has website logic (with multiple possible tags) // has website logic (with multiple possible tags)
$websiteTags = ['website', 'contact:website', 'url', 'contact:url']; $websiteTags = ['website', 'contact:website', 'url', 'contact:url'];
$hasWebsite = false; $hasWebsite = false;
@ -297,7 +297,7 @@ class Place
} }
$this->setHasWebsite($hasWebsite); $this->setHasWebsite($hasWebsite);
// has note logic // has note logic
$noteContent = ''; $noteContent = '';
$hasNote = false; $hasNote = false;
@ -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 [