132 lines
6.1 KiB
PHP
132 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Settings;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class UpdateSettingsRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return auth('backend')->check();
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
*
|
|
* @return void
|
|
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
|
|
*/
|
|
protected function prepareForValidation()
|
|
{
|
|
// phpcs:enable
|
|
$this->merge([
|
|
// Checkboxes.
|
|
'use_ean_codes' => $this->use_ean_codes ? true : false,
|
|
'activated_teaser' => $this->activated_teaser ? true : false,
|
|
'activated_close_page' => $this->activated_close_page ? true : false,
|
|
'reductions_activated' => $this->reductions_activated ? true : false,
|
|
'winning_proof' => $this->winning_proof ? true : false,
|
|
// Arrays.
|
|
'notification_emails' => collect($this->notification_emails)->filter()->all(),
|
|
// Remove some dates if the checkbox is uncheck.
|
|
'close_page_active_date' => $this->activated_close_page ? $this->close_page_active_date : null,
|
|
// Remove reductions datas if the reduction checkbox is uncheck.
|
|
'reductions_site' => $this->reductions_activated ? $this->reductions_site : null,
|
|
'reductions_campaign' => $this->reductions_activated ? $this->reductions_campaign : null,
|
|
'web_coupons' => collect($this->web_coupons)->filter()->all(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'name' => 'required|string|min:3|max:255',
|
|
'company' => 'required|string|min:3|max:255',
|
|
|
|
'start_date' => 'required|date',
|
|
'end_date' => 'required|date',
|
|
'nb_participation_player' => 'required|numeric|min:0',
|
|
'nb_participation_ip' => 'required|numeric|min:0',
|
|
'nb_unique_code_use' => 'required|numeric|min:0',
|
|
'use_ean_codes' => 'required|boolean',
|
|
'activated_teaser' => 'required|boolean',
|
|
'activated_close_page' => 'required|boolean',
|
|
'close_page_active_date' => 'nullable|required_if:activated_close_page,true,1|date|after_or_equal:today',
|
|
'redirect_close' => 'required|url:http,https',
|
|
|
|
'reductions_activated' => 'required|boolean',
|
|
'reductions_site' => 'nullable|required_if:reductions_activated,true,1|string|min:3|max:255',
|
|
'reductions_campaign' => 'nullable|required_if:reductions_activated,true,1|string|min:3|max:255',
|
|
|
|
'web_coupons' => [
|
|
'present', 'array', function ($attribute, $value, $fail) {
|
|
if ($this->post('reductions_activated') and !collect($value)->filter()->count()) {
|
|
$fail(trans('validation.min.array', [
|
|
'attribute' => $this->attributes()[$attribute],
|
|
'min' => 1
|
|
]));
|
|
}
|
|
}
|
|
],
|
|
'web_coupons.*' => 'array',
|
|
'web_coupons.*.web_coupon_identifiant' => 'required|string|min:3|max:255',
|
|
'web_coupons.*.percentage' => 'required|numeric|min:0|max:100',
|
|
'web_coupons.*.face_value' => 'required|string|min:3|max:255',
|
|
'web_coupons.*.valid_on' => 'required|string|min:3|max:255',
|
|
'web_coupons.*.img_name' => 'required|string|min:3|max:255',
|
|
|
|
'notification_emails' => 'required|array|min:1',
|
|
'notification_emails.*' => 'email:rfc,spoof,dns',
|
|
|
|
'winning_proof' => 'required|boolean',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'name' => trans('validation.attributes.name'),
|
|
'company' => trans('validation.custom.company'),
|
|
'start_date' => trans('validation.custom.start_date'),
|
|
'end_date' => trans('validation.custom.end_date'),
|
|
'nb_participation_player' => trans('validation.custom.nb_participation_player'),
|
|
'nb_participation_ip' => trans('validation.custom.nb_participation_ip'),
|
|
'nb_unique_code_use' => trans('validation.custom.nb_unique_code_use'),
|
|
'use_ean_codes' => trans('validation.custom.use_ean_codes'),
|
|
'activated_teaser' => trans('validation.custom.activated_teaser'),
|
|
'activated_close_page' => trans('validation.custom.activated_close_page'),
|
|
'close_page_active_date' => trans('validation.custom.close_page_active_date'),
|
|
'redirect_close' => trans('validation.custom.redirect_close'),
|
|
'winning_proof' => trans('validation.custom.winning_proof'),
|
|
'reductions_activated' => trans('validation.custom.reductions_activated'),
|
|
'reductions_site' => trans('validation.custom.reductions_site'),
|
|
'reductions_campaign' => trans('validation.custom.reductions_campaign'),
|
|
|
|
'web_coupons' => trans('Tableau des coupons'),
|
|
'web_coupons.*.web_coupon_identifiant' => trans('Identifiant coupon :index'),
|
|
'web_coupons.*.percentage' => trans('Pourcentage :index'),
|
|
'web_coupons.*.face_value' => trans('Valeur faciale :index'),
|
|
'web_coupons.*.valid_on' => trans('Valable sur :index'),
|
|
'web_coupons.*.img_name' => trans('Nom image :index'),
|
|
|
|
'notification_emails' => trans('Tableau des email à notifier'),
|
|
'notification_emails.*.email' => trans('validation.attributes.email')
|
|
];
|
|
}
|
|
}
|