116 lines
3.8 KiB
PHP
116 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\View\Components\Front\News;
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\View\Component;
|
|
use App\Enums\News\NewsCategoryEnum;
|
|
use App\Enums\News\NewsYearsEnum;
|
|
use App\Helpers\BladeComponentHelper;
|
|
use App\Models\News;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Illuminate\Support\Str;
|
|
|
|
class IndexNewsComponent extends Component
|
|
{
|
|
public $categories;
|
|
public $years;
|
|
public $newsModels;
|
|
public $postContainer;
|
|
|
|
/**
|
|
* Create a new component instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
// Rajouter ici un filtre pour ne récupérer que le status published
|
|
$bladeHelper = new BladeComponentHelper();
|
|
$this->categories = collect(NewsCategoryEnum::toArray())
|
|
->map(fn($category) => NewsCategoryEnum::make((int) $category->value))
|
|
->filter(fn($categoryLocal) => $categoryLocal->categoriesWithLocal())
|
|
->map(fn($categoryLocal) => [
|
|
'title' => trans($categoryLocal->label()),
|
|
'tag' => Str::slug($categoryLocal->value),
|
|
'category' => 'news',
|
|
])
|
|
->values()
|
|
->toArray();
|
|
|
|
$this->years = collect(NewsYearsEnum::toArray())
|
|
->map(fn($year) => NewsYearsEnum::make((int) $year->value))
|
|
->filter(fn($yearLocal) => $yearLocal->yearsWithLocal())
|
|
->map(fn($yearLocal) => [
|
|
'title' => trans($yearLocal->label()),
|
|
'tag' => Str::slug($yearLocal->value),
|
|
'category' => 'news',
|
|
])
|
|
->values()
|
|
->toArray();
|
|
|
|
/** @var \Illuminate\Database\Eloquent\Builder<\App\Models\News> $query */
|
|
$query = News::query()->with('categories');
|
|
|
|
/** Sort columns with a query */
|
|
$bladeHelper->runSortQuery($query);
|
|
|
|
/** Custom pagination */
|
|
$this->newsModels = $bladeHelper->runPaginate($query);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Cette section est à revoir mais c'est pour coller et être iso au site actuellement en prod
|
|
*/
|
|
$currentRoute = Route::currentRouteName();
|
|
// Common values
|
|
$this->postContainer = [
|
|
'secondaryClass' => 'fw-container no-bottom-padding',
|
|
'tertiaryClass' => 'tagged-posts',
|
|
'list_type' => 'news',
|
|
'id' => 'news',
|
|
'post_id' => '9', // FIXME: probablement plus utile
|
|
'slug' => 'news',
|
|
'url' => route('front.news.index'),
|
|
'localized' => 'ajax_load_more_news_vars', // FIXME: probablement pas utile
|
|
'object' => 'ajax_load_more_news', // FIXME: probablement pas utile
|
|
];
|
|
|
|
|
|
switch ($currentRoute) {
|
|
case 'front.news.index':
|
|
$this->postContainer['load_more'] = ucfirst(__('front.buttons.see_more_news'));
|
|
break;
|
|
|
|
case 'front.espace-presse':
|
|
$this->postContainer = array_merge($this->postContainer, [
|
|
'class' => 'fw-container no-top-padding',
|
|
'load_more' => ucfirst(__('front.buttons.see_more_docs')),
|
|
'type_button' => true
|
|
]);
|
|
break;
|
|
|
|
default:
|
|
$this->postContainer['load_more'] = __('front.buttons.load_more');
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the view / contents that represent the component.
|
|
*
|
|
* @return View|Closure|string
|
|
*/
|
|
public function render(): View|Closure|string
|
|
{
|
|
return view('components.front.news.index-news-component', [
|
|
'categories' => $this->categories,
|
|
'years' => $this->years,
|
|
'newsModels' => $this->newsModels,
|
|
'postContainer' => $this->postContainer
|
|
]);
|
|
}
|
|
}
|