Support oft parent groups
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
|
||||
use App\Casts\AmountCast;
|
||||
use App\Enumerations\EatingHabit;
|
||||
use App\Enumerations\ParticipantGroupType;
|
||||
use App\Enumerations\ParticipationFeeType;
|
||||
use App\RelationModels\EventParticipationFee;
|
||||
use App\RelationModels\EventPaymentMethods;
|
||||
@@ -13,6 +14,7 @@ use DateTime;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* @property string $tenant
|
||||
@@ -50,6 +52,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
* @property boolean $short_registration
|
||||
* @property boolean $swimming_permission_required
|
||||
* @property string|null $invoice_key
|
||||
* @property string $participant_group_type
|
||||
*/
|
||||
class Event extends InstancedModel
|
||||
{
|
||||
@@ -101,6 +104,7 @@ class Event extends InstancedModel
|
||||
'swimming_permission_required',
|
||||
|
||||
'invoice_key',
|
||||
'participant_group_type',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@@ -186,6 +190,33 @@ class Event extends InstancedModel
|
||||
return $this->belongsToMany(Tenant::class, 'event_local_groups', 'event_id', 'local_group_id');
|
||||
}
|
||||
|
||||
public function participantGroupType() : ParticipantGroupType {
|
||||
return ParticipantGroupType::fromStored($this->participant_group_type);
|
||||
}
|
||||
|
||||
public function asksForParentGroup() : bool {
|
||||
return $this->participantGroupType() === ParticipantGroupType::ParentGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Was bei der Anmeldung zur Auswahl steht: die teilnehmenden Local Groups oder -- fragt die Veranstaltung nach der
|
||||
* Parent Group -- deren Parent Groups, jede nur einmal (alphabetisch, „Ohne Zuordnung" zuletzt).
|
||||
* Einzige Quelle für Anzeige und Prüfung der Auswahl.
|
||||
*
|
||||
* @return Collection<int, Tenant>|Collection<int, ParentGroup>
|
||||
*/
|
||||
public function participantGroupOptions() : Collection {
|
||||
$localGroups = $this->localGroups()->with('parentGroup')->get();
|
||||
|
||||
if (!$this->asksForParentGroup()) {
|
||||
return $localGroups;
|
||||
}
|
||||
|
||||
return ParentGroup::sortForDisplay(
|
||||
$localGroups->pluck('parentGroup')->filter()->unique('id')
|
||||
);
|
||||
}
|
||||
|
||||
public function eatingHabits() : BelongsToMany{
|
||||
return $this->belongsToMany(EatingHabit::class, 'event_allowed_eating_habits', 'event_id', 'eating_habit_id');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user