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;
11 class User extends Authenticatable
13 use HasApiTokens, HasFactory, Notifiable;
15 public function isAdmin() {
16 return $this->role === 'admin';
19 public function isParticipant(Tournament $tournament) {
20 foreach ($tournament->participants as $participant) {
21 if ($participant->user_id == $this->id) {
28 public function isRunner(Tournament $tournament) {
29 foreach ($tournament->participants as $participant) {
30 if ($participant->user_id == $this->id) {
31 return in_array('runner', $participant->roles);
37 public function isTournamentAdmin(Tournament $tournament) {
38 foreach ($tournament->participants as $participant) {
39 if ($participant->user_id == $this->id) {
40 return in_array('admin', $participant->roles);
46 public function isTournamentCrew(Tournament $tournament) {
47 return $this->isTournamentAdmin($tournament) || $this->isTournamentMonitor($tournament);
50 public function isTournamentMonitor(Tournament $tournament) {
51 foreach ($tournament->participants as $participant) {
52 if ($participant->user_id == $this->id) {
53 return in_array('monitor', $participant->roles);
59 public function hasFinished(Round $round) {
60 foreach ($round->results as $result) {
61 if ($result->user_id != $this->id) continue;
62 return $result->has_finished;
68 public function participation() {
69 return $this->hasMany(Participant::class);
72 public function results() {
73 return $this->hasMany(Result::class);
76 public function rounds() {
77 return $this->belongsToMany(Round::class, 'results');
80 public function tournaments() {
81 return $this->belongsToMany(Tournament::class, 'participants');
85 public function round_first() {
86 return $this->rounds()
87 ->where('locked', true)
88 ->where('no_record', false)
89 ->wherePivot('forfeit', false)
90 ->wherePivot('placement', 1);
93 public function round_second() {
94 return $this->rounds()
95 ->where('locked', true)
96 ->where('no_record', false)
97 ->wherePivot('forfeit', false)
98 ->wherePivot('placement', 2);
101 public function round_third() {
102 return $this->rounds()
103 ->where('locked', true)
104 ->where('no_record', false)
105 ->wherePivot('forfeit', false)
106 ->wherePivot('placement', 3);
109 public function tournament_first() {
110 return $this->tournaments()
111 ->where('locked', true)
112 ->where('no_record', false)
113 ->wherePivot('placement', 1);
116 public function tournament_second() {
117 return $this->tournaments()
118 ->where('locked', true)
119 ->where('no_record', false)
120 ->wherePivot('placement', 2);
123 public function tournament_third() {
124 return $this->tournaments()
125 ->where('locked', true)
126 ->where('no_record', false)
127 ->wherePivot('placement', 3);
132 * The attributes that are mass assignable.
136 protected $fillable = [
150 * The attributes that should be hidden for serialization.
154 protected $hidden = [
162 * The attributes that should be cast.
168 'username' => 'string',
169 'discriminator' => 'string',
171 'avatar' => 'string',
172 'verified' => 'boolean',
173 'locale' => 'string',
174 'mfa_enabled' => 'boolean',
175 'refresh_token' => 'encrypted',