118 lines
3.7 KiB
PHP
118 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Ajax;
|
|
|
|
use App\Enums\MediaStatut;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class UpdateMediaRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return auth()->check() and $this->ajax();
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function prepareForValidation()
|
|
{
|
|
$this->merge([
|
|
'tags' => $this->tags ?? [],
|
|
'articles' => $this->articles ?? [],
|
|
'marques' => $this->marques ?? [],
|
|
'societes' => $this->societes ?? []
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules()
|
|
{
|
|
$rules = [
|
|
'statut' => 'required|numeric|in:' . \implode(',', collect(MediaStatut::cases())->pluck('value')->all()),
|
|
'version' => 'required|numeric|min:1',
|
|
'type_vue_id' => 'required|exists:type_vues,codeTypevue',
|
|
'variante_id' => 'required|exists:variantes,codeVariante',
|
|
'langue_id' => 'required|exists:langues,langue_id',
|
|
];
|
|
|
|
// ? Est lié à arcadia ?
|
|
if ($this->media->arcadia_id) {
|
|
// Ne pas autoriser brouillon .
|
|
$rules['statut'] = 'required|numeric|in:' . \implode(',', [
|
|
MediaStatut::public->value, MediaStatut::public_etendu->value
|
|
]);
|
|
unset($rules['version']);
|
|
unset($rules['type_vue_id']);
|
|
unset($rules['variante_id']);
|
|
unset($rules['langue_id']);
|
|
}
|
|
|
|
// Article.
|
|
if ($this->sujet_id == 1) {
|
|
$rules['articles'] = 'present|array|min:0';
|
|
$rules['articles.*'] = 'array';
|
|
$rules['articles.*.id'] = 'exists:articles,id';
|
|
}
|
|
// Marque.
|
|
if ($this->sujet_id == 2) {
|
|
$rules['marques'] = 'present|array|min:0';
|
|
$rules['marques.*'] = 'array';
|
|
$rules['marques.*.codMarq'] = 'exists:marques,codMarq';
|
|
}
|
|
// Sociétés.
|
|
if ($this->sujet_id == 4) {
|
|
$rules['societes'] = 'present|array|min:0';
|
|
$rules['societes.*'] = 'array';
|
|
$rules['societes.*.id'] = 'exists:societes,id';
|
|
}
|
|
|
|
return \array_merge($rules, [
|
|
'libelle' => 'required|string|min:2|max:50',
|
|
'commentaire' => 'nullable|string|min:2',
|
|
'copyright_id' => 'required|exists:copyrights,copyright_id',
|
|
|
|
// Tags.
|
|
'tags' => 'present|array|min:0',
|
|
'tags.*.libelle' => 'min:2|max:50',
|
|
|
|
'etiquette_id' => 'required|exists:etiquettes,etiquette_id',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array<string,string>
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'libelle' => trans('libelle'),
|
|
'commentaire' => trans('commentaire'),
|
|
'societes' => trans('societes'),
|
|
'societes.*' => trans('societes'),
|
|
'societes.*.id' => trans('societes'),
|
|
'marques' => trans('marques'),
|
|
'marques.*' => trans('marques'),
|
|
'marques.*.codMarq' => trans('marques'),
|
|
'copyright_id' => trans('copyright'),
|
|
'etiquette_id' => trans('etiquette'),
|
|
'type_vue_id' => trans('type de vue'),
|
|
'variante_id' => trans('type de variante'),
|
|
'tags' => trans('nuage de tags'),
|
|
'tags.*.libelle' => trans('libellé dans le nuage de tags'),
|
|
];
|
|
}
|
|
}
|