Merge branch 'location-address-details' into 'develop'

fix: 🐛 explode offer address location in multiple fields

See merge request ldc-web/projets/le-gaulois!232
This commit is contained in:
noah.lancien 2025-06-18 08:40:16 +00:00
commit 8bb1aba44e
6 changed files with 120 additions and 22 deletions

View file

@ -67,7 +67,7 @@ class FetchDigitalRecruiterOffers
*
* @param \Illuminate\Support\Collection $offers
* @return void
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.MaxExceeded
*/
private function saveOffers(Collection $offers): void
{
@ -76,7 +76,11 @@ class FetchDigitalRecruiterOffers
$offers->splice(0, 6)->map(function (object $offer) {
$offerModel = new Offer();
$offerModel->title = $offer->title;
$offerModel->location = $offer->address->formatted ?? null;
$offerModel->location_street = $offer->address->parts->street ?? null;
$offerModel->location_zip = $offer->address->parts->zip ?? null;
$offerModel->location_city = $offer->address->parts->city ?? null;
$offerModel->location_state = $offer->address->parts->state ?? null;
$offerModel->location_country = $offer->address->parts->country ?? null;
$offerModel->location_details = $offer->entity->around
? strip_tags(clean($offer->entity->around))
: null;

View file

@ -14,7 +14,11 @@ use Uwil\SchemaOrg\Laravel\Traits\SchemaOrgTrait;
/**
* @property string|null $title Offer title.
* @property string|null $location Offer location.
* @property string|null $location_street Offer location street.
* @property string|null $location_zip Offer location zip.
* @property string|null $location_city Offer location city.
* @property string|null $location_state Offer location state.
* @property string|null $location_country Offer location country.
* @property string|null $location_details Offer location details.
* @property string|null $location_latitude Offer location latitude.
* @property string|null $location_longitude Offer location longitude.
@ -53,7 +57,11 @@ class Offer extends Model implements SchemaOrgInterface
*/
protected $fillable = [
'title',
'location',
'location_street',
'location_zip',
'location_city',
'location_state',
'location_country',
'location_details',
'location_latitude',
'location_longitude',
@ -154,6 +162,22 @@ class Offer extends Model implements SchemaOrgInterface
});
}
/**
* Get formatted address location.
*
* @return string
*/
public function getFormattedAddressAttribute(): string
{
return trim(sprintf(
'%s %s %s %s',
$this->location_street ?? '',
$this->location_zip ?? '',
$this->location_city ?? '',
$this->location_country ?? ''
));
}
/**
* Create a SchemaOrg.
*
@ -201,9 +225,24 @@ class Offer extends Model implements SchemaOrgInterface
if (!empty($this->location_latitude)) {
$location->latitude($this->location_latitude);
}
if (!empty($this->location)) {
$location->address($this->location);
// Address location.
$fields = [
'streetAddress' => $this->location_street,
'postalCode' => $this->location_zip,
'addressLocality' => $this->location_city,
'addressRegion' => $this->location_state,
'addressCountry' => $this->location_country,
];
$hasAddress = array_filter($fields);
if (!empty($hasAddress)) {
$postalAddress = Schema::postalAddress();
foreach ($hasAddress as $method => $value) {
$postalAddress->$method($value);
}
$location->address($postalAddress);
}
if (!empty($this->location_details)) {
$location->description($this->location_details);
}

View file

@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::table('offers', function (Blueprint $table) {
$table->dropColumn('location');
$table->string('location_street')->nullable()->comment('Offer location street.')->after('title');
$table->string('location_zip')->nullable()->comment('Offer location zip.')->after('location_street');
$table->string('location_city')->nullable()->comment('Offer location city.')->after('location_zip');
$table->string('location_state')->nullable()->comment('Offer location state.')->after('location_city');
$table->string('location_country')->nullable()->comment('Offer location country.')->after('location_state');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::table('offers', function (Blueprint $table) {
$table->dropColumn('location_street');
$table->dropColumn('location_zip');
$table->dropColumn('location_city');
$table->dropColumn('location_state');
$table->dropColumn('location_country');
$table->string('location')->nullable()->comment('Offer location.')->after('title');
});
}
};

View file

@ -17,12 +17,14 @@
@foreach ($offerModels as $offerModel)
<tr class="border-bottom">
<td class="text-center align-middle">{{ $offerModel->title }}</td>
<td class="text-center align-middle">{{ $offerModel->location }}</td>
<td class="text-center align-middle">
{{ $offerModel->getFormattedAddressAttribute() }}
</td>
<td class="text-center align-middle">{{ $offerModel->contract }}</td>
<td class="text-center align-middle">{{ $offerModel->function }}</td>
<td class="text-center align-middle">
<img class="image-preview" src="{{ asset($offerModel->picture) }}" title="{{ $offerModel->picture_title }}"
alt="{{ $offerModel->picture_alt }}">
<img class="image-preview" src="{{ asset($offerModel->picture) }}"
title="{{ $offerModel->picture_title }}" alt="{{ $offerModel->picture_alt }}">
</td>
@include('bo.modules.change-published-status', [
'routeName' => 'offers',

View file

@ -48,37 +48,43 @@
<table class="table-hover m-0 table">
<tbody>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.title'))->ucFirst() }}</td>
<td class="w-50 fw-bold text-center align-middle">
{{ str(__('validation.attributes.title'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ $offerModel->title }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.location'))->ucFirst() }}</td>
<td class="w-50 fw-bold text-center align-middle">
{{ str(__('validation.custom.location'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ $offerModel->location }}
{{ $offerModel->getFormattedAddressAttribute() }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.contract'))->ucFirst() }}</td>
<td class="w-50 fw-bold text-center align-middle">
{{ str(__('validation.custom.contract'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ $offerModel->contract }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.custom.function'))->ucFirst() }}</td>
<td class="w-50 fw-bold text-center align-middle">
{{ str(__('validation.custom.function'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ $offerModel->function }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.description'))->ucFirst() }}</td>
<td class="w-50 fw-bold text-center align-middle">
{{ str(__('validation.attributes.description'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ $offerModel->description }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.image'))->ucFirst() }}</td>
<td class="w-50 fw-bold text-center align-middle">
{{ str(__('validation.attributes.image'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
<img class="img-fluid" src="{{ asset($offerModel->picture) }}"
title="{{ $offerModel->picture_title }}" alt="{{ $offerModel->picture_alt }}">
@ -86,20 +92,22 @@
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">
{{ str(sprintf("%s du bouton", __('validation.custom.publication')))->ucFirst() }}
{{ str(sprintf('%s du bouton', __('validation.custom.publication')))->ucFirst() }}
</td>
<td class="w-50 text-center align-middle">
{{ $offerModel->published ? __('Oui') : __('Non') }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.created_at'))->ucFirst() }}</td>
<td class="w-50 fw-bold text-center align-middle">
{{ str(__('validation.attributes.created_at'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ str($offerModel->created_at->isoFormat('LLLL'))->ucFirst() }}
</td>
</tr>
<tr class="border-bottom">
<td class="w-50 fw-bold text-center align-middle">{{ str(__('validation.attributes.updated_at'))->ucFirst() }}</td>
<td class="w-50 fw-bold text-center align-middle">
{{ str(__('validation.attributes.updated_at'))->ucFirst() }}</td>
<td class="w-50 text-center align-middle">
{{ str($offerModel->updated_at->isoFormat('LLLL'))->ucFirst() }}
</td>

View file

@ -23,9 +23,12 @@
<div class="bg-quad text-uppercase f-bourton-base fs-5 me-3 mt-2 px-2 py-1 text-white">
{{ $offerModel->contract }}
</div>
<div class="bg-secondary text-uppercase f-bourton-base fs-5 me-3 mt-2 px-2 py-1 text-white">
{{ $offerModel->location }}
</div>
@php $locationAddress = $offerModel->getFormattedAddressAttribute(); @endphp
@if (strlen($locationAddress))
<div class="bg-secondary text-uppercase f-bourton-base fs-5 me-3 mt-2 px-2 py-1 text-white">
{{ $locationAddress }}
</div>
@endif
<div class="bg-tertiary text-uppercase f-bourton-base fs-5 me-3 mt-2 px-2 py-1">
{{ $offerModel->function }}
</div>