2023-12-30 01:00:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Fields;
|
|
|
|
|
2024-02-08 23:09:51 +01:00
|
|
|
use App\Form\Contracts\Displayable;
|
2024-02-16 14:18:16 +01:00
|
|
|
use App\Form\Models\Form;
|
|
|
|
use App\Form\Models\Participant;
|
2024-02-09 23:22:49 +01:00
|
|
|
use App\Form\Presenters\DatePresenter;
|
|
|
|
use App\Form\Presenters\Presenter;
|
2024-02-08 23:09:51 +01:00
|
|
|
use Carbon\Carbon;
|
2023-12-30 01:00:58 +01:00
|
|
|
use Faker\Generator;
|
|
|
|
|
|
|
|
class DateField extends Field
|
|
|
|
{
|
2024-02-06 01:45:25 +01:00
|
|
|
|
|
|
|
public bool $required;
|
|
|
|
public bool $maxToday;
|
|
|
|
|
2023-12-30 01:00:58 +01:00
|
|
|
public static function name(): string
|
|
|
|
{
|
|
|
|
return 'Datum';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function meta(): array
|
|
|
|
{
|
|
|
|
return [
|
2024-04-12 15:23:18 +02:00
|
|
|
['key' => 'required', 'default' => true, 'rules' => ['required' => 'present|boolean'], 'label' => 'Erforderlich'],
|
2023-12-30 01:00:58 +01:00
|
|
|
['key' => 'max_today', 'default' => false, 'rules' => ['required' => 'present|boolean'], 'label' => 'Nur daten bis heute erlauben'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-02-03 17:51:27 +01:00
|
|
|
public static function default(): ?string
|
2023-12-30 01:00:58 +01:00
|
|
|
{
|
2024-02-03 17:51:27 +01:00
|
|
|
return null;
|
2023-12-30 01:00:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function fake(Generator $faker): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'required' => $faker->boolean(),
|
|
|
|
'max_today' => $faker->boolean(),
|
|
|
|
];
|
|
|
|
}
|
2024-02-06 01:45:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2024-02-19 02:10:58 +01:00
|
|
|
public function getRegistrationRules(Form $form): array
|
2024-02-06 01:45:25 +01:00
|
|
|
{
|
|
|
|
$rules = [$this->required ? 'required' : 'nullable'];
|
|
|
|
|
|
|
|
$rules[] = 'date';
|
|
|
|
|
|
|
|
if ($this->maxToday) {
|
|
|
|
$rules[] = 'before_or_equal:' . now()->format('Y-m-d');
|
|
|
|
}
|
|
|
|
|
|
|
|
return [$this->key => $rules];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2024-02-19 02:10:58 +01:00
|
|
|
public function getRegistrationAttributes(Form $form): array
|
2024-02-06 01:45:25 +01:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
$this->key => $this->name,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2024-02-19 02:10:58 +01:00
|
|
|
public function getRegistrationMessages(Form $form): array
|
2024-02-06 01:45:25 +01:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
$this->key . '.before_or_equal' => $this->name . ' muss ein Datum vor oder gleich dem ' . now()->format('d.m.Y') . ' sein.',
|
|
|
|
];
|
|
|
|
}
|
2024-02-08 23:09:51 +01:00
|
|
|
|
2024-02-09 23:22:49 +01:00
|
|
|
public function getPresenter(): Presenter
|
2024-02-08 23:09:51 +01:00
|
|
|
{
|
2024-02-09 23:22:49 +01:00
|
|
|
return app(DatePresenter::class);
|
2024-02-08 23:09:51 +01:00
|
|
|
}
|
2024-02-16 14:18:16 +01:00
|
|
|
|
2024-02-16 14:32:16 +01:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2024-02-16 14:18:16 +01:00
|
|
|
public function afterRegistration(Form $form, Participant $participant, array $input): void
|
|
|
|
{
|
|
|
|
}
|
2023-12-30 01:00:58 +01:00
|
|
|
}
|