1 | <?php |
||
2 | |||
3 | namespace Xoco70\LaravelTournaments\Models; |
||
4 | |||
5 | use Illuminate\Database\Eloquent\Model; |
||
6 | use Illuminate\Http\Request; |
||
7 | |||
8 | class ChampionshipSettings extends Model |
||
9 | { |
||
10 | protected $dates = ['created_at', 'updated_at']; |
||
11 | |||
12 | protected $table = 'championship_settings'; |
||
13 | public $timestamps = true; |
||
14 | protected $guarded = ['id']; |
||
15 | |||
16 | const MIN_COMPETITORS_BY_AREA = 2; |
||
17 | const PLAY_OFF = 0; |
||
18 | const SINGLE_ELIMINATION = 1; |
||
19 | const PRELIMINARY_GROUP_SIZE = [3 => 3, 4 => 4, 5 => 5]; |
||
20 | const PRELIMINARY_WINNERS = [1 => 1]; |
||
21 | const // , 2 => 2, 3 => 3 |
||
0 ignored issues
–
show
|
|||
22 | TEAM_SIZE = [2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10]; |
||
23 | const TEAM_RESERVE = [1 => 1, 2 => 2, 3 => 3, 4 => 4]; |
||
24 | const LIMIT_BY_ENTITY = [0 => '-', 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10]; |
||
25 | const DEFAULT_SETTINGS = [ |
||
26 | 'fightingAreas' => '1', |
||
27 | 'fightDuration' => '05:00', |
||
28 | 'hasPreliminary' => '1', |
||
29 | 'preliminaryGroupSize' => '3', |
||
30 | 'preliminaryDuration' => '05:00', |
||
31 | 'preliminaryWinner' => '1', |
||
32 | 'hasEncho' => '1', |
||
33 | 'enchoQty' => '1', |
||
34 | 'enchoDuration' => '0', |
||
35 | 'hasHantei' => '0', |
||
36 | 'hanteiLimit' => '0', // 1/2 Finals |
||
37 | 'enchoGoldPoint' => '0', // Step where Encho has no more time limit |
||
38 | 'limitByEntity' => '4', |
||
39 | 'cost' => '', |
||
40 | 'treeType' => '1', |
||
41 | 'seedQuantity' => '4', |
||
42 | |||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * A Setting belongs to a Championship. |
||
47 | * |
||
48 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
49 | */ |
||
50 | public function championship() |
||
51 | { |
||
52 | return $this->belongsTo(Championship::class); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param Request $request |
||
57 | * @param Championship $championship |
||
58 | * |
||
59 | * @return ChampionshipSettings |
||
60 | */ |
||
61 | public static function createOrUpdate(Request $request, Championship $championship): self |
||
62 | { |
||
63 | $request->request->add(['championship_id' => $championship->id]); |
||
64 | $arrSettings = $request->except('_token', 'numFighters', 'isTeam'); |
||
65 | $settings = static::where(['championship_id' => $championship->id])->first(); |
||
66 | if ($settings == null) { |
||
67 | $settings = new self(); |
||
68 | } |
||
69 | $settings->fill($arrSettings); |
||
70 | |||
71 | $settings->save(); |
||
72 | |||
73 | return $settings; |
||
74 | } |
||
75 | } |
||
76 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.