2024-02-06 01:45:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Models;
|
|
|
|
|
2024-03-14 23:54:41 +01:00
|
|
|
use App\Form\Data\FieldCollection;
|
2024-03-15 01:52:27 +01:00
|
|
|
use App\Form\Data\FormConfigData;
|
2024-03-15 00:28:57 +01:00
|
|
|
use App\Form\Mails\ConfirmRegistrationMail;
|
2024-03-08 02:19:07 +01:00
|
|
|
use App\Form\Scopes\ParticipantFilterScope;
|
2024-07-02 22:55:37 +02:00
|
|
|
use App\Member\Member;
|
|
|
|
use App\Prevention\Contracts\Preventable;
|
2024-09-22 17:32:29 +02:00
|
|
|
use Database\Factories\Form\Models\ParticipantFactory;
|
2024-03-08 02:19:07 +01:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2024-02-06 01:45:25 +01:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2024-02-08 21:04:00 +01:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2024-03-08 02:19:07 +01:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2024-03-15 00:28:57 +01:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
2024-12-11 22:32:23 +01:00
|
|
|
use Laravel\Scout\Searchable;
|
2024-07-02 22:55:37 +02:00
|
|
|
use stdClass;
|
2024-02-06 01:45:25 +01:00
|
|
|
|
2024-07-02 22:55:37 +02:00
|
|
|
class Participant extends Model implements Preventable
|
2024-02-06 01:45:25 +01:00
|
|
|
{
|
2024-09-22 17:32:29 +02:00
|
|
|
|
|
|
|
/** @use HasFactory<ParticipantFactory> */
|
2024-02-06 01:45:25 +01:00
|
|
|
use HasFactory;
|
2024-12-11 22:32:23 +01:00
|
|
|
use Searchable;
|
2024-02-06 01:45:25 +01:00
|
|
|
|
|
|
|
public $guarded = [];
|
|
|
|
|
|
|
|
public $casts = [
|
|
|
|
'data' => 'json',
|
2024-07-02 22:55:37 +02:00
|
|
|
'last_remembered_at' => 'datetime',
|
2024-02-06 01:45:25 +01:00
|
|
|
];
|
2024-02-08 21:04:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return BelongsTo<Form, self>
|
|
|
|
*/
|
|
|
|
public function form(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Form::class);
|
|
|
|
}
|
2024-03-08 02:19:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return HasMany<self>
|
|
|
|
*/
|
|
|
|
public function children(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(self::class, 'parent_id');
|
|
|
|
}
|
|
|
|
|
2024-07-02 23:00:09 +02:00
|
|
|
/**
|
|
|
|
* @return BelongsTo<Member, self>
|
|
|
|
*/
|
2024-07-02 22:55:37 +02:00
|
|
|
public function member(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Member::class);
|
|
|
|
}
|
|
|
|
|
2024-03-14 23:54:41 +01:00
|
|
|
public function getFields(): FieldCollection
|
|
|
|
{
|
|
|
|
return FieldCollection::fromRequest($this->form, $this->data);
|
|
|
|
}
|
2024-03-15 00:28:57 +01:00
|
|
|
|
2024-03-15 01:52:27 +01:00
|
|
|
public function getConfig(): FormConfigData
|
|
|
|
{
|
|
|
|
return tap($this->form->config, function ($config) {
|
|
|
|
$config->sections->each(function ($section) {
|
|
|
|
$section->fields->each(function ($field) {
|
|
|
|
$field->value = $this->getFields()->find($field)->value;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-03-15 00:28:57 +01:00
|
|
|
public function sendConfirmationMail(): void
|
|
|
|
{
|
|
|
|
if (!$this->getFields()->getMailRecipient()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-07-02 22:55:37 +02:00
|
|
|
Mail::to($this->getMailRecipient())->queue(new ConfirmRegistrationMail($this));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function preventableLayout(): string
|
|
|
|
{
|
|
|
|
return 'mail.prevention.prevention-remember-participant';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function preventions(): array
|
|
|
|
{
|
|
|
|
return $this->member?->preventions($this->form->from) ?: [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMailRecipient(): stdClass
|
|
|
|
{
|
|
|
|
return $this->getFields()->getMailRecipient();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function preventableSubject(): string
|
|
|
|
{
|
|
|
|
return 'Nachweise erforderlich für deine Anmeldung zu ' . $this->form->name;
|
2024-03-15 00:28:57 +01:00
|
|
|
}
|
2024-12-11 22:32:23 +01:00
|
|
|
|
2024-12-12 00:36:56 +01:00
|
|
|
public function searchableAs(): string
|
2024-12-11 22:32:23 +01:00
|
|
|
{
|
|
|
|
return $this->form->participantsSearchableAs();
|
|
|
|
}
|
|
|
|
|
2024-12-12 00:36:56 +01:00
|
|
|
/** @return array<string, mixed> */
|
2024-12-11 22:32:23 +01:00
|
|
|
public function toSearchableArray(): array
|
|
|
|
{
|
2024-12-12 00:30:59 +01:00
|
|
|
return [...$this->data, 'parent-id' => $this->parent_id];
|
2024-12-11 22:32:23 +01:00
|
|
|
}
|
2024-02-06 01:45:25 +01:00
|
|
|
}
|