1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Xoco70\KendoTournaments\Models; |
4
|
|
|
|
5
|
|
|
use App\User; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
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
|
|
|
|
16
|
|
|
protected $table = 'competitor'; |
17
|
|
|
public $timestamps = true; |
18
|
|
|
protected $fillable = [ |
19
|
|
|
"tournament_category_id", |
20
|
|
|
"user_id", |
21
|
|
|
"confirmed", |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Get the Competitor's Championship |
27
|
|
|
* @param $ctId |
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 = Competitor::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
|
|
|
* @param $ctuId |
43
|
|
|
* @return mixed |
44
|
|
|
*/ |
45
|
|
|
public function category($ctuId) |
46
|
|
|
{ |
47
|
|
|
$championship = $this->championship($ctuId); |
48
|
|
|
$categoryId = $championship->category_id; |
49
|
|
|
$cat = Category::find($categoryId); |
50
|
|
|
return $cat; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the tournament where Competitors is competing |
56
|
|
|
* @param $ctuId |
57
|
|
|
* @return mixed |
58
|
|
|
*/ |
59
|
|
|
public function tournament($ctuId) |
60
|
|
|
{ |
61
|
|
|
$tc = $this->championship($ctuId); |
62
|
|
|
$tourmanentId = $tc->tournament_id; |
63
|
|
|
$tour = Tournament::findOrNew($tourmanentId); |
64
|
|
|
return $tour; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get User from Competitor |
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
|
|
public function user() |
72
|
|
|
{ |
73
|
|
|
return $this->belongsTo(User::class); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
public function rounds() |
78
|
|
|
{ |
79
|
|
|
return $this->belongsToMany(Round::class,'round_competitor'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|