Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
AngelType
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
4 / 4
7
100.00% covered (success)
100.00%
1 / 1
 neededBy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 shiftEntries
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 userAngelTypes
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 hasContactInfo
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 boot
n/a
0 / 0
n/a
0 / 0
1
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Models;
6
7use Engelsystem\Models\Shifts\NeededAngelType;
8use Engelsystem\Models\Shifts\ShiftEntry;
9use Engelsystem\Models\User\User;
10use Illuminate\Database\Eloquent\Builder;
11use Illuminate\Database\Eloquent\Collection;
12use Illuminate\Database\Eloquent\Factories\HasFactory;
13use Illuminate\Database\Eloquent\Relations\BelongsToMany;
14use Illuminate\Database\Eloquent\Relations\HasMany;
15use Illuminate\Database\Query\Builder as QueryBuilder;
16
17/**
18 * @property int                               $id
19 * @property string                            $name
20 * @property string                            $description
21 * @property string                            $contact_name
22 * @property string                            $contact_dect
23 * @property string                            $contact_email
24 * @property boolean                           $restricted # If users need an introduction
25 * @property boolean                           $requires_driver_license # If users must have a driver license
26 * @property boolean                           $requires_ifsg_certificate # If users must have a ifsg certificate
27 * @property boolean                           $shift_self_signup # Users can sign up for shifts
28 * @property boolean                           $show_on_dashboard # Show on public dashboard
29 * @property boolean                           $hide_register # Hide from registration page
30 * @property boolean                           $hide_on_shift_view # Hide from shift page
31 *
32 * @property-read Collection|NeededAngelType[] $neededBy
33 * @property-read UserAngelType                $pivot
34 * @property-read Collection|ShiftEntry[]      $shiftEntries
35 * @property-read Collection|User[]            $userAngelTypes
36 *
37 * @method static QueryBuilder|AngelType[] whereId($value)
38 * @method static QueryBuilder|AngelType[] whereName($value)
39 * @method static QueryBuilder|AngelType[] whereDescription($value)
40 * @method static QueryBuilder|AngelType[] whereContactName($value)
41 * @method static QueryBuilder|AngelType[] whereContactDect($value)
42 * @method static QueryBuilder|AngelType[] whereContactEmail($value)
43 * @method static QueryBuilder|AngelType[] whereRestricted($value)
44 * @method static QueryBuilder|AngelType[] whereRequiresDriverLicense($value)
45 * @method static QueryBuilder|AngelType[] whereRequiresIfsgCertificate($value)
46 * @method static QueryBuilder|AngelType[] whereNoSelfSignup($value)
47 * @method static QueryBuilder|AngelType[] whereShowOnDashboard($value)
48 * @method static QueryBuilder|AngelType[] whereHideRegister($value)
49 */
50class AngelType extends BaseModel
51{
52    use HasFactory;
53
54    /** @var array Default attributes */
55    protected $attributes = [ // phpcs:ignore
56        'description'               => '',
57        'contact_name'              => '',
58        'contact_dect'              => '',
59        'contact_email'             => '',
60        'restricted'                => false,
61        'requires_driver_license'   => false,
62        'requires_ifsg_certificate' => false,
63        'shift_self_signup'         => false,
64        'show_on_dashboard'         => true,
65        'hide_register'             => false,
66        'hide_on_shift_view'        => false,
67    ];
68
69    /**
70     * The attributes that are mass assignable.
71     *
72     * @var array<string>
73     */
74    protected $fillable = [ // phpcs:ignore
75        'name',
76        'description',
77
78        'contact_name',
79        'contact_dect',
80        'contact_email',
81
82        'restricted',
83        'requires_driver_license',
84        'requires_ifsg_certificate',
85        'shift_self_signup',
86        'show_on_dashboard',
87        'hide_register',
88        'hide_on_shift_view',
89    ];
90
91    /** @var array<string, string> */
92    protected $casts = [ // phpcs:ignore
93        'restricted'                => 'boolean',
94        'requires_driver_license'   => 'boolean',
95        'requires_ifsg_certificate' => 'boolean',
96        'shift_self_signup'         => 'boolean',
97        'show_on_dashboard'         => 'boolean',
98        'hide_register'             => 'boolean',
99        'hide_on_shift_view'        => 'boolean',
100    ];
101
102    public function neededBy(): HasMany
103    {
104        return $this->hasMany(NeededAngelType::class);
105    }
106
107    public function shiftEntries(): HasMany
108    {
109        return $this->hasMany(ShiftEntry::class);
110    }
111
112    public function userAngelTypes(): BelongsToMany
113    {
114        return $this
115            ->belongsToMany(User::class, 'user_angel_type')
116            ->using(UserAngelType::class)
117            ->withPivot(UserAngelType::getPivotAttributes());
118    }
119
120    public function hasContactInfo(): bool
121    {
122        return !empty($this->contact_name)
123            || !empty($this->contact_dect)
124            || !empty($this->contact_email);
125    }
126
127    /**
128     * @codeCoverageIgnore For some reasons parent::boot get s ignored here 0o
129     */
130    protected static function boot(): void
131    {
132        parent::boot();
133        static::addGlobalScope('order', fn(Builder $builder) => $builder->orderBy('name'));
134    }
135}