1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @file |
4
|
|
|
* The main sportsdb class. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace TheSportsDb; |
8
|
|
|
|
9
|
|
|
use TheSportsDb\Entity\EntityManagerConsumerInterface; |
10
|
|
|
use TheSportsDb\Entity\EntityManagerConsumerTrait; |
11
|
|
|
use TheSportsDb\Entity\EntityManagerInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Main API class for TheSportsDb. |
15
|
|
|
* |
16
|
|
|
* @author Jelle Sebreghts |
17
|
|
|
*/ |
18
|
|
|
class TheSportsDb implements EntityManagerConsumerInterface { |
19
|
|
|
|
20
|
|
|
use EntityManagerConsumerTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Creates a new TheSportsDb instance |
24
|
|
|
*/ |
25
|
|
|
public function __construct(EntityManagerInterface $entityManager = NULL) { |
26
|
|
|
if ($entityManager instanceof EntityManagerInterface) { |
27
|
|
|
$this->entityManager = $entityManager; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Gets all sports. |
33
|
|
|
* |
34
|
|
|
* @return \TheSportsDb\Entity\SportInterface[] |
35
|
|
|
* The sports. |
36
|
|
|
*/ |
37
|
|
|
public function getSports() { |
38
|
|
|
return $this->entityManager->repository('sport')->all(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get a sport by name. |
43
|
|
|
* |
44
|
|
|
* @param string $name |
45
|
|
|
* The sport name. |
46
|
|
|
* |
47
|
|
|
* @return \TheSportsDb\Entity\SportInterface |
48
|
|
|
* The sport. |
49
|
|
|
*/ |
50
|
|
|
public function getSport($name) { |
51
|
|
|
return $this->entityManager->repository('sport')->byId($name); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Gets all leagues. |
56
|
|
|
* |
57
|
|
|
* @return \TheSportsDb\Entity\LeagueInterface[] |
58
|
|
|
* The leagues. |
59
|
|
|
*/ |
60
|
|
|
public function getLeagues() { |
61
|
|
|
return $this->entityManager->repository('league')->all(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get a league by id. |
66
|
|
|
* |
67
|
|
|
* @param int $leagueId |
68
|
|
|
* The league id. |
69
|
|
|
* |
70
|
|
|
* @return \TheSportsDb\Entity\LeagueInterface |
71
|
|
|
* The league. |
72
|
|
|
*/ |
73
|
|
|
public function getLeague($leagueId) { |
74
|
|
|
return $this->entityManager->repository('league')->byId($leagueId); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Gets all leagues by country. |
79
|
|
|
* |
80
|
|
|
* @param string $country |
81
|
|
|
* The country of which to get the leagues. |
82
|
|
|
* |
83
|
|
|
* @return \TheSportsDb\Entity\LeagueInterface[] |
84
|
|
|
* The leagues. |
85
|
|
|
*/ |
86
|
|
|
public function getLeaguesByCountry($country) { |
87
|
|
|
return $this->entityManager->repository('league')->byCountry($country); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Gets all leagues by sport. |
92
|
|
|
* |
93
|
|
|
* @param mixed $sport |
94
|
|
|
* The sport of which to get the leagues. |
95
|
|
|
* |
96
|
|
|
* @return \TheSportsDb\Entity\LeagueInterface[] |
97
|
|
|
* The leagues. |
98
|
|
|
*/ |
99
|
|
|
public function getLeaguesBySport($sport) { |
100
|
|
|
return $this->entityManager->repository('league')->bySport($sport); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Gets all leagues by country and sport. |
105
|
|
|
* |
106
|
|
|
* @param string $country |
107
|
|
|
* The country of which to get the leagues. |
108
|
|
|
* @param mixed $sport |
109
|
|
|
* The sport of which to get the leagues. |
110
|
|
|
* |
111
|
|
|
* @return \TheSportsDb\Entity\LeagueInterface[] |
112
|
|
|
* The leagues. |
113
|
|
|
*/ |
114
|
|
|
public function getLeaguesByCountryAndSport($country, $sport) { |
115
|
|
|
return $this->entityManager->repository('league')->byCountryAndSport($country, $sport); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Gets a team by id. |
120
|
|
|
* |
121
|
|
|
* @param mixed $teamId |
122
|
|
|
* The team id. |
123
|
|
|
* |
124
|
|
|
* @return \TheSportsDb\Entity\TeamInterface |
125
|
|
|
* The team. |
126
|
|
|
*/ |
127
|
|
|
public function getTeam($teamId) { |
128
|
|
|
return $this->entityManager->repository('team')->byId($teamId); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Gets a team by name. |
133
|
|
|
* |
134
|
|
|
* @param string $teamName |
135
|
|
|
* The team name. |
136
|
|
|
* |
137
|
|
|
* @return \TheSportsDb\Entity\TeamInterface[] |
138
|
|
|
* The team. |
139
|
|
|
*/ |
140
|
|
|
public function getTeamsByName($teamName) { |
141
|
|
|
return $this->entityManager->repository('team')->byName($teamName); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Gets a teams by league id. |
146
|
|
|
* |
147
|
|
|
* @param mixed $leagueId |
148
|
|
|
* The league id. |
149
|
|
|
* |
150
|
|
|
* @return \TheSportsDb\Entity\TeamInterface[] |
151
|
|
|
* The teams. |
152
|
|
|
*/ |
153
|
|
|
public function getTeamsByLeague($leagueId) { |
154
|
|
|
return $this->entityManager->repository('team')->byLeague($leagueId); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Gets a teams by league name. |
159
|
|
|
* |
160
|
|
|
* @param string $leagueName |
161
|
|
|
* The league name. |
162
|
|
|
* |
163
|
|
|
* @return \TheSportsDb\Entity\TeamInterface[] |
164
|
|
|
* The teams. |
165
|
|
|
*/ |
166
|
|
|
public function getTeamsByLeagueName($leagueName) { |
167
|
|
|
return $this->entityManager->repository('team')->byLeagueName($leagueName); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Gets a teams by sport and country. |
172
|
|
|
* |
173
|
|
|
* @param mixed $sport |
174
|
|
|
* The sport. |
175
|
|
|
* @param string $country |
176
|
|
|
* The country. |
177
|
|
|
* |
178
|
|
|
* @return \TheSportsDb\Entity\TeamInterface[] |
179
|
|
|
* The teams. |
180
|
|
|
*/ |
181
|
|
|
public function getTeamsBySportAndCountry($sport, $country) { |
182
|
|
|
return $this->entityManager->repository('team')->bySportAndCountry($sport, $country); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Get a player by id. |
187
|
|
|
* |
188
|
|
|
* @param mixed $playerId |
189
|
|
|
* The player id. |
190
|
|
|
* |
191
|
|
|
* @return \TheSportsDb\Entity\PlayerInterface |
192
|
|
|
* The player. |
193
|
|
|
*/ |
194
|
|
|
public function getPlayer($playerId) { |
195
|
|
|
return $this->entityManager->repository('player')->byId($playerId); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Get a players by team id. |
200
|
|
|
* |
201
|
|
|
* @param mixed $teamId |
202
|
|
|
* The team id. |
203
|
|
|
* |
204
|
|
|
* @return \TheSportsDb\Entity\PlayerInterface[] |
205
|
|
|
* The players. |
206
|
|
|
*/ |
207
|
|
|
public function getPlayersByTeam($teamId) { |
208
|
|
|
return $this->entityManager->repository('player')->byTeam($teamId); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Get a players by team name. |
213
|
|
|
* |
214
|
|
|
* @param mixed $teamName |
215
|
|
|
* The team name. |
216
|
|
|
* |
217
|
|
|
* @return \TheSportsDb\Entity\PlayerInterface[] |
218
|
|
|
* The players. |
219
|
|
|
*/ |
220
|
|
|
public function getPlayersByTeamName($teamName) { |
221
|
|
|
return $this->entityManager->repository('player')->byTeamName($teamName); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Get a players by name. |
226
|
|
|
* |
227
|
|
|
* @param mixed $name |
228
|
|
|
* The name. |
229
|
|
|
* |
230
|
|
|
* @return \TheSportsDb\Entity\PlayerInterface[] |
231
|
|
|
* The players. |
232
|
|
|
*/ |
233
|
|
|
public function getPlayersByName($name) { |
234
|
|
|
return $this->entityManager->repository('player')->byName($name); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Get a players by team and name. |
239
|
|
|
* |
240
|
|
|
* @param string $teamName |
241
|
|
|
* The team name. |
242
|
|
|
* @param string $name |
243
|
|
|
* The name. |
244
|
|
|
* |
245
|
|
|
* @return \TheSportsDb\Entity\PlayerInterface[] |
246
|
|
|
* The players. |
247
|
|
|
*/ |
248
|
|
|
public function getPlayersByTeamNameAndName($teamName, $name) { |
249
|
|
|
return $this->entityManager->repository('player')->byTeamNameAndName($teamName, $name); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Get an event by id. |
254
|
|
|
* |
255
|
|
|
* @param mixed $eventId |
256
|
|
|
* The event id. |
257
|
|
|
* |
258
|
|
|
* @return \TheSportsDb\Entity\EventInterface |
259
|
|
|
* The event. |
260
|
|
|
*/ |
261
|
|
|
public function getEvent($eventId) { |
262
|
|
|
return $this->entityManager->repository('event')->byId($eventId); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Get events by name. |
267
|
|
|
* |
268
|
|
|
* @param string $name |
269
|
|
|
* The event name. |
270
|
|
|
* |
271
|
|
|
* @return \TheSportsDb\Entity\EventInterface[] |
272
|
|
|
* The events. |
273
|
|
|
*/ |
274
|
|
|
public function getEventsByName($name) { |
275
|
|
|
return $this->entityManager->repository('event')->byName($name); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Get events by file name. |
280
|
|
|
* |
281
|
|
|
* @param string $name |
282
|
|
|
* The file name. |
283
|
|
|
* |
284
|
|
|
* @return \TheSportsDb\Entity\EventInterface[] |
285
|
|
|
* The events. |
286
|
|
|
*/ |
287
|
|
|
public function getEventsByFileName($name) { |
288
|
|
|
return $this->entityManager->repository('event')->byFileName($name); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Get events by name and season. |
293
|
|
|
* |
294
|
|
|
* @param string $name |
295
|
|
|
* The event name. |
296
|
|
|
* @param mixed $season |
297
|
|
|
* The season. |
298
|
|
|
* |
299
|
|
|
* @return \TheSportsDb\Entity\EventInterface[] |
300
|
|
|
* The events. |
301
|
|
|
*/ |
302
|
|
|
public function getEventsByNameAndSeason($name, $season) { |
303
|
|
|
return $this->entityManager->repository('event')->byNameAndSeason($name, $season); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Get next five events by team. |
308
|
|
|
* |
309
|
|
|
* @param mixed $teamId |
310
|
|
|
* The team id. |
311
|
|
|
* |
312
|
|
|
* @return \TheSportsDb\Entity\EventInterface[] |
313
|
|
|
* The events. |
314
|
|
|
*/ |
315
|
|
|
public function getNextFiveEventsByTeam($teamId) { |
316
|
|
|
return $this->entityManager->repository('event')->nextFiveByTeam($teamId); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* Get next fifteen events by league. |
321
|
|
|
* |
322
|
|
|
* @param mixed $leagueId |
323
|
|
|
* The league id. |
324
|
|
|
* |
325
|
|
|
* @return \TheSportsDb\Entity\EventInterface[] |
326
|
|
|
* The events. |
327
|
|
|
*/ |
328
|
|
|
public function getNextFifteenEventsByLeague($leagueId) { |
329
|
|
|
return $this->entityManager->repository('event')->nextFifteenEventsByLeague($leagueId); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* Get next fifteen events by league and round. |
334
|
|
|
* |
335
|
|
|
* @param mixed $leagueId |
336
|
|
|
* The league id. |
337
|
|
|
* @param int $round |
338
|
|
|
* The round. |
339
|
|
|
* |
340
|
|
|
* @return \TheSportsDb\Entity\EventInterface[] |
341
|
|
|
* The events. |
342
|
|
|
*/ |
343
|
|
|
public function getNextFifteenEventsByLeagueAndRound($leagueId, $round) { |
344
|
|
|
return $this->entityManager->repository('event')->nextFifteenEventsByLeagueAndRound($leagueId, $round); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Get last five events by team. |
349
|
|
|
* |
350
|
|
|
* @param mixed $teamId |
351
|
|
|
* The team id. |
352
|
|
|
* |
353
|
|
|
* @return \TheSportsDb\Entity\EventInterface[] |
354
|
|
|
* The events. |
355
|
|
|
*/ |
356
|
|
|
public function getLastFiveEventsByTeam($teamId) { |
357
|
|
|
return $this->entityManager->repository('event')->lastFiveByTeam($teamId); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Get last fifteen events by league. |
362
|
|
|
* |
363
|
|
|
* @param mixed $leagueId |
364
|
|
|
* The league id. |
365
|
|
|
* |
366
|
|
|
* @return \TheSportsDb\Entity\EventInterface[] |
367
|
|
|
* The events. |
368
|
|
|
*/ |
369
|
|
|
public function getLastFifteenEventsByLeague($leagueId) { |
370
|
|
|
return $this->entityManager->repository('event')->lastFifteenEventsByLeague($leagueId); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* Get events by day. |
375
|
|
|
* |
376
|
|
|
* @param \DateTime $date |
377
|
|
|
* The day. |
378
|
|
|
* @param string|null $sport |
379
|
|
|
* The sport. |
380
|
|
|
* @param string|null $leagueName |
381
|
|
|
* The league name. |
382
|
|
|
* |
383
|
|
|
* @return \TheSportsDb\Entity\EventInterface[] |
384
|
|
|
* The events. |
385
|
|
|
*/ |
386
|
|
|
public function getEventsByDay(\DateTime $date, $sport = NULL, $leagueName = NULL) { |
387
|
|
|
return $this->entityManager->repository('event')->byDay($date, $sport, $leagueName); |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Get events by league, round and season. |
392
|
|
|
* |
393
|
|
|
* @param mixed $leagueId |
394
|
|
|
* The league id. |
395
|
|
|
* @param int $round |
396
|
|
|
* The round. |
397
|
|
|
* @param mixed $season |
398
|
|
|
* The season. |
399
|
|
|
* |
400
|
|
|
* @return \TheSportsDb\Entity\EventInterface[] |
401
|
|
|
* The events. |
402
|
|
|
*/ |
403
|
|
|
public function getEventsByLeagueRoundAndSeason($leagueId, $round, $season) { |
404
|
|
|
return $this->entityManager->repository('event')->byLeagueRoundAndSeason($leagueId, $round, $season); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Get events by league and season. |
409
|
|
|
* |
410
|
|
|
* @param mixed $leagueId |
411
|
|
|
* The league id. |
412
|
|
|
* @param mixed $season |
413
|
|
|
* The season. |
414
|
|
|
* |
415
|
|
|
* @return \TheSportsDb\Entity\EventInterface[] |
416
|
|
|
* The events. |
417
|
|
|
*/ |
418
|
|
|
public function getEventsByLeagueAndSeason($leagueId, $season) { |
419
|
|
|
return $this->entityManager->repository('event')->byLeagueAndSeason($leagueId, $season); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Get seasons by league. |
424
|
|
|
* |
425
|
|
|
* @param mixed $leagueId |
426
|
|
|
* The league id. |
427
|
|
|
* |
428
|
|
|
* @return \TheSportsDb\Entity\SeasonInterface[] |
429
|
|
|
* The seasons. |
430
|
|
|
*/ |
431
|
|
|
public function getSeasonsByLeague($leagueId) { |
432
|
|
|
return $this->entityManager->repository('season')->byLeague($leagueId); |
433
|
|
|
} |
434
|
|
|
} |
435
|
|
|
|