]> git.localhorst.tv Git - alttp.git/blob - app/Models/User.php
allow admins to lock/unlock rounds
[alttp.git] / app / Models / User.php
1 <?php
2
3 namespace App\Models;
4
5 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 use Illuminate\Foundation\Auth\User as Authenticatable;
7 use Illuminate\Notifications\Notifiable;
8 use Laravel\Sanctum\HasApiTokens;
9
10
11 class User extends Authenticatable
12 {
13         use HasApiTokens, HasFactory, Notifiable;
14
15         public function isParticipant(Tournament $tournament) {
16                 foreach ($tournament->participants as $participant) {
17                         if ($participant->user_id == $this->id) {
18                                 return true;
19                         }
20                 }
21                 return false;
22         }
23
24         public function isRunner(Tournament $tournament) {
25                 foreach ($tournament->participants as $participant) {
26                         if ($participant->user_id == $this->id) {
27                                 return in_array('runner', $participant->roles);
28                         }
29                 }
30                 return false;
31         }
32
33         public function isTournamentAdmin(Tournament $tournament) {
34                 foreach ($tournament->participants as $participant) {
35                         if ($participant->user_id == $this->id) {
36                                 return in_array('admin', $participant->roles);
37                         }
38                 }
39                 return false;
40         }
41
42         public function participation() {
43                 return $this->hasMany(Participant::class);
44         }
45
46         /**
47          * The attributes that are mass assignable.
48          *
49          * @var string[]
50          */
51         protected $fillable = [
52                 'id',
53                 'username',
54                 'discriminator',
55                 'email',
56                 'avatar',
57                 'verified',
58                 'locale',
59                 'mfa_enabled',
60                 'refresh_token',
61                 'role',
62         ];
63
64         /**
65          * The attributes that should be hidden for serialization.
66          *
67          * @var array
68          */
69         protected $hidden = [
70                 'email',
71                 'mfa_enabled',
72                 'refresh_token',
73                 'remember_token',
74         ];
75
76         /**
77          * The attributes that should be cast.
78          *
79          * @var array
80          */
81         protected $casts = [
82                 'id' => 'string',
83                 'username' => 'string',
84                 'discriminator' => 'string',
85                 'email' => 'string',
86                 'avatar' => 'string',
87                 'verified' => 'boolean',
88                 'locale' => 'string',
89                 'mfa_enabled' => 'boolean',
90                 'refresh_token' => 'encrypted',
91         ];
92 }