1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @file |
4
|
|
|
* Contains \TheSportsDb\Entity\Season. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace TheSportsDb\Entity; |
8
|
|
|
|
9
|
|
|
use TheSportsDb\Entity\EntityManagerInterface; |
10
|
|
|
use TheSportsDb\PropertyMapper\PropertyDefinition; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* A fully loaded season object. |
14
|
|
|
* |
15
|
|
|
* @author Jelle Sebreghts |
16
|
|
|
*/ |
17
|
|
|
class Season extends Entity implements SeasonInterface { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
protected static $propertyMapDefinition; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The primary identifier. |
26
|
|
|
* |
27
|
|
|
* @var mixed |
28
|
|
|
*/ |
29
|
|
|
protected $id; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The name. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $name; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The league of this season. |
40
|
|
|
* |
41
|
|
|
* @var \TheSportsDb\Entity\LeagueInterface |
42
|
|
|
*/ |
43
|
|
|
protected $league; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The events of this season. |
47
|
|
|
* |
48
|
|
|
* @var \TheSportsDb\Entity\EventInterface[] |
49
|
|
|
*/ |
50
|
|
|
protected $events = array(); |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
1 |
|
public function getId() { |
56
|
1 |
|
return $this->id; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
1 |
|
public function getName() { |
63
|
1 |
|
return $this->name; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
1 |
|
public function getLeague() { |
70
|
1 |
|
return $this->league; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
1 |
|
public function getEvents() { |
77
|
1 |
|
return $this->events; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Transforms the league property to a league entity. |
82
|
|
|
* |
83
|
|
|
* @param mixed $value |
84
|
|
|
* The source value of the league property. |
85
|
|
|
* @param \stdClass $context |
86
|
|
|
* The source object representing this season. |
87
|
|
|
* @param EntityManagerInterface $entityManager |
88
|
|
|
* The entity manager. |
89
|
|
|
* |
90
|
|
|
* @return \TheSportsDb\Entity\LeagueInterface |
91
|
|
|
* The league entity. |
92
|
|
|
*/ |
93
|
|
|
public static function transformLeague($value, $context, EntityManagerInterface $entityManager) { |
94
|
|
|
return static::transform($value, $context, $entityManager, 'league', 'idLeague', array('strLeague' => 'strLeague')); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Transforms the events property to event entities. |
99
|
|
|
* |
100
|
|
|
* @param array $values |
101
|
|
|
* The source value of the event property. |
102
|
|
|
* @param \stdClass $context |
103
|
|
|
* The source object representing this season. |
104
|
|
|
* @param EntityManagerInterface $entityManager |
105
|
|
|
* The entity manager. |
106
|
|
|
* |
107
|
|
|
* @return \TheSportsDb\Entity\EventInterface[] |
108
|
|
|
* The event entity. |
109
|
|
|
*/ |
110
|
|
|
public static function transformEvents(array $values, $context, EntityManagerInterface $entityManager) { |
111
|
|
|
$mappedEvents = array(); |
112
|
|
|
foreach ($values as $eventData) { |
113
|
|
|
$mappedEvents[] = $entityManager->repository('event')->byId($eventData->idEvent); |
114
|
|
|
} |
115
|
|
|
return $mappedEvents; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Transforms the id property to a unique identifier. |
120
|
|
|
* |
121
|
|
|
* @param mixed $value |
122
|
|
|
* The source value of the id property. |
123
|
|
|
* @param \stdClass $context |
124
|
|
|
* The source object representing this season. |
125
|
|
|
* |
126
|
|
|
* @return string |
127
|
|
|
* The unique identifier. |
128
|
|
|
*/ |
129
|
|
|
public static function transformId($value, $context) { |
130
|
|
|
return $value . '|' . $context->idLeague; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Reverses the transformation of the id property. |
135
|
|
|
* |
136
|
|
|
* @param mixed $value |
137
|
|
|
* The source value of the id property. |
138
|
|
|
* @param \stdClass $context |
139
|
|
|
* The source object representing this season. |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
* The id property value. |
143
|
|
|
*/ |
144
|
|
|
public static function reverseId($value, $context) { |
145
|
|
|
$id = explode('|', $value); |
146
|
|
|
return reset($id); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* {@inheritdoc} |
151
|
|
|
*/ |
152
|
1 |
|
protected static function initPropertyMapDefinition() { |
153
|
1 |
|
static::$propertyMapDefinition |
154
|
1 |
|
->addPropertyMap( |
155
|
1 |
|
new PropertyDefinition('strSeason'), |
156
|
1 |
|
new PropertyDefinition('id'), |
157
|
1 |
|
[self::class, 'transformId'], |
158
|
1 |
|
[self::class, 'reverseId'] |
159
|
|
|
) |
160
|
1 |
|
->addPropertyMap( |
161
|
1 |
|
new PropertyDefinition('strSeason'), |
162
|
1 |
|
new PropertyDefinition('name') |
163
|
|
|
) |
164
|
1 |
|
->addPropertyMap( |
165
|
1 |
|
new PropertyDefinition('idLeague'), |
166
|
1 |
|
new PropertyDefinition('league', 'league'), |
167
|
1 |
|
[self::class, 'transformLeague'], |
168
|
1 |
|
[League::class, 'reverse'] |
169
|
|
|
) |
170
|
1 |
|
->addPropertyMap( |
171
|
1 |
|
new PropertyDefinition('events'), |
172
|
1 |
|
new PropertyDefinition('events', 'event', TRUE), |
173
|
1 |
|
[self::class, 'transformEvents'], |
174
|
1 |
|
[Event::class, 'reverseArray'] |
175
|
|
|
); |
176
|
1 |
|
} |
177
|
|
|
|
178
|
|
|
} |
179
|
|
|
|