1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Xoco70\KendoTournaments\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
7
|
|
|
use Illuminate\Foundation\Auth\User; |
8
|
|
|
use Illuminate\Support\Collection; |
9
|
|
|
|
10
|
|
|
class Competitor extends Model |
11
|
|
|
{ |
12
|
|
|
use SoftDeletes; |
13
|
|
|
protected $DATES = ['created_at', 'updated_at', 'deleted_at']; |
14
|
|
|
|
15
|
|
|
protected $table = 'competitor'; |
16
|
|
|
public $timestamps = true; |
17
|
|
|
protected $fillable = [ |
18
|
|
|
'tournament_category_id', |
19
|
|
|
'user_id', |
20
|
|
|
'confirmed', |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Get the Competitor's Championship. |
25
|
|
|
* |
26
|
|
|
* @param $ctId |
27
|
|
|
* |
28
|
|
|
* @return Collection |
29
|
|
|
*/ |
30
|
|
|
public function championship($ctId) |
31
|
|
|
{ |
32
|
|
|
//TODO Surely I could Refactor it to Eloquent - Should Debug that. $ctId <> $championshipId ??? |
33
|
|
|
$competitor = self::where('championship_id', $ctId)->first(); |
34
|
|
|
$championshipId = $competitor->championship_id; |
35
|
|
|
$championship = Championship::find($championshipId); |
36
|
|
|
|
37
|
|
|
return $championship; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Not sure I use it, I could use $competitor->championship->category. |
42
|
|
|
* |
43
|
|
|
* @param $ctuId |
44
|
|
|
* |
45
|
|
|
* @return mixed |
46
|
|
|
*/ |
47
|
|
|
public function category($ctuId) |
48
|
|
|
{ |
49
|
|
|
$championship = $this->championship($ctuId); |
50
|
|
|
$categoryId = $championship->category_id; |
51
|
|
|
$cat = Category::find($categoryId); |
52
|
|
|
|
53
|
|
|
return $cat; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the tournament where Competitors is competing. |
58
|
|
|
* |
59
|
|
|
* @param $ctuId |
60
|
|
|
* |
61
|
|
|
* @return mixed |
62
|
|
|
*/ |
63
|
|
|
public function tournament($ctuId) |
64
|
|
|
{ |
65
|
|
|
$tc = $this->championship($ctuId); |
66
|
|
|
$tourmanentId = $tc->tournament_id; |
67
|
|
|
$tour = Tournament::findOrNew($tourmanentId); |
68
|
|
|
|
69
|
|
|
return $tour; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get User from Competitor. |
74
|
|
|
* |
75
|
|
|
* @return mixed |
76
|
|
|
*/ |
77
|
|
|
public function user() |
78
|
|
|
{ |
79
|
|
|
return $this->belongsTo(User::class); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function fightersGroups() |
83
|
|
|
{ |
84
|
|
|
return $this->belongsToMany(FightersGroup::class, 'fighters_group_competitor')->withTimestamps(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getName() |
88
|
|
|
{ |
89
|
|
|
if ($this == null) return "BYE"; |
90
|
|
|
if ($this->user == null) return "BYE"; |
91
|
|
|
return $this->user->name; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|