53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\RelationModels;
|
|
|
|
use App\Casts\AmountCast;
|
|
use App\Enumerations\ParticipationFeeType;
|
|
use App\Enumerations\ParticipationType;
|
|
use App\Models\Tenant;
|
|
use App\Scopes\CommonModel;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class EventParticipationFee extends CommonModel
|
|
{
|
|
protected $table = 'event_participation_fees';
|
|
|
|
protected $fillable = ['tenant', 'type', 'name', 'description', 'amount_standard', 'amount_reduced', 'amount_solidarity', 'active'];
|
|
protected $casts = [
|
|
'amount_standard' => AmountCast::class,
|
|
'amount_reduced' => AmountCast::class,
|
|
'amount_solidarity' => AmountCast::class,
|
|
|
|
];
|
|
|
|
/** Beitragsstufen in Anzeigereihenfolge; die Schlüssel sind die Spaltensuffixe von `amount_*`. */
|
|
public const array FEE_TYPE_LABELS = [
|
|
'standard' => 'Standardbeitrag',
|
|
'reduced' => 'Reduzierter Beitrag',
|
|
'solidarity' => 'Solidaritätsbeitrag',
|
|
];
|
|
|
|
/**
|
|
* Die Beitragsstufen, die für diese Teilnahmegruppe tatsächlich hinterlegt sind. Den Standardbeitrag gibt es
|
|
* immer, reduzierter und Solidaritätsbeitrag sind optional. Nur für diese Stufen liefert
|
|
* `EventResource::calculateAmount()` einen Betrag.
|
|
*
|
|
* @return array<int, string>
|
|
*/
|
|
public function availableFeeTypes() : array {
|
|
return array_values(array_filter(
|
|
array_keys(self::FEE_TYPE_LABELS),
|
|
fn (string $feeType) => $this->{'amount_' . $feeType} !== null
|
|
));
|
|
}
|
|
|
|
public function tenant() : BelongsTo {
|
|
return $this->belongsTo(Tenant::class, 'tenant', 'slug');
|
|
}
|
|
|
|
public function type() : BelongsTo {
|
|
return $this->belongsTo(ParticipationType::class, 'type', 'slug');
|
|
}
|
|
}
|