Skip to content

Commit c0699d2

Browse files
committed
Affichage liste régions page pays
1 parent 30290f2 commit c0699d2

File tree

9 files changed

+142
-37
lines changed

9 files changed

+142
-37
lines changed

app/Models/Pays.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public function subdivisions(): HasManyThrough
432432
SubdivisionType::class,
433433
'pays_id',
434434
'subdivision_type_id',
435-
'id',
435+
'ch_pay_id',
436436
'id',
437437
);
438438
}

app/Models/Subdivision.php

+11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
use Carbon\Carbon;
88
use Illuminate\Database\Eloquent\Builder;
9+
use Illuminate\Database\Eloquent\Collection;
910
use Illuminate\Database\Eloquent\Model;
1011
use Illuminate\Database\Eloquent\Relations\BelongsTo;
12+
use Illuminate\Database\Eloquent\Relations\HasMany;
1113
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
1214
use Illuminate\Database\Eloquent\SoftDeletes;
1315
use Roxayl\MondeGC\Models\Presenters\SubdivisionPresenter;
@@ -26,6 +28,7 @@
2628
* @property SubdivisionType|null $subdivision_type
2729
* @property-read SubdivisionType|null $subdivisionType
2830
* @property-read Pays|null $pays
31+
* @property-read Collection|Ville[] $villes
2932
*
3033
* @method static Builder|Subdivision newModelQuery()
3134
* @method static Builder|Subdivision newQuery()
@@ -84,4 +87,12 @@ public function pays(): HasOneThrough
8487
'pays_id',
8588
);
8689
}
90+
91+
/**
92+
* @return HasMany
93+
*/
94+
public function villes(): HasMany
95+
{
96+
return $this->hasMany(Ville::class, 'subdivision_id');
97+
}
8798
}

app/Models/Ville.php

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
* @property-read Pays|null $pays
6666
* @property-read Eloquent\Collection|ChapterResourceable[] $chapterResources
6767
* @property-read int|null $chapter_resources_count
68+
* @property-read CustomUser|null $mayor
6869
* @property-read Eloquent\Collection|Infrastructure[] $infrastructures
6970
* @property-read int|null $infrastructures_count
7071
* @property-read Eloquent\Collection|Infrastructure[] $infrastructuresAll
@@ -233,6 +234,14 @@ public function subdivision(): BelongsTo
233234
return $this->belongsTo(Subdivision::class, 'subdivision_id');
234235
}
235236

237+
/**
238+
* @return BelongsTo
239+
*/
240+
public function mayor(): BelongsTo
241+
{
242+
return $this->belongsTo(CustomUser::class, 'ch_vil_user');
243+
}
244+
236245
/**
237246
* @return Collection<int, CustomUser>
238247
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Roxayl\MondeGC\View\Components\Pays;
6+
7+
use Illuminate\Contracts\View\View;
8+
use Illuminate\Support\Collection;
9+
use Roxayl\MondeGC\Models\Pays;
10+
use Roxayl\MondeGC\Models\Ville;
11+
use Roxayl\MondeGC\View\Components\BaseComponent;
12+
use YlsIdeas\FeatureFlags\Facades\Features;
13+
14+
class VilleFrontSection extends BaseComponent
15+
{
16+
public function __construct(public Pays $pays)
17+
{
18+
}
19+
20+
/**
21+
* @return Collection<int, Ville>
22+
*/
23+
public function villesWithoutSubdivisions(): Collection
24+
{
25+
if ($this->usesSubdivisions()) {
26+
return $this->pays->villes()->whereNull('subdivision_id')->get();
27+
}
28+
return $this->pays->villes;
29+
}
30+
31+
/**
32+
* @inheritDoc
33+
*/
34+
public function render(): View
35+
{
36+
if ($this->usesSubdivisions()) {
37+
return view('pays.components.ville-subdivision-list');
38+
}
39+
return view('pays.components.ville-list');
40+
}
41+
42+
private function usesSubdivisions(): bool
43+
{
44+
return Features::accessible('subdivision') && $this->pays->use_subdivisions;
45+
}
46+
}

config/features.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
'roleplay' => true,
2626
'roleplay-only-restricted' => false,
2727
'cache' => true,
28-
'subdivision' => false,
28+
'subdivision' => true,
2929
],
3030

3131
/*

legacy/page-pays.php

+6-35
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
use Illuminate\Support\Facades\Gate;
4-
use YlsIdeas\FeatureFlags\Facades\Features;
4+
use Roxayl\MondeGC\Services\StringBladeService;
55

66
//Connexion et deconnexion
77
include('php/log.php');
@@ -508,41 +508,12 @@ class="img-menu-drapeau">
508508
<!-- Liste des villes
509509
================================================== -->
510510
<?php if ($row_villes) { ?>
511-
<section>
512-
<div id="villes" class="titre-vert anchor">
513-
<?php if(Features::accessible('subdivision') && $eloquentPays->use_subdivisions): ?>
514-
<h1>Subdivisions et villes</h1>
515-
<?php else: ?>
516-
<h1>Villes</h1>
517-
<?php endif; ?>
518-
</div>
519-
<div id="liste-villes">
520-
<ul class="listes listes-two-columns">
521-
<?php do { ?>
522-
<li class="row-fluid">
523-
<div class="span5 img-listes"> <a href="page-ville.php?ch_pay_id=<?= e($row_Pays['ch_pay_id']) ?>&ch_ville_id=<?= e($row_villes['ch_vil_ID']) ?>">
524-
<?php if ($row_villes['ch_vil_lien_img1']) {?>
525-
<img src="<?php echo $row_villes['ch_vil_lien_img1']; ?>" alt="<?= e($row_villes['ch_vil_nom']) ?>">
526-
<?php } else { ?>
527-
<img src="assets/img/imagesdefaut/ville.jpg" alt="ville">
528-
<?php } ?>
529-
</a> </div>
530-
<div class="span6 info-listes" style="text-justify: none;">
531-
<h4 class="mb-2"><?= e($row_villes['ch_vil_nom']) ?></h4>
532-
<p><strong>Population&nbsp;: </strong>
533-
<?= number_format($row_villes['ch_vil_population'], 0, ',', ' ') ?>
534-
</p>
535-
<?php if(! empty($row_villes['ch_vil_specialite'])): ?>
536-
<p><strong>Sp&eacute;cialit&eacute;&nbsp;: </strong> <?= e($row_villes['ch_vil_specialite']) ?></p>
537-
<?php endif; ?>
538-
<p>Ville créée par <strong><?= e($row_villes['ch_use_login']) ?></strong></p>
539-
<a href="page-ville.php?ch_pay_id=<?= e($row_Pays['ch_pay_id']) ?>&ch_ville_id=<?= e($row_villes['ch_vil_ID']) ?>" class="btn btn-primary">Visiter</a> </div>
540-
</li>
541-
<?php } while ($row_villes = mysql_fetch_assoc($villes)); ?>
542-
</ul>
543-
</div>
544-
</section>
511+
<?php echo app(StringBladeService::class)->render(
512+
'<x-pays.ville-front-section :pays="$pays" />',
513+
['pays' => $eloquentPays]
514+
) ?>
545515
<?php } ?>
516+
546517
<!-- Géographie - Carte INTERACTIVE
547518
================================================== -->
548519

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<section>
2+
<div id="villes" class="titre-vert anchor">
3+
<h1>Villes</h1>
4+
</div>
5+
6+
<ul class="listes listes-two-columns">
7+
@foreach($pays->villes as $ville)
8+
@include('pays.components.ville-two-columns')
9+
@endforeach
10+
</ul>
11+
</section>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<section>
2+
<div id="villes" class="titre-vert anchor">
3+
<h1>Subdivisions et villes</h1>
4+
</div>
5+
6+
@foreach($pays->subdivisions as $subdivision)
7+
<h4 class="ml-2">
8+
@if($subdivision->subdivisionType)
9+
{{ $subdivision->subdivisionType->type_name }} :
10+
@endif
11+
{{ $subdivision->name }}</h4>
12+
<div class="ml-2">
13+
<a href="{{ route('subdivision.show', $subdivision->showRouteParameter()) }}" class="btn btn-primary">
14+
Visiter
15+
</a>
16+
</div>
17+
@if($subdivision->villes?->isNotEmpty())
18+
<ul class="listes listes-two-columns">
19+
@foreach($subdivision->villes as $ville)
20+
@include('pays.components.ville-two-columns')
21+
@endforeach
22+
</ul>
23+
@endif
24+
@endforeach
25+
26+
@if(($otherVilles = $villesWithoutSubdivisions())->isNotEmpty())
27+
@if(! empty($pays->subdivisions))
28+
<h4 class="ml-2">Autres villes</h4>
29+
@endif
30+
<ul class="listes listes-two-columns">
31+
@foreach($villesWithoutSubdivisions as $ville)
32+
@include('pays.components.ville-two-columns')
33+
@endforeach
34+
</ul>
35+
@endif
36+
</section>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<li class="row-fluid">
2+
<div class="span5 img-listes">
3+
<a href="{{ url('page-ville.php?ch_ville_id=' . $ville->getKey()) }}">
4+
@if($ville->ch_vil_lien_img1)
5+
<img src="{{ $ville->ch_vil_lien_img1 }}" alt="{{ $ville->ch_vil_nom }}">
6+
@else
7+
<img src="assets/img/imagesdefaut/ville.jpg" alt="ville">
8+
@endif
9+
</a>
10+
</div>
11+
<div class="span6 info-listes" style="text-justify: none;">
12+
<h4 class="mb-2">{{ $ville->ch_vil_nom }}</h4>
13+
<p><strong>Population : </strong>{{ number_format($ville->ch_vil_population, 0, ',', '') }}
14+
</p>
15+
@if(! empty($ville->ch_vil_specialite))
16+
<p><strong>Spécialité : </strong> {{ $ville->ch_vil_specialite }}</p>
17+
@endif
18+
<p>Ville créée par <strong>{{ $ville->mayor->ch_use_login }}</strong></p>
19+
<a href="{{ url('page-ville.php?ch_ville_id=' . $ville->getKey()) }}" class="btn btn-primary">Visiter</a>
20+
</div>
21+
</li>

0 commit comments

Comments
 (0)