58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use App\Enums\DepartaimantCurrent;
|
|
use App\Enums\GMapDataType;
|
|
use App\Enums\OCBType;
|
|
use BadMethodCallException;
|
|
use Exception;
|
|
|
|
trait GoogleMapSerialize
|
|
{
|
|
public function googleMapSerialize()
|
|
{
|
|
$type = $this->title ? GMapDataType::portrait() : GMapDataType::ocbbreeder();
|
|
$departaimant = false;
|
|
// try to get the departement
|
|
try {
|
|
$departaimant = DepartaimantCurrent::make(substr($this->postal_code, 0, 2))
|
|
->label;
|
|
} catch (BadMethodCallException $e) {
|
|
$departaimant = false;
|
|
}
|
|
$ocbType = '';
|
|
if ($this->ocbType) {
|
|
switch ($this->ocbType->value) {
|
|
case OCBType::poultry()->value:
|
|
$ocbType = trans('Éleveur de volaille');
|
|
break;
|
|
case OCBType::rabbit()->value:
|
|
$ocbType = trans('Éleveur de lapins');
|
|
break;
|
|
default:
|
|
throw new Exception(sprintf(
|
|
'Unhandled OCB type %s',
|
|
$this->ocbType->value
|
|
));
|
|
}
|
|
}
|
|
return [
|
|
'id' => $this->id,
|
|
'slug' => $this->slug,
|
|
'type' => $type,
|
|
'firstname' => $this->first_name,
|
|
'postal' => $this->postal,
|
|
'departaimant' => $departaimant,
|
|
'title' => $this->title,
|
|
'subtitle' => $this->subtitle,
|
|
'testimony' => $this->testimony,
|
|
'latitude' => $this->latitude,
|
|
'longitude' => $this->longitude,
|
|
'picture' => $this->picture,
|
|
'place' => $this->place,
|
|
'ocbType' => $ocbType,
|
|
'status' => $this->status
|
|
];
|
|
}
|
|
}
|