1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @file |
4
|
|
|
* Contains \TheSportsDb\Entity\Proxy\SportProxy. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace TheSportsDb\Entity\Proxy; |
8
|
|
|
|
9
|
|
|
use TheSportsDb\Entity\LeagueInterface; |
10
|
|
|
use TheSportsDb\Entity\SportInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* A sport object that is not yet fully loaded. |
14
|
|
|
* |
15
|
|
|
* @author Jelle Sebreghts |
16
|
|
|
*/ |
17
|
|
|
class SportProxy extends Proxy implements SportInterface { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
protected function load() { |
23
|
|
|
throw new \Exception('Could not fully load sport with id ' . $this->properties->id . '.'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Lazy loads the leagues for this sport. |
28
|
|
|
* |
29
|
|
|
* @throws \Exception |
30
|
|
|
* When the leagues cannot be loaded. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
protected function loadLeagues() { |
35
|
|
|
$leagueData = $this->sportsDbClient->doRequest('search_all_leagues.php', array('s' => $this->properties->id)); |
36
|
|
|
if (isset($leagueData->countrys)) { |
37
|
|
|
$this->update($this->entityManager->mapProperties((object) array('leagues' => $leagueData->countrys), $this->getEntityType())); |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
throw new \Exception('Could not fully load sport with id ' . $this->properties->id . '.'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
1 |
|
public function getId() { |
47
|
1 |
|
return $this->get('id'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
1 |
|
public function getLeagues() { |
54
|
1 |
|
return $this->get('leagues'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
1 |
|
public function getName() { |
61
|
1 |
|
return $this->get('name'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
1 |
|
public function addLeague(LeagueInterface $league) { |
68
|
1 |
|
if ($this->entity) { |
69
|
|
|
$this->entity->addLeague($league); |
70
|
|
|
return; |
71
|
|
|
} |
72
|
1 |
|
if (!isset($this->properties->leagues)) { |
73
|
|
|
$this->properties->leagues = array(); |
74
|
|
|
} |
75
|
1 |
|
if (!isset($this->properties->leagues[$league->getId()])) { |
76
|
1 |
|
$this->properties->leagues[$league->getId()] = $league; |
77
|
|
|
} |
78
|
1 |
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|