-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatch.php
More file actions
157 lines (148 loc) · 5.37 KB
/
Match.php
File metadata and controls
157 lines (148 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
Class Match
{
private $id;
private $identifier;
private $loser_id;
private $player1_id;
private $player2_id;
private $round;
private $title;
private $state;
private $tournament_id;
private $underway_at;
private $winner_id;
private $player1;
private $player2;
private $player1_score;
private $player2_score;
private $is_score_valid;
private $scores;
/**
* Creates a new match Object
* @param array $matchArray An associative array from the tournamentRip
*/
function __construct($matchArray){
$this->round = arrayExtract($matchArray, "round", "int");
$this->id = arrayExtract($matchArray, "id", "int");
$this->identifier = arrayExtract($matchArray, "identifier", "int");
$this->loser_id = arrayExtract($matchArray, "loser_id", "int");
$this->state = arrayExtract($matchArray, "state", "string");
$this->tournament_id = arrayExtract($matchArray, "tournament_id", "int");
$this->underway_at = arrayExtract($matchArray, "underway_at", "string");
$this->winner_id = arrayExtract($matchArray, "winner_id", "int");
$this->player1 = arrayExtract($matchArray, "player1", "array");
$this->player2 = arrayExtract($matchArray, "player2", "array");
$this->player1_id = arrayExtract($this->player1, "id", "int");
$this->player2_id = arrayExtract($this->player2, "id", "int");
$this->scores = arrayExtract($matchArray, "scores", "array");
//Empty Score brackets are possible
if (sizeof($this->scores) == 2)
{
$this->player1_score = arrayExtract($this->scores, 0, "int");
$this->player2_score = arrayExtract($this->scores, 1, "int");
}
else
{
$this->player1_score = 0;
$this->player2_score = 0;
}
//Verify Scores are in desired range
if(($this->player1_score >= 0 && $this->player1_score <=2) &&
($this->player2_score >= 0 && $this->player2_score <=2) &&
($this->player1_score > $this->player2_score || $this->player1_score < $this->player2_score))
$this->is_score_valid = true;
else
$this->is_score_valid = false;
}
function setTitle(string $title){
$this->title = $title;
}
/**
* Returns the value of a specific index, much like JSON
* @param string $indexString The value which is indexed
* @throws OutOfBoundsException if index is invalid
*/
public function index($indexString) {
switch ($indexString) {
case "id":
return $this->id;
break;
case "identifier":
return $this->identifier;
break;
case "title":
return $this->title;
break;
case "loser_id":
return $this->loser_id;
break;
case "player1":
return $this->player1;
break;
case "player2":
return $this->player2;
break;
case "player1_id":
return $this->player1_id;
break;
case "player2_id":
return $this->player2_id;
break;
case "round":
return $this->round;
break;
case "title":
return $this->title;
break;
case "state":
return $this->state;
break;
case "tournament_id":
return $this->tournament_id;
break;
case "underway_at":
return $this->underway_at;
break;
case "winner_id":
return $this->winner_id;
break;
case "scores":
return $this->scores;
break;
case "player1_score":
return $this->player1_score;
break;
case "player2_score":
return $this->player2_score;
break;
case "is_score_valid":
return$this->is_score_valid;
break;
default:
throw new OutOfBoundsException($indexString." is not a valid index of Match!");
break;
}
}
public function toArray(){
return array(
"id" => $this->id,
"identifier" => $this->identifier,
"loser_id" => $this->loser_id,
"player1_id" => $this->player1_id,
"player2_id" => $this->player2_id,
"round" => $this->round,
"title" => $this->title,
"state" => $this->state,
"tournament_id" => $this->tournament_id,
"underway_at" => $this->underway_at,
"winner_id" => $this->winner_id,
"player1" => $this->player1,
"player2" => $this->player2,
"player1_score" => $this->player1_score,
"player2_score" => $this->player2_score,
"is_score_valid" => $this->is_score_valid,
"scores" => $this->scores
);
}
}