|
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
|
|
|
public function getSports() { |
|
|
|
|
|
|
32
|
|
|
return $this->entityManager->repository('sport')->all(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Get a sport by name. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $name |
|
39
|
|
|
* The sport name. |
|
40
|
|
|
* |
|
41
|
|
|
* @return \TheSportsDb\Entity\SportInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getSport($name) { |
|
44
|
|
|
return $this->entityManager->repository('sport')->byId($name); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function getLeagues() { |
|
|
|
|
|
|
48
|
|
|
return $this->entityManager->repository('league')->all(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get a league by id. |
|
53
|
|
|
* |
|
54
|
|
|
* @param int $leagueId |
|
55
|
|
|
* The league id. |
|
56
|
|
|
* |
|
57
|
|
|
* @return \TheSportsDb\Entity\LeagueInterface |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getLeague($leagueId) { |
|
60
|
|
|
return $this->entityManager->repository('league')->byId($leagueId); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getLeaguesByCountry($country) { |
|
|
|
|
|
|
64
|
|
|
return $this->entityManager->repository('league')->byCountry($country); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getLeaguesBySport($sport) { |
|
|
|
|
|
|
68
|
|
|
return $this->entityManager->repository('league')->bySport($sport); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getLeaguesByCountryAndSport($country, $sport) { |
|
|
|
|
|
|
72
|
|
|
return $this->entityManager->repository('league')->byCountryAndSport($country, $sport); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getTeam($teamId) { |
|
|
|
|
|
|
76
|
|
|
return $this->entityManager->repository('team')->byId($teamId); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getTeamByName($teamName) { |
|
|
|
|
|
|
80
|
|
|
return $this->entityManager->repository('team')->byName($teamName); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function getTeamsByLeague($leagueId) { |
|
|
|
|
|
|
84
|
|
|
return $this->entityManager->repository('team')->byLeague($leagueId); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getTeamsByLeagueName($leagueName) { |
|
|
|
|
|
|
88
|
|
|
return $this->entityManager->repository('team')->byLeagueName($leagueName); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function getTeamsBySportAndCountry($sport, $country) { |
|
|
|
|
|
|
92
|
|
|
return $this->entityManager->repository('team')->bySportAndCountry($sport, $country); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function getPlayer($playerId) { |
|
|
|
|
|
|
96
|
|
|
return $this->entityManager->repository('player')->byId($playerId); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function getPlayersByTeam($teamId) { |
|
|
|
|
|
|
100
|
|
|
return $this->entityManager->repository('player')->byTeam($teamId); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getPlayersByTeamName($teamName) { |
|
|
|
|
|
|
104
|
|
|
return $this->entityManager->repository('player')->byTeamName($teamName); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function getPlayersByName($teamName) { |
|
|
|
|
|
|
108
|
|
|
return $this->entityManager->repository('player')->byName($teamName); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function getPlayersByTeamNameAndName($teamName, $name) { |
|
|
|
|
|
|
112
|
|
|
return $this->entityManager->repository('player')->byTeamNameAndName($teamName, $name); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function getEvent($eventId) { |
|
|
|
|
|
|
116
|
|
|
return $this->entityManager->repository('event')->byId($eventId); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function getEventsByName($name) { |
|
|
|
|
|
|
120
|
|
|
return $this->entityManager->repository('event')->byName($name); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function getEventsByFileName($name) { |
|
|
|
|
|
|
124
|
|
|
return $this->entityManager->repository('event')->byFileName($name); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function getEventsByNameAndSeason($name, $season) { |
|
|
|
|
|
|
128
|
|
|
return $this->entityManager->repository('event')->byNameAndSeason($name, $season); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function getNextFiveEventsByTeam($teamId) { |
|
|
|
|
|
|
132
|
|
|
return $this->entityManager->repository('event')->nextFiveByTeam($teamId); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function getNextFifteenEventsByLeague($leagueId) { |
|
|
|
|
|
|
136
|
|
|
return $this->entityManager->repository('event')->nextFifteenEventsByLeague($leagueId); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function getSeasonsByLeague($leagueId) { |
|
|
|
|
|
|
140
|
|
|
return $this->entityManager->repository('season')->byLeague($leagueId); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.