Merge branch 'phpstan-errors' into 'develop'

fix: 🚨 resolve last phpstan errors

See merge request ldc-web/projets/ldc!132
This commit is contained in:
karl.muller 2026-02-13 15:35:55 +00:00
commit 5324ed68b4
51 changed files with 410 additions and 315 deletions

View file

@ -13,12 +13,12 @@ class LocalDateTime implements CastsAttributes
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param string|integer|null $value
* @param mixed $value
* @param array $attributes
* @return \Carbon\Carbon|null
* @phpcs:disable
*/
public function get(Model $model, string $key, string|int|null $value, array $attributes): ?\Carbon\Carbon
public function get(Model $model, string $key, mixed $value, array $attributes): ?\Carbon\Carbon
{
// phpcs:enable
return $value
@ -31,12 +31,12 @@ class LocalDateTime implements CastsAttributes
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param string|integer|null $value
* @param mixed $value
* @param array $attributes
* @return \Carbon\Carbon|null
* @phpcs:disable
*/
public function set(Model $model, string $key, string|int|null $value, array $attributes): ?\Carbon\Carbon
public function set(Model $model, string $key, mixed $value, array $attributes): ?\Carbon\Carbon
{
// phpcs:enable
return $value

View file

@ -41,8 +41,6 @@ enum ContactFormType: int
/**
* Optionnal SUBTYPES definition.
*
* @phpstan-ignore-next-line
*/
private const SUBTYPES = [
self::professional->name => [
@ -61,9 +59,9 @@ enum ContactFormType: int
];
/**
* Get Class
* Get sub type status.
*
* @return string|null
* @return boolean
*/
public function isSubtype(): bool
{
@ -77,8 +75,6 @@ enum ContactFormType: int
/**
* Optionnal TOPLEVELS definition.
*
* @phpstan-ignore-next-line
*/
private const TOPLEVELS = [
self::professional->name => true,
@ -94,43 +90,44 @@ enum ContactFormType: int
];
/**
* Get Class
* Get top level status.
*
* @return string|null
* @return boolean
*/
public function topLevel(): ?string
public function topLevel(): bool
{
return !empty(self::TOPLEVELS[$this->name]) ?
self::TOPLEVELS[$this->name] : false;
}
/**
* Get the data-target
* Get the data-target.
*
* @return string
* @return string|null
*/
public function dataTarget(): string
public function dataTarget(): ?string
{
return match ($this) {
self::professional => 'askPro',
default => null,
};
}
/**
* Get the subtitle
* Get the subtitle.
*
* @return string
*/
public function subtitle(): string
{
return match (true) {
$this === self::restauration => __('enums.contactFormType.' . $this->name . '.subtitle'),
return match ($this) {
self::restauration => __('enums.contactFormType.' . $this->name . '.subtitle'),
default => __('enums.contactFormType.' . $this->name . '.label'),
};
}
/**
* Get the slug for each type
* Get the slug for each type.
*
* @param string|null $locale
* @return string|null
@ -154,7 +151,7 @@ enum ContactFormType: int
}
/**
* Check if current lang slug match in specific lang slug
* Check if current lang slug match in specific lang slug.
*
* @param string $slug
* @param string $locale
@ -176,13 +173,13 @@ enum ContactFormType: int
}
/**
* Get the route
* Get the route.
*
* @return string|null
*/
public function route(): ?string
{
$commonRoutes = [
return match ($this) {
self::collaborator,
self::breeder,
self::export,
@ -190,19 +187,15 @@ enum ContactFormType: int
self::commitments,
self::product,
self::info,
self::restauration
];
return match (true) {
in_array($this, $commonRoutes, true) => route('front.contact.show', ['slug' => $this->slug()]),
$this === self::professional => null,
$this === self::press =>
RouteHelper::routeNameChecker('front.dynamic-pages.espace-presse') . '#page-press-form',
default => null,
self::restauration => route('front.contact.show', ['slug' => $this->slug()]),
self::professional => null,
self::press => RouteHelper::routeNameChecker('front.dynamic-pages.espace-presse')
. '#page-press-form',
};
}
/**
* Get the route for the contact form type
* Get the route for the contact form type.
*
* @return array
*/
@ -217,7 +210,7 @@ enum ContactFormType: int
}
/**
* Get the slug for each type
* Get the slug for each type.
*
* @return array
*/
@ -245,7 +238,7 @@ enum ContactFormType: int
}
/**
* Get the slug for each type
* Get the slug for each type.
*
* @return array
* @phpcs:disable Generic.Metrics.CyclomaticComplexity

View file

@ -95,6 +95,7 @@ enum DynamicFieldTypes: int
* Is array definition.
*
* @return array
* @phpstan-ignore-next-line
*/
private const ISARRAY = [
self::string->name => false,

View file

@ -21,18 +21,18 @@ enum OrdersEnum: int
self::desc->name => 'enums.orders.desc',
];
/**
* Get the orders to display using the app locale
* Get the orders to display using the app locale.
*
* @return boolean
*/
public function ordersWithLocal(): bool
{
$locale = config('app.locale');
return match (true) {
$this === self::asc => true,
$this === self::desc => true,
return match ($this) {
self::asc,
/** @phpstan-ignore-next-line */
self::desc => true,
default => $locale === "fr" ? true : false,
};
}

View file

@ -6,9 +6,9 @@ use App\Enums\DynamicFieldTypes;
use App\Enums\DynamicPages\PageStatusEnum;
use App\Models\DynamicPage;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Uwil\LaravelCommon\Helpers\FileHelper;
use Uwil\LaravelCommon\Helpers\ToolboxHelper;
@ -181,9 +181,9 @@ class DynamicPageHelper
/**
* Get all segments url for dynamic pages.
*
* @param \App\Models\DynamicPage $page
* @param \Illuminate\Support\Collection $pages
* @param string $locale
* @param \App\Models\DynamicPage $page
* @param \Illuminate\Database\Eloquent\Collection $pages
* @param string $locale
* @return array|null
*/
public static function getAllDynamicPageSegments(DynamicPage $page, Collection $pages, string $locale): ?array

View file

@ -88,9 +88,9 @@ class RouteHelper extends Controller
*
* @param \Illuminate\Routing\Route $route
* @param string $localeCode
* @return string|false|null
* @return string|null
*/
private static function getContactShowLocalizedUrl(Route $route, string $localeCode)
private static function getContactShowLocalizedUrl(Route $route, string $localeCode): ?string
{
$contactPage = $route->parameter('contactPage');
@ -123,6 +123,8 @@ class RouteHelper extends Controller
}
return $localizedUrl;
} //end if
return null;
}
/**
@ -137,10 +139,10 @@ class RouteHelper extends Controller
/** @var \App\Models\DynamicPage|null $dynamicPage */
$dynamicPage = $route->parameter('dynamicPage');
if ($dynamicPage instanceof DynamicPage) {
$path = $dynamicPage->getLocalizedPath($localeCode);
if ($path) {
return LaravelLocalization::getLocalizedURL($localeCode, "/{$path}", [], false);
}
$path = $dynamicPage->getLocalizedPath($localeCode);
$defPath = $path ?? "";
return LaravelLocalization::getLocalizedURL($localeCode, "/{$defPath}", [], false);
}
return null;
}
}

View file

@ -2,8 +2,8 @@
namespace App\Http\Controllers\Back;
use App\Http\Requests\Back\DocumentCategory\StoreDocumentCategoryRequest;
use App\Http\Requests\Back\DocumentCategory\UpdateDocumentCategoryRequest;
use App\Http\Requests\Back\DocumentCategories\StoreDocumentCategoryRequest;
use App\Http\Requests\Back\DocumentCategories\UpdateDocumentCategoryRequest;
use App\Models\DocumentCategory;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@ -99,7 +99,7 @@ class DocumentCategoryController extends Controller
/**
* Store a newly created resource.
*
* @param \App\Http\Requests\Back\News\StoreDocumentCategoryRequest $request
* @param \App\Http\Requests\Back\DocumentCategories\StoreDocumentCategoryRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(StoreDocumentCategoryRequest $request): \Illuminate\Http\RedirectResponse
@ -131,8 +131,8 @@ class DocumentCategoryController extends Controller
/**
* Update the specified resource.
*
* @param \App\Http\Requests\Back\News\UpdateDocumentCategoryRequest $request
* @param \App\Models\DocumentCategory $document_category
* @param \App\Http\Requests\Back\DocumentCategories\UpdateDocumentCategoryRequest $request
* @param \App\Models\DocumentCategory $document_category
* @return \Illuminate\Http\RedirectResponse
*/
public function update(

View file

@ -5,8 +5,8 @@ namespace App\Http\Controllers\Back;
use App\Enums\Document\DocumentStatusEnum;
use App\Enums\YearsEnum;
use App\Helpers\DocumentHelper;
use App\Http\Requests\Back\Document\StoreDocumentRequest;
use App\Http\Requests\Back\Document\UpdateDocumentRequest;
use App\Http\Requests\Back\Documents\StoreDocumentRequest;
use App\Http\Requests\Back\Documents\UpdateDocumentRequest;
use App\Models\Document;
use App\Models\DocumentCategory;
use App\Models\DocumentTag;
@ -108,7 +108,7 @@ class DocumentController extends Controller
/**
* Store a newly created resource.
*
* @param \App\Http\Requests\Back\Document\StoreDocumentRequest $request
* @param \App\Http\Requests\Back\Documents\StoreDocumentRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(StoreDocumentRequest $request): \Illuminate\Http\RedirectResponse
@ -144,8 +144,8 @@ class DocumentController extends Controller
/**
* Update the specified resource.
*
* @param \App\Http\Requests\Back\Document\UpdateDocumentRequest $request
* @param \App\Models\Document $document
* @param \App\Http\Requests\Back\Documents\UpdateDocumentRequest $request
* @param \App\Models\Document $document
* @return \Illuminate\Http\RedirectResponse
*/
public function update(UpdateDocumentRequest $request, Document $document): \Illuminate\Http\RedirectResponse

View file

@ -2,8 +2,8 @@
namespace App\Http\Controllers\Back;
use App\Http\Requests\Back\DocumentTag\StoreDocumentTagRequest;
use App\Http\Requests\Back\DocumentTag\UpdateDocumentTagRequest;
use App\Http\Requests\Back\DocumentTags\StoreDocumentTagRequest;
use App\Http\Requests\Back\DocumentTags\UpdateDocumentTagRequest;
use App\Models\DocumentTag;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@ -99,7 +99,7 @@ class DocumentTagController extends Controller
/**
* Store a newly created resource.
*
* @param \App\Http\Requests\Back\News\StoreDocumentTagRequest $request
* @param \App\Http\Requests\Back\DocumentTags\StoreDocumentTagRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(StoreDocumentTagRequest $request): \Illuminate\Http\RedirectResponse
@ -131,8 +131,8 @@ class DocumentTagController extends Controller
/**
* Update the specified resource.
*
* @param \App\Http\Requests\Back\News\UpdateDocumentTagRequest $request
* @param \App\Models\DocumentTag $document_tag
* @param \App\Http\Requests\Back\DocumentTags\UpdateDocumentTagRequest $request
* @param \App\Models\DocumentTag $document_tag
* @return \Illuminate\Http\RedirectResponse
*/
public function update(

View file

@ -119,7 +119,7 @@ class InputsController extends Controller
$url = (method_exists($modelClass, 'getAccessModel'))
? $modelClass::getAccessModel($validated['selectedEntry'])
: static::getAccessModel($validated['selectedEntry'], $validated['modelName']);
: self::getAccessModel($validated['selectedEntry'], $validated['modelName']);
$token = Crypt::encryptString(json_encode([
'modelName' => $validated['modelName'],

View file

@ -3,8 +3,8 @@
namespace App\Http\Controllers\Back;
use App\Enums\News\NewsStatusEnum;
use App\Http\Requests\Back\NewsCategory\StoreNewsCategoryRequest;
use App\Http\Requests\Back\NewsCategory\UpdateNewsCategoryRequest;
use App\Http\Requests\Back\NewsCategories\StoreNewsCategoryRequest;
use App\Http\Requests\Back\NewsCategories\UpdateNewsCategoryRequest;
use App\Models\NewsCategory;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@ -102,7 +102,7 @@ class NewsCategoryController extends Controller
/**
* Store a newly created resource.
*
* @param \App\Http\Requests\Back\NewsCategory\StoreNewsCategoryRequest $request
* @param \App\Http\Requests\Back\NewsCategories\StoreNewsCategoryRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(StoreNewsCategoryRequest $request): \Illuminate\Http\RedirectResponse
@ -134,8 +134,8 @@ class NewsCategoryController extends Controller
/**
* Update the specified resource.
*
* @param \App\Http\Requests\Back\News\UpdateNewsCategoryRequest $request
* @param \App\Models\NewsCategory $news_category
* @param \App\Http\Requests\Back\NewsCategories\UpdateNewsCategoryRequest $request
* @param \App\Models\NewsCategory $news_category
* @return \Illuminate\Http\RedirectResponse
*/
public function update(

View file

@ -3,8 +3,8 @@
namespace App\Http\Controllers\Back;
use App\Enums\News\NewsStatusEnum;
use App\Http\Requests\Back\NewsTag\StoreNewsTagRequest;
use App\Http\Requests\Back\NewsTag\UpdateNewsTagRequest;
use App\Http\Requests\Back\NewsTags\StoreNewsTagRequest;
use App\Http\Requests\Back\NewsTags\UpdateNewsTagRequest;
use App\Models\NewsTag;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@ -102,7 +102,7 @@ class NewsTagController extends Controller
/**
* Store a newly created resource.
*
* @param \App\Http\Requests\Back\NewsTag\StoreNewsTagRequest $request
* @param \App\Http\Requests\Back\NewsTags\StoreNewsTagRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(StoreNewsTagRequest $request): \Illuminate\Http\RedirectResponse
@ -134,8 +134,8 @@ class NewsTagController extends Controller
/**
* Update the specified resource.
*
* @param \App\Http\Requests\Back\News\UpdateNewsTagRequest $request
* @param \App\Models\NewsTag $news_tag
* @param \App\Http\Requests\Back\NewsTags\UpdateNewsTagRequest $request
* @param \App\Models\NewsTag $news_tag
* @return \Illuminate\Http\RedirectResponse
*/
public function update(UpdateNewsTagRequest $request, NewsTag $news_tag): \Illuminate\Http\RedirectResponse

View file

@ -8,6 +8,7 @@ use App\Http\Requests\Front\Contact\ContactRequest;
use App\Jobs\Mails\SendContactMail;
use App\Models\ContactCount;
use App\Models\MailContactData;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\HtmlString;
use LDC\LDCCRM\Enums\ApiError;
@ -32,9 +33,9 @@ class ContactController
* Show contact show page.
*
* @param string $slug
* @return \Illuminate\Contracts\View\View
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Contracts\View\View
*/
public function show(string $slug): \Illuminate\Contracts\View\View
public function show(string $slug): \Illuminate\Http\RedirectResponse|\Illuminate\Contracts\View\View
{
$enumType = collect(ContactFormType::all())->first(function ($enum) use ($slug) {
return $enum->slug() === $slug;
@ -53,12 +54,16 @@ class ContactController
*/
public function send(ContactRequest $request): \Illuminate\Http\RedirectResponse
{
$data = $request->validated();
$messageContact = new MailContactData($data);
$validatedData = $request->validated();
$messageContact = new MailContactData($validatedData);
$contactMessage = "";
$hasContactError = false;
$newsletterMessage = null;
$hasNewsletterError = false;
/** @var boolean $isNewsletter */
$isNewsletter = $validatedData['newsletter'];
try {
dispatch(new SendContactMail($messageContact))
->onConnection('database')
@ -70,7 +75,7 @@ class ContactController
$hasContactError = true;
$contactMessage = trans('Une erreur est survenue lors de l\'envoi du message de contact.');
}
if (!empty($data['newsletter']) && $data['newsletter']) {
if ($isNewsletter) {
try {
SingleOptin::setStatus($request->email, true);
$newsletterMessage = trans("Votre inscription à la newsletter a été prise en compte");
@ -90,8 +95,8 @@ class ContactController
}
}
ContactCount::updateOrInsert(
['type' => $data['enumType']],
['submissions' => \DB::raw('submissions + 1')]
['type' => $validatedData['enumType']],
['submissions' => DB::raw('submissions + 1')]
);
$contactMessage = trans('Votre message a bien été envoyé.');

View file

@ -68,13 +68,14 @@ class HomeController extends Controller
/**
* Call the CRM to add a single optin
*
* @param \App\Http\Requests\Fo\SingleOptinRequest $request
* @param \App\Http\Requests\Front\SingleOptinRequest $request
* @return string|array|null|\Illuminate\Contracts\Translation\Translator
* @throws \LDC\LDCCRM\Exceptions\ValidationException ValidationException.
* @throws \Illuminate\Contracts\Container\BindingResolutionException BindingResolutionException.
*/
public function addOptIn(SingleOptinRequest $request)
{
public function addOptIn(
SingleOptinRequest $request,
): string|array|null|\Illuminate\Contracts\Translation\Translator {
try {
SingleOptin::setStatus($request->email, true);
return \response(trans("Votre inscription à la newsletter a été prise en compte"), 200);

View file

@ -2,16 +2,17 @@
namespace App\Http\Controllers\Front;
use Carbon\Carbon;
use App\Enums\OrdersEnum;
use App\Enums\YearsEnum;
use App\Http\Requests\Front\PostsRequest;
use App\Models\Document;
use App\Models\DocumentTag;
use App\Models\News;
use App\Models\NewsTag;
use App\Enums\YearsEnum;
use App\Models\Document;
use App\Enums\OrdersEnum;
use App\Models\DocumentTag;
use Illuminate\Support\Str;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection;
use App\Http\Requests\Front\PostsRequest;
use Illuminate\Support\Str;
use Uwil\LaravelCommon\Controllers\Controller;
use Uwil\LaravelCommon\Helpers\CollectionHelper;
@ -26,12 +27,14 @@ class PostsController extends Controller
/**
* Extract unique years from date field in a collection.
*
* @param \Illuminate\Support\Collection $model
* @param string $field
* @param EloquentCollection $model
* @param string $field
* @return \Illuminate\Support\Collection
*/
private function getUniqueYearsFromCollection(Collection $model, string $field): \Illuminate\Support\Collection
{
private function getUniqueYearsFromCollection(
EloquentCollection $model,
string $field,
): \Illuminate\Support\Collection {
return $model->pluck($field)
->map(fn($date) => Carbon::parse($date)->year)
->unique()
@ -55,27 +58,30 @@ class PostsController extends Controller
}
/**
* Build the common filters configuration for front-end listing pages
* Build the common filters configuration for front-end listing pages.
* If the type is "documents" the "order" filter is included.
*
* If the type is "documents" the "order" filter is included
*
* @param string $type
* @param string $category
* @param \Illuminate\Database\Eloquent\Collection $publishedTags
* @param \Illuminate\Database\Eloquent\Collection $model
* @param string $type
* @param string $category
* @param EloquentCollection $publishedTags
* @param EloquentCollection $model
* @return array
*/
private function getFilters(string $type, string $category, Collection $publishedTags, Collection $model): array
{
private function getFilters(
string $type,
string $category,
EloquentCollection $publishedTags,
EloquentCollection $model,
): array {
$filters = [];
$tags = collect($publishedTags)
->map(fn($tag) => [
'title' => $tag->name,
'tag' => $tag->slug,
'category' => $category,
])
->values();
/** @phpstan-ignore-next-line */
$tags = $publishedTags->map(fn(DocumentTag|NewsTag $tag) => [
'title' => $tag->name,
'tag' => $tag->slug,
'category' => $category,
])
->values();
$enumYears = collect(YearsEnum::toArray())
->map(fn($year) => YearsEnum::make((int) $year->value))
@ -140,18 +146,19 @@ class PostsController extends Controller
*/
public function ajaxLoadNews(PostsRequest $request): \Illuminate\Http\JsonResponse
{
$data = $request->validated();
$validatedData = $request->validated();
$perPage = 9;
$selectedFilters = [];
$category = $data['category'];
app()->setLocale($data['locale']);
/** @var string $slugCategory */
$slugCategory = $validatedData['category'];
$publishedNewsTags = NewsTag::getTagsByCategoryInCurrentLocale($category);
app()->setLocale($validatedData['locale']);
$newsModel = News::getPublishedNewsByCategoryInCurrentLocale($category);
$publishedNewsTags = NewsTag::getTagsByCategoryInCurrentLocale($slugCategory);
$newsModel = News::getPublishedNewsByCategoryInCurrentLocale($slugCategory);
$requestedTags = collect($data['filters']['tags'] ?? '')
$requestedTags = collect($validatedData['filters']['tags'] ?? '')
->filter()
->unique()
->values();
@ -162,13 +169,13 @@ class PostsController extends Controller
'title' => $tag->name,
'tag' => $tag->slug,
'color' => $tag->color,
'category' => $category,
'category' => $slugCategory,
])
->values();
if ($selectedTags->isNotEmpty()) {
$newsModel = $newsModel->filter(function ($news) use ($selectedTags) {
return $news->tags->contains(
$newsModel = $newsModel->filter(function ($newsModel) use ($selectedTags) {
return $newsModel->tags->contains(
fn ($tag) => $selectedTags->contains('id', $tag->id)
);
});
@ -176,14 +183,14 @@ class PostsController extends Controller
$selectedFilters['tags'] = $selectedTags;
}
$selectedYears = collect($data['filters']['years'] ?? '')
$selectedYears = collect($validatedData['filters']['years'] ?? '')
->map(fn (string $label) => YearsEnum::makeFromLabel(Str::replace('-', '/', $label)))
->filter()
->map(fn($year) => [
'title' => $year->label(),
'tag' => Str::replace('/', '-', $year->label()),
'value' => explode('/', $year->label())[1],
'category' => $category,
'category' => $slugCategory,
])
->values();
@ -197,7 +204,7 @@ class PostsController extends Controller
$newsModel = $newsModel->sortByDesc('published_at');
$filters = $this->getFilters('news', $category, $publishedNewsTags, $newsModel);
$filters = $this->getFilters('news', $slugCategory, $publishedNewsTags, $newsModel);
// Custom pagination.
$newsModel = CollectionHelper::paginate($newsModel, $perPage);
@ -227,36 +234,36 @@ class PostsController extends Controller
*/
public function ajaxLoadDocuments(PostsRequest $request): \Illuminate\Http\JsonResponse
{
$data = $request->validated();
$validatedData = $request->validated();
$perPage = 3;
$selectedFilters = [];
$category = $data['category'];
app()->setLocale($data['locale']);
/** @var string $slugCategory */
$slugCategory = $validatedData['category'];
$publishedDocumentsTags = DocumentTag::getTagsByCategoryInCurrentLocale($category);
app()->setLocale($validatedData['locale']);
$documentsModel = Document::getPublishedDocumentsByCategoryInCurrentLocale($category);
$documentTagModels = DocumentTag::getTagsByCategoryInCurrentLocale($slugCategory);
$documentModels = Document::getPublishedDocumentsByCategoryInCurrentLocale($slugCategory);
$requestedTags = collect($data['filters']['tags'] ?? '')
$requestedTags = collect($validatedData['filters']['tags'] ?? '')
->filter()
->unique()
->values();
$selectedTags = $publishedDocumentsTags
$selectedTags = $documentTagModels
->filter(fn ($tag) => $requestedTags->contains($tag->slug ?? null))
->map(fn ($tag) => [
'id' => $tag->id,
'title' => $tag->name,
'tag' => $tag->slug,
'color' => $tag->color,
'category' => $category,
'category' => $slugCategory,
])
->values();
if ($selectedTags->isNotEmpty()) {
$documentsModel = $documentsModel->filter(function ($documents) use ($selectedTags) {
return $documents->tags->contains(
$documentModels = $documentModels->filter(function ($documentModel) use ($selectedTags) {
return $documentModel->tags->contains(
fn ($tag) => $selectedTags->contains('id', $tag->id)
);
});
@ -264,64 +271,65 @@ class PostsController extends Controller
$selectedFilters['tags'] = $selectedTags;
}
$selectedYears = collect($data['filters']['years'] ?? '')
$selectedYears = collect($validatedData['filters']['years'] ?? '')
->map(fn (string $label) => YearsEnum::makeFromLabel(Str::replace('-', '/', $label)))
->filter()
->map(fn($year) => [
'title' => $year->label(),
'tag' => Str::replace('/', '-', $year->label()),
'value' => $year->value,
'category' => $category,
'category' => $slugCategory,
])
->values();
if ($selectedYears->isNotEmpty()) {
$documentsModel = $documentsModel->filter(function ($documents) use ($selectedYears) {
return $selectedYears->contains('value', $documents->exercice);
$documentModels = $documentModels->filter(function ($documentModel) use ($selectedYears) {
return $selectedYears->contains('value', $documentModel->exercice);
});
$selectedFilters['years'] = $selectedYears;
}
$selectedOrder = collect($data['filters']['order'] ?? '')
$selectedOrder = collect($validatedData['filters']['order'] ?? '')
->map(fn (string $label) => OrdersEnum::makeFromLabel($label))
->filter()
->map(fn($order) => [
'title' => trans($order->label()),
'tag' => $order->name(),
'category' => $category,
'category' => $slugCategory,
])
->values();
if ($selectedOrder->isNotEmpty()) {
$documentsModel = $selectedOrder->map->tag->first() === 'desc'
? $documentsModel->sortByDesc('published_at')
: $documentsModel->sortBy('published_at');
$firstTag = $selectedOrder->map(fn($order) => $order['tag'])->first();
$documentModels = $firstTag === 'desc'
? $documentModels->sortByDesc('published_at')
: $documentModels->sortBy('published_at');
$selectedFilters['order'] = $selectedOrder->all();
} else {
$documentsModel = $documentsModel->sortByDesc('published_at');
$documentModels = $documentModels->sortByDesc('published_at');
}
$filters = $this->getFilters('documents', $category, $publishedDocumentsTags, $documentsModel);
$filters = $this->getFilters('documents', $slugCategory, $documentTagModels, $documentModels);
// Custom pagination.
$documentsModel = CollectionHelper::paginate($documentsModel, $perPage);
$documentModels = CollectionHelper::paginate($documentModels, $perPage);
return response()->json([
'pagination' => [
'total' => $documentsModel->total(),
'nbItems' => count($documentsModel->items()),
'currentPage' => $documentsModel->currentPage(),
'lastPage' => $documentsModel->lastPage(),
'hasMore' => $documentsModel->currentPage() < $documentsModel->lastPage(),
'total' => $documentModels->total(),
'nbItems' => count($documentModels->items()),
'currentPage' => $documentModels->currentPage(),
'lastPage' => $documentModels->lastPage(),
'hasMore' => $documentModels->currentPage() < $documentModels->lastPage(),
],
'filters' => view('components.front.posts.filters-dropdowns', ['filters' => $filters])->render(),
'selectedFilters' => view('components.front.posts.selected-filters', [
'selectedFilters' => $selectedFilters,
])->render(),
'news' => view('components.front.posts.documents', [
'documentsList' => $documentsModel->items(),
'documentsList' => $documentModels->items(),
])->render()
]);
}

View file

@ -1,6 +1,6 @@
<?php
namespace App\Http\Requests\Back\DocumentCategory;
namespace App\Http\Requests\Back\DocumentCategories;
use App\Models\DocumentCategory;
use Illuminate\Foundation\Http\FormRequest;

View file

@ -1,6 +1,6 @@
<?php
namespace App\Http\Requests\Back\DocumentCategory;
namespace App\Http\Requests\Back\DocumentCategories;
use Illuminate\Support\Facades\Gate;

View file

@ -1,6 +1,6 @@
<?php
namespace App\Http\Requests\Back\DocumentTag;
namespace App\Http\Requests\Back\DocumentTags;
use App\Models\DocumentTag;
use Illuminate\Foundation\Http\FormRequest;

View file

@ -1,6 +1,6 @@
<?php
namespace App\Http\Requests\Back\DocumentTag;
namespace App\Http\Requests\Back\DocumentTags;
use Illuminate\Support\Facades\Gate;

View file

@ -1,6 +1,6 @@
<?php
namespace App\Http\Requests\Back\Document;
namespace App\Http\Requests\Back\Documents;
use App\Enums\Document\DocumentStatusEnum;
use App\Enums\YearsEnum;

View file

@ -1,6 +1,6 @@
<?php
namespace App\Http\Requests\Back\Document;
namespace App\Http\Requests\Back\Documents;
use Illuminate\Support\Facades\Gate;

View file

@ -1,6 +1,6 @@
<?php
namespace App\Http\Requests\Back\NewsCategory;
namespace App\Http\Requests\Back\NewsCategories;
use App\Models\NewsCategory;
use Illuminate\Foundation\Http\FormRequest;

View file

@ -1,6 +1,6 @@
<?php
namespace App\Http\Requests\Back\NewsCategory;
namespace App\Http\Requests\Back\NewsCategories;
use Illuminate\Support\Facades\Gate;

View file

@ -1,6 +1,6 @@
<?php
namespace App\Http\Requests\Back\NewsTag;
namespace App\Http\Requests\Back\NewsTags;
use App\Models\NewsTag;
use Illuminate\Foundation\Http\FormRequest;

View file

@ -1,6 +1,6 @@
<?php
namespace App\Http\Requests\Back\NewsTag;
namespace App\Http\Requests\Back\NewsTags;
use Illuminate\Support\Facades\Gate;

View file

@ -50,7 +50,7 @@ class StorePageConfigRequest extends FormRequest
'string',
'between:3,255',
'regex:/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/',
function ($attribute, $value, $fail) use ($prefix) {
function ($attribute, $value, $fail) {
$parentPath = implode('.', array_slice(explode('.', $attribute), 0, -2));
$levelItems = data_get($this->input(), $parentPath, []);
$keysAtLevel = collect($levelItems)->pluck('key')->filter()->toArray();

View file

@ -39,7 +39,7 @@ class Company extends Model
/**
* The attributes that are mass assignable.
*
* @var array<int, string, array[]>
* @var list<string>
*/
protected $fillable = [
'name',
@ -67,7 +67,7 @@ class Company extends Model
/**
* Relations should be included in the cache.
*
* @var array<string, string>
* @var list<string>
*/
protected static $cacheRelations = [
'companyActivity',

View file

@ -33,7 +33,7 @@ class CompanyActivity extends Model implements TranslatableModel
/**
* The attributes that are mass assignable.
*
* @var array<int, string, array[]>
* @var list<string>
*/
protected $fillable = [
'name',

View file

@ -32,7 +32,7 @@ class CompanySector extends Model implements TranslatableModel
/**
* The attributes that are mass assignable.
*
* @var array<int, string, array[]>
* @var list<string>
*/
protected $fillable = [
'name',

View file

@ -10,7 +10,7 @@ class ContactCount extends Model
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
* @var list<string>
*/
protected $fillable = [
'type',

View file

@ -18,6 +18,32 @@ use Illuminate\Support\Facades\App;
use Laravel\Scout\Searchable;
use Uwil\LaravelActivityLogs\Traits\ActivityLog;
/**
* @property integer $id
* Id of the document.
* @property string $name
* Name of the document.
* @property string $path
* Path of the document.
* @property boolean $is_issuu
* Issu status of the document.
* @property string $issuu_path
* Issu path of the document.
* @property string $exercice
* Exercice of the document.
* @property \App\Enums\Document\DocumentStatusEnum $status
* Status of the document.
* @property-read \Carbon\Carbon $created_at
* Created date of the document.
* @property-read \Carbon\Carbon $updated_at
* Updated date of the document.
* @property-read \Illuminate\Support\Carbon $deleted_at
* Deleted date of the document.
* @property \Illuminate\Database\Eloquent\Collection<int, \App\Models\DocumentCategory> $categories
* Associated document categories of the document.
* @property \Illuminate\Database\Eloquent\Collection<int, \App\Models\DocumentTag> $tags
* Associated document tags of the document.
*/
class Document extends Model implements TranslatableModel
{
use ActivityLog;
@ -81,7 +107,7 @@ class Document extends Model implements TranslatableModel
/**
* Relations should be included in the cache.
*
* @var array<string, string>
* @var list<string>
*/
protected static $cacheRelations = [
'categories',
@ -324,24 +350,24 @@ class Document extends Model implements TranslatableModel
/**
* Get all published news by category.
*
* @param string $category
*
* @return \Illuminate\Database\Eloquent\Collection
* @param string $slugCategory
* @return \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document>
*/
public static function getPublishedDocumentsByCategoryInCurrentLocale(string $category)
{
public static function getPublishedDocumentsByCategoryInCurrentLocale(
string $slugCategory,
): \Illuminate\Database\Eloquent\Collection {
$locale = App::getLocale();
return Document::getModelsCached()
->where('status', DocumentStatusEnum::published)
->filter(function ($document) use ($category, $locale) {
->filter(function ($document) use ($slugCategory, $locale) {
$hasPath = !empty($document->getTranslation('path', $locale, false));
$hasIssuuPath = $document->is_issuu === true
&& !empty($document->getTranslation('issuu_path', $locale, false));
return ($hasPath || $hasIssuuPath) && $document->categories->contains(
fn($cat) => $cat->slug === $category
fn($documentCategoryModel) => $documentCategoryModel->slug === $slugCategory
);
});
}
@ -349,11 +375,11 @@ class Document extends Model implements TranslatableModel
// * RELATIONSHIPS
/**
* Relation to Tag
* Relation to Tag.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function tags(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
public function tags(): \Illuminate\Database\Eloquent\Relations\MorphToMany
{
return $this->morphedByMany(
DocumentTag::class,
@ -365,11 +391,11 @@ class Document extends Model implements TranslatableModel
}
/**
* Relation to Category
* Relation to Category.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function categories(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
public function categories(): \Illuminate\Database\Eloquent\Relations\MorphToMany
{
return $this->morphedByMany(
DocumentCategory::class,

View file

@ -10,6 +10,22 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Uwil\LaravelActivityLogs\Traits\ActivityLog;
/**
* @property integer $id
* Id of the category.
* @property string $name
* Name of the category.
* @property string $slug
* Slug of the category.
* @property-read \Carbon\Carbon $created_at
* Created date of the category.
* @property-read \Carbon\Carbon $updated_at
* Updated date of the category.
* @property-read \Illuminate\Support\Carbon $deleted_at
* Deleted date of the category.
* @property \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* Associated documents of the category.
*/
class DocumentCategory extends Model implements TranslatableModel
{
use ActivityLog;
@ -38,12 +54,14 @@ class DocumentCategory extends Model implements TranslatableModel
'slug'
];
// * RELATIONSHIPS
/**
* Relation to Document
* Associated documents of the category.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function documents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
public function documents(): \Illuminate\Database\Eloquent\Relations\MorphToMany
{
return $this->morphToMany(
Document::class,

View file

@ -11,6 +11,24 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\App;
use Uwil\LaravelActivityLogs\Traits\ActivityLog;
/**
* @property integer $id
* Id of the tag.
* @property string $name
* Name of the tag.
* @property string $slug
* Slug of the tag.
* @property string $color
* Color of the tag.
* @property-read \Carbon\Carbon $created_at
* Created date of the tag.
* @property-read \Carbon\Carbon $updated_at
* Updated date of the tag.
* @property-read \Illuminate\Support\Carbon $deleted_at
* Deleted date of the tag.
* @property \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
* Associated documents of the tag.
*/
class DocumentTag extends Model implements TranslatableModel
{
use ActivityLog;
@ -43,34 +61,20 @@ class DocumentTag extends Model implements TranslatableModel
/**
* Relations should be included in the cache.
*
* @var array<string, string>
* @var list<string>
*/
protected static $cacheRelations = [
'documents',
];
/**
* Relation to Document
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function documents(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->morphToMany(
Document::class,
'documentable',
'documentables',
'documentable_id',
'document_id'
);
}
// * METHODS
/**
* Get all Tags by category.
*
* @param string $slugCategory
*
* @return \Illuminate\Database\Eloquent\Collection
* @return \Illuminate\Database\Eloquent\Collection<int, \App\Models\DocumentTag>
*/
public static function getTagsByCategoryInCurrentLocale(
string $slugCategory,
@ -92,4 +96,22 @@ class DocumentTag extends Model implements TranslatableModel
})->isNotEmpty();
});
}
// * RELATIONSHIPS
/**
* Associated documents of the tag.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function documents(): \Illuminate\Database\Eloquent\Relations\MorphToMany
{
return $this->morphToMany(
Document::class,
'documentable',
'documentables',
'documentable_id',
'document_id'
);
}
}

View file

@ -86,7 +86,7 @@ class DynamicPage extends Model implements TranslatableModel
/**
* Relations should be included in the cache.
*
* @var array<string, string>
* @var list<string>
*/
protected static $cacheRelations = [
'config',
@ -327,7 +327,7 @@ class DynamicPage extends Model implements TranslatableModel
/**
* Get fields that we want to keep in the current locale.
*
* @return array.
* @return array
*/
public static function searchTransFields(): array
{

View file

@ -44,7 +44,7 @@ class MailContactData extends Model
/**
* The attributes that are mass assignable.
*
* @var array<int, string, array[]>
* @var list<string>
*/
protected $fillable = [
'enumType',

View file

@ -21,21 +21,40 @@ use Mcamara\LaravelLocalization\Interfaces\LocalizedUrlRoutable;
use Uwil\LaravelActivityLogs\Traits\ActivityLog;
/**
* @property string $seo_title SEO title of the news.
* @property string $seo_description SEO description of the news.
* @property string $title Title of the news.
* @property string $slug Slug of the news.
* @property string $picture Main img of the news.
* @property string $picture_alt Alt text for the picture.
* @property string $picture_title Title for the picture.
* @property string $content Content of the news.
* @property boolean $inverted Are image and content inverted in front
* @property string $vimeo_id Optionnal vimeo_id
* @property boolean $has_show_picture Show the picture in the show page
* @property \App\Enums\News\NewsStatusEnum $status Status of the news.
* @property-read \Illuminate\Support\Carbon $created_at Date on which the news was created.
* @property-read \Illuminate\Support\Carbon $updated_at Date on which the news was updated.
* @property-read \Illuminate\Support\Carbon $deleted_at Date on which the news was updated.
* @property string $seo_title
* SEO title of the news.
* @property string $seo_description
* SEO description of the news.
* @property string $title
* Title of the news.
* @property string $slug
* Slug of the news.
* @property string $picture
* Main img of the news.
* @property string $picture_alt
* Alt text for the picture.
* @property string $picture_title
* Title for the picture.
* @property string $content
* Content of the news.
* @property boolean $inverted
* Are image and content inverted in front
* @property string $vimeo_id
* Optionnal vimeo_id
* @property boolean $has_show_picture
* Show the picture in the show page
* @property \App\Enums\News\NewsStatusEnum $status
* Status of the news.
* @property-read \Illuminate\Support\Carbon $created_at
* Date on which the news was created.
* @property-read \Illuminate\Support\Carbon $updated_at
* Date on which the news was updated.
* @property-read \Illuminate\Support\Carbon $deleted_at
* Date on which the news was updated.
* @property \Illuminate\Database\Eloquent\Collection<int, \App\Models\NewsCategory> $categories
* Associated news categories of the news.
* @property \Illuminate\Database\Eloquent\Collection<int, \App\Models\NewsTag> $tags
* Associated news tags of the news.
*/
class News extends Model implements TranslatableModel, LocalizedUrlRoutable
{
@ -145,7 +164,7 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable
/**
* Relations should be included in the cache.
*
* @var array<string, string>
* @var list<string>
*/
protected static $cacheRelations = [
'categories',
@ -332,9 +351,9 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable
* Get the url to access a specific resource.
*
* @param integer $id Id field of the target model.
* @return string
* @return string|null
*/
public static function getAccessModel(int $id): string
public static function getAccessModel(int $id): ?string
{
$targetModel = self::getModelsCached()->firstWhere('id', $id);
if (!$targetModel) {
@ -432,8 +451,7 @@ class News extends Model implements TranslatableModel, LocalizedUrlRoutable
* Get all published news by category.
*
* @param string $category
*
* @return \Illuminate\Database\Eloquent\Collection
* @return \Illuminate\Database\Eloquent\Collection<int, \App\Models\News>
*/
public static function getPublishedNewsByCategoryInCurrentLocale(string $category)
{

View file

@ -8,16 +8,21 @@ use App\Traits\Models\HasCache;
use App\Traits\Models\HasTranslations;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
use Uwil\LaravelActivityLogs\Traits\ActivityLog;
/**
* @property int $news_id News focused.
* @property string $name Name of the category.
* @property-read \Illuminate\Support\Carbon $created_at Date on which the news was created.
* @property-read \Illuminate\Support\Carbon $updated_at Date on which the news was updated.
* @property int $id
* Id of the news.
* @property string $name
* Name of the category.
* @property-read \Illuminate\Support\Carbon $created_at
* Date on which the category was created.
* @property-read \Illuminate\Support\Carbon $updated_at
* Date on which the category was updated.
* @property \Illuminate\Database\Eloquent\Collection<int, \App\Models\News> $news
* Associated news of the category.
*/
class NewsCategory extends Model implements TranslatableModel
{
@ -30,7 +35,7 @@ class NewsCategory extends Model implements TranslatableModel
/**
* The attributes that are mass assignable.
*
* @var array<int, string, array[]>
* @var list<string>
*/
protected $fillable = [
'name',
@ -63,6 +68,8 @@ class NewsCategory extends Model implements TranslatableModel
});
}
// * METHODS
/**
* Manage model fields.
*
@ -80,12 +87,14 @@ class NewsCategory extends Model implements TranslatableModel
TranslationHelper::validateFallbackTranslations($model);
}
// * RELATIONSHIPS
/**
* The relation with News
* Associated news of the category.
*
* @return BelongsToMany
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function news(): BelongsToMany
public function news(): \Illuminate\Database\Eloquent\Relations\MorphToMany
{
return $this->morphToMany(
News::class,

View file

@ -12,11 +12,18 @@ use Uwil\LaravelActivityLogs\Traits\ActivityLog;
use Illuminate\Database\Eloquent\Factories\HasFactory;
/**
* @property int $news_id News focused.
* @property string $name Name of the tag.
* @property string $color Color of the tag
* @property-read \Illuminate\Support\Carbon $created_at Date on which the news was created.
* @property-read \Illuminate\Support\Carbon $updated_at Date on which the news was updated.
* @property int $news_id
* News focused.
* @property string $name
* Name of the tag.
* @property string $color
* Color of the tag
* @property-read \Illuminate\Support\Carbon $created_at
* Date on which the tag was created.
* @property-read \Illuminate\Support\Carbon $updated_at
* Date on which the tag was updated.
* @property \Illuminate\Database\Eloquent\Collection<int, \App\Models\News> $news
* Associated news of the tag.
*/
class NewsTag extends Model implements TranslatableModel
{
@ -50,33 +57,19 @@ class NewsTag extends Model implements TranslatableModel
/**
* Relations should be included in the cache.
*
* @var array<string, string>
* @var list<string>
*/
protected static $cacheRelations = [
'news',
];
/**
* Relation to Document
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function news(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->morphToMany(
News::class,
'newsable',
'newsables',
'newsable_id',
'news_id'
);
}
// * METHODS
/**
* Get all Tags by category.
*
* @param string $slugCategory
* @return \Illuminate\Database\Eloquent\Collection
* @return \Illuminate\Database\Eloquent\Collection<int, \App\Models\NewsTag>
*/
public static function getTagsByCategoryInCurrentLocale(
string $slugCategory,
@ -93,4 +86,22 @@ class NewsTag extends Model implements TranslatableModel
})->isNotEmpty();
});
}
// * RELATIONSHIPS
/**
* Associated news of the tag.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function news(): \Illuminate\Database\Eloquent\Relations\MorphToMany
{
return $this->morphToMany(
News::class,
'newsable',
'newsables',
'newsable_id',
'news_id'
);
}
}

View file

@ -113,51 +113,21 @@ class PageConfig extends Model implements TranslatableModel
TranslationHelper::validateFallbackTranslations($model);
}
/**
* Check if the config is updated.
*
* @param array $newArray
* @param array $originalArray
* @return boolean
*/
private static function isConfigUpdated(array $newArray, array $originalArray): bool
{
if (count($newArray) !== count($originalArray)) {
return false;
}
foreach ($newArray as $i => $subA) {
$subB = $originalArray[$i] ?? null;
if ($subB === null) {
return false;
}
ksort($subA);
ksort($subB);
if ($subA != $subB) {
return false;
}
}
return true;
}
/**
* Get the target model from a specific id and model name.
*
* @param string $modelId
* @param string $modelName
* @return \Illuminate\Database\Eloquent\Model
* @return \Illuminate\Database\Eloquent\Model|null
*/
public static function getModelFromInputModelConfig(
string $modelId,
string $modelName,
): \Illuminate\Database\Eloquent\Model {
): ?\Illuminate\Database\Eloquent\Model {
$studly = Str::studly(Str::singular($modelName));
$class = "App\\Models\\{$studly}";
if (!$class || !class_exists($class)) {
if (!class_exists($class)) {
return null;
}

View file

@ -53,6 +53,7 @@ class DynamicPageRouteServiceProvider extends ServiceProvider
$slug = $dynamicPageModel->getTranslation('slug', $locale);
// If no slug for the locale → skip.
/** @phpstan-ignore-next-line */
if (!empty($slug) && !$slug) {
continue;
}

View file

@ -28,10 +28,13 @@ trait HasCache
static::deleted(function () {
self::resetCache();
});
/** @phpstan-ignore-next-line */
if (method_exists(static::class, 'initializeSoftDeletes')) {
/** @phpstan-ignore-next-line */
static::restored(function () {
self::resetCache();
});
/** @phpstan-ignore-next-line */
static::forceDeleted(function () {
self::resetCache();
});
@ -57,11 +60,12 @@ trait HasCache
public static function getModelsCached(): \Illuminate\Database\Eloquent\Collection
{
return Cache::remember(static::getCacheKey(), 86400, function () {
/** @var class-string<static> $class */
$class = static::class;
/** @var \Illuminate\Database\Eloquent\Model $class */
/** @phpstan-ignore-next-line */
return $class::query()
->when(
/** @phpstan-ignore-next-line */
property_exists($class, 'cacheRelations') && is_array($class::$cacheRelations),
function ($query) use ($class) {
$query->with($class::$cacheRelations);
@ -76,8 +80,8 @@ trait HasCache
*
* @return string
*/
private static function getCacheKey(): string
public static function getCacheKey(): string
{
return 'cache_' . str_replace('\\', '_', static::class);
return sprintf("cache_%s", str_replace('\\', '_', static::class));
}
}

View file

@ -42,9 +42,11 @@ trait HasUwilImages
*/
protected static function bootHasUwilImages(): void
{
/** @phpstan-ignore-next-line */
$hadSoftDelete = method_exists(static::class, 'initializeSoftDeletes');
if ($hadSoftDelete) {
/** @phpstan-ignore-next-line */
static::forceDeleted(function (self $model) {
self::initLoop($model, self::FORCE_DELETE_ACTION);
});
@ -134,9 +136,8 @@ trait HasUwilImages
continue;
} //end if
// PAS TESTE.
// TODO pas testé
if (is_array($originalValue) && is_array($currentValue)) {
dd('juste array');
static::traverseAndManage(
$model,
$originalValue,
@ -168,7 +169,7 @@ trait HasUwilImages
$forceDeleteImage = $eventType === self::FORCE_DELETE_ACTION;
$imagesFields = self::getImageFields($model);
$wysiwygFields = self::getWysiwygFields($model);
$isTranslatable = method_exists($model, 'getTranslations') ?? false;
$isTranslatable = method_exists($model, 'getTranslations');
$locale = config('app.locale');
$availableLocales = array_keys(config('laravellocalization.supportedLocales', ['fr' => "Frenchouz"]));
@ -230,7 +231,6 @@ trait HasUwilImages
$path = $isList ? "$fieldPath.$key" : (is_int($key) ? $fieldPath : "$fieldPath.$key");
// TODO cette récursivité n'a pas encore été testé.
if (is_array($oldValue) || is_array($newValue)) {
dd('pas testé');
static::traverseAndManage(
$model,
(array) $oldValue,

View file

@ -14,7 +14,7 @@ trait HasLaravelFailedValidation
* @return void
* @throws \Illuminate\Http\Exceptions\HttpResponseException Override ajax code error.
*/
protected function failedValidation(Validator $validator): \Illuminate\Http\Exceptions\HttpResponseException
protected function failedValidation(Validator $validator): void
{
$response = response()->json([
'errors' => $validator->errors(),

View file

@ -13,7 +13,7 @@ trait HasInertiaPicture
*/
protected function mergeInertiaPicture(): void
{
if (empty($this->convertedFiles) || !is_array($this->convertedFiles)) {
if (empty($this->convertedFiles)) {
return;
}
$original = $this->all();
@ -47,7 +47,7 @@ trait HasInertiaPicture
* Set picture rules (UploadedFile or string path).
*
* @param string $rules
* @return string
* @return array<mixed>
*/
protected function pictureRules(string $rules): array
{

View file

@ -9,7 +9,7 @@ use Illuminate\View\Component;
class NewsNextEventComponent extends Component
{
/** @var array<\App\Models\News> $nextEvents List of published news. */
/** @var \Illuminate\Support\Collection<int, \App\Models\News> $nextEvents List of published news. */
public $nextEvents;
/**
@ -17,12 +17,16 @@ class NewsNextEventComponent extends Component
*/
public function __construct()
{
/** @var \App\Models\NewsCategory|null $newsCategory */
$newsCategory = NewsCategory::getModelsCached()
->filter(fn($category) => $category->getTranslation('slug', 'fr') === "actualites")
->first();
/** @var \App\Models\NewsTag|null $eventTag */
$eventTag = NewsTag::getTagsByCategoryInCurrentLocale($newsCategory->slug)
->filter(fn($tag) => $tag->getTranslation('slug', 'fr') === "evenement")
->filter(
fn(\Illuminate\Database\Eloquent\Model $tag) => $tag->getTranslation('slug', 'fr') === "evenement"
)
->first();
$eventTagId = $eventTag ? $eventTag->id : null;
@ -30,7 +34,7 @@ class NewsNextEventComponent extends Component
$this->nextEvents = News::getPublishedNewsByCategoryInCurrentLocale($newsCategory->slug)
->filter(function ($news) use ($eventTagId) {
return $news->tags->contains(
fn ($tag) => $eventTagId === $tag->id
fn($tag) => $eventTagId === $tag->id
);
})
->sortByDesc('published_at')

View file

@ -11,13 +11,13 @@ class OurImplantations extends Component
/** @var string $id Identification of the section. */
public string $id;
/** @var $implantations Content section. */
/** @var array Content section. */
public $implantations;
/** @var array<\App\Models\Company> $companyModels List of published companies. */
/** @var \Illuminate\Database\Eloquent\Collection $companyModels List of published companies. */
public $companyModels;
/** @var array<\App\Models\CompanyActivity> $companyActivityModels List of published company activities. */
/** @var \Illuminate\Database\Eloquent\Collection $companyActivityModels List of published company activities. */
public $companyActivityModels;
/**

View file

@ -81,7 +81,7 @@ export default function EnumSelect({
/**
* Get the identification field of specific option.
* @param option Model
* @param value number
* @return string
*/
const getEnumLabel = (value: number): string => {

View file

@ -18,7 +18,7 @@ import {
TableRow,
} from "@/components/ui/table";
// * Other
import { Model, Resource, Views } from "@/back/types/global";
import { DefaultModel, Resource, Views } from "@/back/types/global";
import ModelActions from "@/back/Components/ModelActions";
import DataTableFilterButton from "@/back/Components/Table/DataTableFilterButton";
import PaginationWrapper from "@/back/Components/Pagination/PaginationWrapper";
@ -102,7 +102,7 @@ export default function DataTable<TData, TValue>({
<ModelActions
actions={actions}
modelRoute={modelRoute}
model={row.original as Model}
model={row.original as DefaultModel}
inDialog
/>
</TableCell>

View file

@ -11,16 +11,16 @@ import {
} from "@/components/ui/table";
// * Other
import useTrans from "@/hooks/use-translations";
import { Model } from "@/back/types/global";
import { DefaultModel } from "@/back/types/global";
interface DetailsTableProps {
columns: {
accessorKey: keyof Model;
accessorKey: keyof DefaultModel;
header: string;
// eslint-disable-next-line no-unused-vars
cell?: (params: { value: unknown }) => ReactNode;
}[];
model: Model;
model: DefaultModel;
forceRenderValue?: boolean;
}

View file

@ -1,4 +1,4 @@
// * Packages
// * Other
import useTrans from "@/hooks/use-translations";
export default function WordCounter({ value }: { value: string }) {

View file

@ -197,7 +197,9 @@ export default function Form({
choice: 1,
})}
pathField={data.slug}
additionalGroupPath="actualites" // TODO: ce sera translatable plus tard
additionalGroupPath={useTrans("models.classes.news", {
choice: 1,
})}
isAvailable={
model?.status === enumNewsStatus.published.value
}