]> git.localhorst.tv Git - alttp.git/blob - app/Models/Result.php
show placements on user profile
[alttp.git] / app / Models / Result.php
1 <?php
2
3 namespace App\Models;
4
5 use App\Events\ResultChanged;
6 use Illuminate\Database\Eloquent\Factories\HasFactory;
7 use Illuminate\Database\Eloquent\Model;
8
9 class Result extends Model
10 {
11         use HasFactory;
12
13
14         public function updateResult($time, $forfeit) {
15                 $this->time = $time;
16                 $this->forfeit = $forfeit;
17                 $this->save();
18                 if ($this->wasChanged()) {
19                         ResultChanged::dispatch($this);
20                 }
21         }
22
23         public function updatePlacement($score, $placement) {
24                 $this->score = $score;
25                 $this->placement = $placement;
26                 $this->save();
27                 if ($this->wasChanged()) {
28                         ResultChanged::dispatch($this);
29                 }
30         }
31
32
33         public function round() {
34                 return $this->belongsTo(Round::class);
35         }
36
37         public function participant() {
38                 return $this->belongsTo(Participant::class);
39         }
40
41         public function getHasFinishedAttribute() {
42                 return $this->time > 0 || $this->forfeit;
43         }
44
45
46         protected $appends = [
47                 'has_finished',
48         ];
49
50         protected $fillable = [
51                 'forfeit',
52                 'round_id',
53                 'time',
54                 'user_id',
55         ];
56
57 }