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 isApplicant(Tournament $tournament) {
20 foreach ($tournament->applications as $applicant) {
21 if ($applicant->user_id == $this->id) {
28 public function isDeniedApplicant(Tournament $tournament) {
29 foreach ($tournament->applications as $applicant) {
30 if ($applicant->user_id == $this->id) {
31 return $applicant->denied;
37 public function isParticipant(Tournament $tournament) {
38 foreach ($tournament->participants as $participant) {
39 if ($participant->user_id == $this->id) {
46 public function isRunner(Tournament $tournament) {
47 foreach ($tournament->participants as $participant) {
48 if ($participant->user_id == $this->id) {
49 return in_array('runner', $participant->roles);
55 public function isTournamentAdmin(Tournament $tournament) {
56 foreach ($tournament->participants as $participant) {
57 if ($participant->user_id == $this->id) {
58 return in_array('admin', $participant->roles);
64 public function isTournamentCrew(Tournament $tournament) {
65 return $this->isTournamentAdmin($tournament) || $this->isTournamentMonitor($tournament);
68 public function isTournamentMonitor(Tournament $tournament) {
69 foreach ($tournament->participants as $participant) {
70 if ($participant->user_id == $this->id) {
71 return in_array('monitor', $participant->roles);
77 public function hasFinished(Round $round) {
78 foreach ($round->results as $result) {
79 if ($result->user_id != $this->id) continue;
80 return $result->has_finished;
86 public function participation() {
87 return $this->hasMany(Participant::class);
90 public function results() {
91 return $this->hasMany(Result::class);
94 public function rounds() {
95 return $this->belongsToMany(Round::class, 'results');
98 public function tournaments() {
99 return $this->belongsToMany(Tournament::class, 'participants');
103 public function round_first() {
104 return $this->rounds()
105 ->where('locked', true)
106 ->where('no_record', false)
107 ->wherePivot('forfeit', false)
108 ->wherePivot('placement', 1);
111 public function round_second() {
112 return $this->rounds()
113 ->where('locked', true)
114 ->where('no_record', false)
115 ->wherePivot('forfeit', false)
116 ->wherePivot('placement', 2);
119 public function round_third() {
120 return $this->rounds()
121 ->where('locked', true)
122 ->where('no_record', false)
123 ->wherePivot('forfeit', false)
124 ->wherePivot('placement', 3);
127 public function tournament_first() {
128 return $this->tournaments()
129 ->where('locked', true)
130 ->where('no_record', false)
131 ->wherePivot('placement', 1);
134 public function tournament_second() {
135 return $this->tournaments()
136 ->where('locked', true)
137 ->where('no_record', false)
138 ->wherePivot('placement', 2);
141 public function tournament_third() {
142 return $this->tournaments()
143 ->where('locked', true)
144 ->where('no_record', false)
145 ->wherePivot('placement', 3);
150 * The attributes that are mass assignable.
154 protected $fillable = [
168 * The attributes that should be hidden for serialization.
172 protected $hidden = [
180 * The attributes that should be cast.
186 'username' => 'string',
187 'discriminator' => 'string',
189 'avatar' => 'string',
190 'verified' => 'boolean',
191 'locale' => 'string',
192 'mfa_enabled' => 'boolean',
193 'refresh_token' => 'encrypted',