|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* dependency Core |
|
4
|
|
|
* @author gbesson |
|
5
|
|
|
* |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace PlaygroundGame; |
|
8
|
|
|
|
|
9
|
|
|
use Zend\ModuleManager\ModuleManager; |
|
10
|
|
|
use Zend\Mvc\ModuleRouteListener; |
|
11
|
|
|
use Zend\Mvc\MvcEvent; |
|
12
|
|
|
use Zend\Validator\AbstractValidator; |
|
13
|
|
|
|
|
14
|
|
|
class Module |
|
15
|
|
|
{ |
|
16
|
|
|
public function init(ModuleManager $manager) |
|
17
|
|
|
{ |
|
18
|
|
|
$eventManager = $manager->getEventManager(); |
|
19
|
|
|
|
|
20
|
|
|
/* |
|
21
|
|
|
* This event change the config before it's cached |
|
22
|
|
|
* The change will apply to 'template_path_stack' and 'assetic_configuration' |
|
23
|
|
|
* These 2 config take part in the Playground Theme Management |
|
24
|
|
|
*/ |
|
25
|
|
|
$eventManager->attach(\Zend\ModuleManager\ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'onMergeConfig'), 50); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* This method is called only when the config is not cached. |
|
30
|
|
|
* @param \Zend\ModuleManager\ModuleEvent $e |
|
31
|
|
|
*/ |
|
32
|
|
|
public function onMergeConfig(\Zend\ModuleManager\ModuleEvent $e) |
|
33
|
|
|
{ |
|
34
|
|
|
$config = $e->getConfigListener()->getMergedConfig(false); |
|
35
|
|
|
|
|
36
|
|
|
if (isset($config['design']) && isset($config['design']['frontend'])) { |
|
37
|
|
|
$parentTheme = array($config['design']['frontend']['package'], $config['design']['frontend']['theme']); |
|
38
|
|
|
} else { |
|
39
|
|
|
$parentTheme = array('playground','base'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
// If custom games need a specific route. I create these routes |
|
43
|
|
|
if (PHP_SAPI !== 'cli') { |
|
44
|
|
|
if (isset($config['custom_games'])) { |
|
45
|
|
|
foreach ($config['custom_games'] as $k => $v) { |
|
46
|
|
|
// add custom language directory |
|
47
|
|
|
$config['translator']['translation_file_patterns'][] = array( |
|
48
|
|
|
'type' => 'phpArray', |
|
49
|
|
|
'base_dir' => __DIR__ . '/../../../../../design/frontend/'. $parentTheme[0] . |
|
50
|
|
|
'/'. $parentTheme[1] . '/custom/' . $k . '/language', |
|
51
|
|
|
'pattern' => '%s.php', |
|
52
|
|
|
'text_domain' => $k |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
// create routes |
|
56
|
|
|
if (isset($v['url'])) { |
|
57
|
|
|
if (!is_array($v['url'])) { |
|
58
|
|
|
$v['url'] = array($v['url']); |
|
59
|
|
|
} |
|
60
|
|
|
foreach ($v['url'] as $url) { |
|
61
|
|
|
// I take the url model of the game type |
|
62
|
|
|
if (isset($config['router']['routes']['frontend']['child_routes'][$v['classType']])) { |
|
63
|
|
|
$routeModel = $config['router']['routes']['frontend']['child_routes'][$v['classType']]; |
|
64
|
|
|
|
|
65
|
|
|
// Changing the root of the route |
|
66
|
|
|
$routeModel['options']['route'] = '/'; |
|
67
|
|
|
|
|
68
|
|
|
// and removing the trailing slash for each subsequent route |
|
69
|
|
|
foreach ($routeModel['child_routes'] as $id => $ar) { |
|
70
|
|
|
$routeModel['child_routes'][$id]['options']['route'] = ltrim( |
|
71
|
|
|
$ar['options']['route'], |
|
72
|
|
|
'/' |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
// then create the hostname route + appending the model updated |
|
77
|
|
|
$config['router']['routes']['frontend.'.$url] = array( |
|
78
|
|
|
'type' => 'Zend\Mvc\Router\Http\Hostname', |
|
79
|
|
|
'options' => array( |
|
80
|
|
|
'route' => $url, |
|
81
|
|
|
'defaults' => array( |
|
82
|
|
|
'id' => $k |
|
83
|
|
|
) |
|
84
|
|
|
), |
|
85
|
|
|
'may_terminate' => true |
|
86
|
|
|
); |
|
87
|
|
|
$config['router']['routes']['frontend.'.$url]['child_routes'][$v['classType']] = $routeModel; |
|
88
|
|
|
|
|
89
|
|
|
// adding not-found catchall : Any non existent URL will be catched by this controller |
|
90
|
|
|
$config['router']['routes']['frontend.'.$url]['child_routes'][$v['classType']]['child_routes']['catchall'] = array( |
|
91
|
|
|
'type' => '\Zend\Mvc\Router\Http\Regex', |
|
92
|
|
|
'priority' => -1000, |
|
93
|
|
|
'options' => array( |
|
94
|
|
|
'regex' => '.*', |
|
95
|
|
|
'spec' => '%url%', |
|
96
|
|
|
'defaults' => array( |
|
97
|
|
|
'controller' => 'playgroundgame_'.$v['classType'], |
|
98
|
|
|
'action' => 'not-found' |
|
99
|
|
|
), |
|
100
|
|
|
), |
|
101
|
|
|
); |
|
102
|
|
|
|
|
103
|
|
|
$coreLayoutModel = isset($config['core_layout']['frontend'])? |
|
104
|
|
|
$config['core_layout']['frontend']: |
|
105
|
|
|
[]; |
|
106
|
|
|
$config['core_layout']['frontend.'.$url] = $coreLayoutModel; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
if (isset($v['assetic_configuration'])) { |
|
111
|
|
|
foreach ($v['assetic_configuration']['modules'] as $m => $d) { |
|
112
|
|
|
$v['assetic_configuration']['modules'][$m]['root_path'][] = __DIR__ . |
|
113
|
|
|
'/../../../../../design/frontend/'. $parentTheme[0] .'/'. $parentTheme[1] . |
|
114
|
|
|
'/custom/' . $k . '/assets'; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
// I specialize the route config to the game ! |
|
118
|
|
|
if (isset($v['assetic_configuration']['routes'])) { |
|
119
|
|
|
$customRoutes = array(); |
|
120
|
|
|
if (isset($v['assetic_configuration']['routes']['params'])) { |
|
121
|
|
|
$customRoutes['custom'][$k]['params'] = $v['assetic_configuration']['routes']['params']; |
|
122
|
|
|
unset($v['assetic_configuration']['routes']['params']); |
|
123
|
|
|
} |
|
124
|
|
|
$customRoutes['custom'][$k]['params']['id'] = $k; |
|
125
|
|
|
$customRoutes['custom'][$k]['routes'] = $v['assetic_configuration']['routes']; |
|
126
|
|
|
$v['assetic_configuration']['routes'] = $customRoutes; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$config['assetic_configuration'] = array_replace_recursive( |
|
130
|
|
|
$config['assetic_configuration'], |
|
131
|
|
|
$v['assetic_configuration'] |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
$e->getConfigListener()->setMergedConfig($config); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function onBootstrap(MvcEvent $e) |
|
142
|
|
|
{ |
|
143
|
|
|
$serviceManager = $e->getApplication()->getServiceManager(); |
|
144
|
|
|
|
|
145
|
|
|
$options = $serviceManager->get('playgroundcore_module_options'); |
|
146
|
|
|
$locale = $options->getLocale(); |
|
147
|
|
|
$translator = $serviceManager->get('translator'); |
|
148
|
|
|
if (!empty($locale)) { |
|
149
|
|
|
//translator |
|
150
|
|
|
$translator->setLocale($locale); |
|
151
|
|
|
|
|
152
|
|
|
// plugins |
|
153
|
|
|
$translate = $serviceManager->get('viewhelpermanager')->get('translate'); |
|
154
|
|
|
$translate->getTranslator()->setLocale($locale); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
AbstractValidator::setDefaultTranslator($translator, 'playgroundcore'); |
|
158
|
|
|
|
|
159
|
|
|
$eventManager = $e->getApplication()->getEventManager(); |
|
160
|
|
|
$moduleRouteListener = new ModuleRouteListener(); |
|
161
|
|
|
$moduleRouteListener->attach($eventManager); |
|
162
|
|
|
|
|
163
|
|
|
// If PlaygroundCms is installed, I can add my own dynareas to benefit from this feature |
|
164
|
|
|
$e->getApplication()->getEventManager()->getSharedManager()->attach( |
|
165
|
|
|
'Zend\Mvc\Application', |
|
166
|
|
|
'getDynareas', |
|
167
|
|
|
array($this, 'updateDynareas') |
|
168
|
|
|
); |
|
169
|
|
|
|
|
170
|
|
|
// I can post cron tasks to be scheduled by the core cron service |
|
171
|
|
|
$e->getApplication()->getEventManager()->getSharedManager()->attach( |
|
172
|
|
|
'Zend\Mvc\Application', |
|
173
|
|
|
'getCronjobs', |
|
174
|
|
|
array($this, 'addCronjob') |
|
175
|
|
|
); |
|
176
|
|
|
|
|
177
|
|
|
// If PlaygroundCms is installed, I can add game categories |
|
178
|
|
|
$e->getApplication()->getEventManager()->getSharedManager()->attach( |
|
179
|
|
|
'Zend\Mvc\Application', |
|
180
|
|
|
'getCmsCategories', |
|
181
|
|
|
array($this, 'populateCmsCategories') |
|
182
|
|
|
); |
|
183
|
|
|
|
|
184
|
|
|
// If cron is called, the $e->getRequest()->getPost() produces an error so I protect it with |
|
185
|
|
|
// this test |
|
186
|
|
|
if ((get_class($e->getRequest()) == 'Zend\Console\Request')) { |
|
187
|
|
|
return; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* This listener gives the possibility to select the layout on module / controller / action level |
|
192
|
|
|
* This is triggered after the PlaygroundDesign one so that it's the last triggered for games. |
|
193
|
|
|
*/ |
|
194
|
|
|
$e->getApplication()->getEventManager()->getSharedManager()->attach( |
|
195
|
|
|
'Zend\Mvc\Controller\AbstractActionController', |
|
196
|
|
|
'dispatch', |
|
197
|
|
|
function (MvcEvent $e) { |
|
198
|
|
|
$config = $e->getApplication()->getServiceManager()->get('config'); |
|
199
|
|
|
if (isset($config['core_layout'])) { |
|
200
|
|
|
$controller = $e->getTarget(); |
|
201
|
|
|
$controllerClass = get_class($controller); |
|
202
|
|
|
$moduleName = strtolower(substr($controllerClass, 0, strpos($controllerClass, '\\'))); |
|
203
|
|
|
$match = $e->getRouteMatch(); |
|
204
|
|
|
$routeName = $match->getMatchedRouteName(); |
|
205
|
|
|
$areaName = (strpos($routeName, '/'))? |
|
206
|
|
|
substr($routeName, 0, strpos($routeName, '/')): |
|
207
|
|
|
$routeName; |
|
208
|
|
|
$areaName = (strpos($areaName, '.'))?substr($areaName, 0, strpos($areaName, '.')):$areaName; |
|
209
|
|
|
$areaName = ($areaName == 'frontend' || $areaName == 'admin')? $areaName : 'frontend'; |
|
210
|
|
|
$controllerName = $match->getParam('controller', 'not-found'); |
|
211
|
|
|
$actionName = $match->getParam('action', 'not-found'); |
|
212
|
|
|
$slug = $match->getParam('id', ''); |
|
213
|
|
|
$viewModel = $e->getViewModel(); |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* Assign the correct layout |
|
217
|
|
|
*/ |
|
218
|
|
|
if (!empty($slug)) { |
|
219
|
|
|
if (isset($config['custom_games'][$slug]['core_layout'][$areaName]['modules'][$moduleName]['controllers'][$controllerName]['actions'][$actionName]['layout'])) { |
|
220
|
|
|
$controller->layout($config['custom_games'][$slug]['core_layout'][$areaName]['modules'][$moduleName]['controllers'][$controllerName]['actions'][$actionName]['layout']); |
|
221
|
|
|
} elseif (isset($config['custom_games'][$slug]['core_layout'][$areaName]['modules'][$moduleName]['controllers'][$controllerName]['layout'])) { |
|
222
|
|
|
$controller->layout($config['custom_games'][$slug]['core_layout'][$areaName]['modules'][$moduleName]['controllers'][$controllerName]['layout']); |
|
223
|
|
|
} elseif (isset($config['custom_games'][$slug]['core_layout'][$areaName]['modules'][$moduleName]['layout'])) { |
|
224
|
|
|
$controller->layout($config['custom_games'][$slug]['core_layout'][$areaName]['modules'][$moduleName]['layout']); |
|
225
|
|
|
} elseif (isset($config['custom_games'][$slug]['core_layout'][$areaName]['layout'])) { |
|
226
|
|
|
$controller->layout($config['custom_games'][$slug]['core_layout'][$areaName]['layout']); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
|
|
230
|
|
|
// the area needs to be updated if I'm in a custom game for frontendUrl to work |
|
231
|
|
|
if (isset($config['custom_games'][$slug])) { |
|
232
|
|
|
$url = (is_array($config['custom_games'][$slug]['url']))? |
|
233
|
|
|
$config['custom_games'][$slug]['url']: |
|
234
|
|
|
array($config['custom_games'][$slug]['url']); |
|
235
|
|
|
$from = strtolower($e->getRequest()->getUri()->getHost()); |
|
|
|
|
|
|
236
|
|
|
$areaName = ($areaName === 'frontend' && in_array($from, $url))? $areaName.'.'.$from:$areaName; |
|
237
|
|
|
} |
|
238
|
|
|
// I add this area param so that it can be used by Controller plugin frontendUrl |
|
239
|
|
|
// and View helper frontendUrl |
|
240
|
|
|
$match->setParam('area', $areaName); |
|
241
|
|
|
/** |
|
242
|
|
|
* Create variables attached to layout containing path views |
|
243
|
|
|
* cascading assignment is managed |
|
244
|
|
|
*/ |
|
245
|
|
|
if (isset($config['custom_games'][$slug]['core_layout'][$areaName]['modules'][$moduleName]['children_views'])) { |
|
246
|
|
|
foreach ($config['custom_games'][$slug]['core_layout'][$areaName]['modules'][$moduleName]['children_views'] as $k => $v) { |
|
247
|
|
|
$viewModel->$k = $v; |
|
248
|
|
|
} |
|
249
|
|
|
} |
|
250
|
|
|
if (isset($config['custom_games'][$slug]['core_layout'][$areaName]['modules'][$moduleName]['controllers'][$controllerName]['children_views'])) { |
|
251
|
|
View Code Duplication |
foreach ($config['custom_games'][$slug]['core_layout'][$areaName]['modules'][$moduleName]['controllers'][$controllerName]['children_views'] as $k => $v) { |
|
|
|
|
|
|
252
|
|
|
$viewModel->$k = $v; |
|
253
|
|
|
} |
|
254
|
|
|
} |
|
255
|
|
|
if (isset($config['custom_games'][$slug]['core_layout'][$areaName]['modules'][$moduleName]['controllers'][$controllerName]['actions'][$actionName]['children_views'])) { |
|
256
|
|
View Code Duplication |
foreach ($config['custom_games'][$slug]['core_layout'][$areaName]['modules'][$moduleName]['controllers'][$controllerName]['actions'][$actionName]['children_views'] as $k => $v) { |
|
|
|
|
|
|
257
|
|
|
$viewModel->$k = $v; |
|
258
|
|
|
} |
|
259
|
|
|
} |
|
260
|
|
|
} |
|
261
|
|
|
} |
|
262
|
|
|
}, |
|
263
|
|
|
10 |
|
264
|
|
|
); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* This method get the games and add them as Dynareas to PlaygroundCms |
|
269
|
|
|
* so that blocks can be dynamically added to the games. |
|
270
|
|
|
* |
|
271
|
|
|
* @param MvcEvent $e |
|
272
|
|
|
* @return array |
|
273
|
|
|
*/ |
|
274
|
|
|
public function updateDynareas(\Zend\EventManager\Event $e) |
|
275
|
|
|
{ |
|
276
|
|
|
$dynareas = $e->getParam('dynareas'); |
|
277
|
|
|
|
|
278
|
|
|
$gameService = $e->getTarget()->getServiceManager()->get('playgroundgame_game_service'); |
|
279
|
|
|
|
|
280
|
|
|
$games = $gameService->getActiveGames(); |
|
281
|
|
|
|
|
282
|
|
|
foreach ($games as $game) { |
|
283
|
|
|
$array = array( |
|
284
|
|
|
'game'.$game->getId() => array( |
|
285
|
|
|
'title' => $game->getTitle(), |
|
286
|
|
|
'description' => $game->getClassType(), |
|
287
|
|
|
'location'=>'pages du jeu' |
|
288
|
|
|
) |
|
289
|
|
|
); |
|
290
|
|
|
$dynareas = array_merge($dynareas, $array); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
return $dynareas; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* This method add the games to the cms categories of pages |
|
298
|
|
|
* not that satisfied neither |
|
299
|
|
|
* |
|
300
|
|
|
* @param EventManager $e |
|
301
|
|
|
* @return array |
|
302
|
|
|
*/ |
|
303
|
|
|
public function populateCmsCategories ($e) |
|
304
|
|
|
{ |
|
305
|
|
|
$catsArray = $e->getParam('categories'); |
|
306
|
|
|
|
|
307
|
|
|
$gameService = $e->getTarget()->getServiceManager()->get('playgroundgame_game_service'); |
|
308
|
|
|
$games = $gameService->getActiveGames(false); |
|
309
|
|
|
|
|
310
|
|
|
foreach ($games as $game) { |
|
311
|
|
|
$catsArray[$game->getIdentifier()] = 'Pg Game - ' . $game->getIdentifier(); |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
return $catsArray; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* This method get the cron config for this module an add them to the listener |
|
319
|
|
|
* |
|
320
|
|
|
* @param MvcEvent $e |
|
321
|
|
|
* @return array |
|
322
|
|
|
*/ |
|
323
|
|
|
public function addCronjob(\Zend\EventManager\Event $e) |
|
324
|
|
|
{ |
|
325
|
|
|
$cronjobs = $e->getParam('cronjobs'); |
|
326
|
|
|
|
|
327
|
|
|
$cronjobs['adfagame_email'] = array( |
|
328
|
|
|
'frequency' => '*/15 * * * *', |
|
329
|
|
|
'callback' => '\PlaygroundGame\Service\Cron::cronMail', |
|
330
|
|
|
'args' => array('bar', 'baz'), |
|
331
|
|
|
); |
|
332
|
|
|
|
|
333
|
|
|
// tous les jours à 5:00 AM |
|
334
|
|
|
$cronjobs['adfagame_instantwin_email'] = array( |
|
335
|
|
|
'frequency' => '* 5 * * *', |
|
336
|
|
|
'callback' => '\PlaygroundGame\Service\Cron::instantWinEmail', |
|
337
|
|
|
'args' => array(), |
|
338
|
|
|
); |
|
339
|
|
|
|
|
340
|
|
|
return $cronjobs; |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
public function getConfig() |
|
344
|
|
|
{ |
|
345
|
|
|
return include __DIR__ . '/../../config/module.config.php'; |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
public function getAutoloaderConfig() |
|
349
|
|
|
{ |
|
350
|
|
|
return array( |
|
351
|
|
|
'Zend\Loader\StandardAutoloader' => array( |
|
352
|
|
|
'namespaces' => array( |
|
353
|
|
|
__NAMESPACE__ => __DIR__ . '/../../src/' . __NAMESPACE__, |
|
354
|
|
|
), |
|
355
|
|
|
), |
|
356
|
|
|
); |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* @return array |
|
361
|
|
|
*/ |
|
362
|
|
|
public function getViewHelperConfig() |
|
363
|
|
|
{ |
|
364
|
|
|
return array( |
|
365
|
|
|
'factories' => array( |
|
366
|
|
|
'playgroundPrizeCategory' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
367
|
|
|
$locator = $sm->getServiceLocator(); |
|
|
|
|
|
|
368
|
|
|
$viewHelper = new View\Helper\PrizeCategory; |
|
369
|
|
|
$viewHelper->setPrizeCategoryService($locator->get('playgroundgame_prizecategory_service')); |
|
370
|
|
|
|
|
371
|
|
|
return $viewHelper; |
|
372
|
|
|
}, |
|
373
|
|
|
), |
|
374
|
|
|
); |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
public function getServiceConfig() |
|
378
|
|
|
{ |
|
379
|
|
|
return array( |
|
380
|
|
|
'aliases' => array( |
|
381
|
|
|
// An alias for linking a partner service with PlaygroundGame without adherence |
|
382
|
|
|
'playgroundgame_partner_service' => 'playgroundpartnership_partner_service', |
|
383
|
|
|
'playgroundgame_message' => 'playgroundcore_message', |
|
384
|
|
|
|
|
385
|
|
|
), |
|
386
|
|
|
|
|
387
|
|
|
'invokables' => array( |
|
388
|
|
|
'playgroundgame_game_service' => 'PlaygroundGame\Service\Game', |
|
389
|
|
|
'playgroundgame_lottery_service' => 'PlaygroundGame\Service\Lottery', |
|
390
|
|
|
'playgroundgame_postvote_service' => 'PlaygroundGame\Service\PostVote', |
|
391
|
|
|
'playgroundgame_quiz_service' => 'PlaygroundGame\Service\Quiz', |
|
392
|
|
|
'playgroundgame_instantwin_service' => 'PlaygroundGame\Service\InstantWin', |
|
393
|
|
|
'playgroundgame_mission_service' => 'PlaygroundGame\Service\Mission', |
|
394
|
|
|
'playgroundgame_prize_service' => 'PlaygroundGame\Service\Prize', |
|
395
|
|
|
'playgroundgame_prizecategory_service' => 'PlaygroundGame\Service\PrizeCategory', |
|
396
|
|
|
'playgroundgame_prizecategoryuser_service' => 'PlaygroundGame\Service\PrizeCategoryUser', |
|
397
|
|
|
), |
|
398
|
|
|
|
|
399
|
|
|
'factories' => array( |
|
400
|
|
|
'playgroundgame_module_options' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
401
|
|
|
$config = $sm->get('Configuration'); |
|
402
|
|
|
|
|
403
|
|
|
return new Options\ModuleOptions( |
|
404
|
|
|
isset($config['playgroundgame']) ? $config['playgroundgame'] : array() |
|
405
|
|
|
); |
|
406
|
|
|
}, |
|
407
|
|
|
|
|
408
|
|
|
'playgroundgame_game_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
409
|
|
|
$mapper = new \PlaygroundGame\Mapper\Game( |
|
410
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
411
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
412
|
|
|
); |
|
413
|
|
|
|
|
414
|
|
|
return $mapper; |
|
415
|
|
|
}, |
|
416
|
|
|
|
|
417
|
|
|
'playgroundgame_playerform_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
418
|
|
|
$mapper = new \PlaygroundGame\Mapper\PlayerForm( |
|
419
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
420
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
421
|
|
|
); |
|
422
|
|
|
|
|
423
|
|
|
return $mapper; |
|
424
|
|
|
}, |
|
425
|
|
|
|
|
426
|
|
|
'playgroundgame_lottery_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
427
|
|
|
$mapper = new \PlaygroundGame\Mapper\Lottery( |
|
428
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
429
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
430
|
|
|
); |
|
431
|
|
|
|
|
432
|
|
|
return $mapper; |
|
433
|
|
|
}, |
|
434
|
|
|
|
|
435
|
|
|
'playgroundgame_instantwin_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
436
|
|
|
$mapper = new \PlaygroundGame\Mapper\InstantWin( |
|
437
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
438
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
439
|
|
|
); |
|
440
|
|
|
|
|
441
|
|
|
return $mapper; |
|
442
|
|
|
}, |
|
443
|
|
|
|
|
444
|
|
|
'playgroundgame_instantwinoccurrence_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
445
|
|
|
$mapper = new \PlaygroundGame\Mapper\InstantWinOccurrence( |
|
446
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
447
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
448
|
|
|
); |
|
449
|
|
|
|
|
450
|
|
|
return $mapper; |
|
451
|
|
|
}, |
|
452
|
|
|
|
|
453
|
|
|
'playgroundgame_quiz_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
454
|
|
|
$mapper = new \PlaygroundGame\Mapper\Quiz( |
|
455
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
456
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
457
|
|
|
); |
|
458
|
|
|
|
|
459
|
|
|
return $mapper; |
|
460
|
|
|
}, |
|
461
|
|
|
|
|
462
|
|
|
'playgroundgame_quizquestion_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
463
|
|
|
$mapper = new \PlaygroundGame\Mapper\QuizQuestion( |
|
464
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
465
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
466
|
|
|
); |
|
467
|
|
|
|
|
468
|
|
|
return $mapper; |
|
469
|
|
|
}, |
|
470
|
|
|
|
|
471
|
|
|
'playgroundgame_quizanswer_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
472
|
|
|
$mapper = new \PlaygroundGame\Mapper\QuizAnswer( |
|
473
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
474
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
475
|
|
|
); |
|
476
|
|
|
|
|
477
|
|
|
return $mapper; |
|
478
|
|
|
}, |
|
479
|
|
|
|
|
480
|
|
|
'playgroundgame_quizreply_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
481
|
|
|
$mapper = new \PlaygroundGame\Mapper\QuizReply( |
|
482
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
483
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
484
|
|
|
); |
|
485
|
|
|
|
|
486
|
|
|
return $mapper; |
|
487
|
|
|
}, |
|
488
|
|
|
|
|
489
|
|
|
'playgroundgame_quizreplyanswer_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
490
|
|
|
$mapper = new \PlaygroundGame\Mapper\QuizReplyAnswer( |
|
491
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
492
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
493
|
|
|
); |
|
494
|
|
|
|
|
495
|
|
|
return $mapper; |
|
496
|
|
|
}, |
|
497
|
|
|
|
|
498
|
|
|
|
|
499
|
|
|
'playgroundgame_entry_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
500
|
|
|
$mapper = new \PlaygroundGame\Mapper\Entry( |
|
501
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
502
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
503
|
|
|
); |
|
504
|
|
|
|
|
505
|
|
|
return $mapper; |
|
506
|
|
|
}, |
|
507
|
|
|
|
|
508
|
|
|
'playgroundgame_postvote_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
509
|
|
|
$mapper = new \PlaygroundGame\Mapper\PostVote( |
|
510
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
511
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
512
|
|
|
); |
|
513
|
|
|
|
|
514
|
|
|
return $mapper; |
|
515
|
|
|
}, |
|
516
|
|
|
|
|
517
|
|
|
'playgroundgame_postvoteform_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
518
|
|
|
$mapper = new \PlaygroundGame\Mapper\PostVoteForm( |
|
519
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
520
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
521
|
|
|
); |
|
522
|
|
|
|
|
523
|
|
|
return $mapper; |
|
524
|
|
|
}, |
|
525
|
|
|
|
|
526
|
|
|
'playgroundgame_postvotepost_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
527
|
|
|
$mapper = new \PlaygroundGame\Mapper\PostVotePost( |
|
528
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
529
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
530
|
|
|
); |
|
531
|
|
|
|
|
532
|
|
|
return $mapper; |
|
533
|
|
|
}, |
|
534
|
|
|
|
|
535
|
|
|
'playgroundgame_postvotepostelement_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
536
|
|
|
$mapper = new \PlaygroundGame\Mapper\PostVotePostElement( |
|
537
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
538
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
539
|
|
|
); |
|
540
|
|
|
|
|
541
|
|
|
return $mapper; |
|
542
|
|
|
}, |
|
543
|
|
|
|
|
544
|
|
|
'playgroundgame_postvotevote_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
545
|
|
|
$mapper = new \PlaygroundGame\Mapper\PostVoteVote( |
|
546
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
547
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
548
|
|
|
); |
|
549
|
|
|
|
|
550
|
|
|
return $mapper; |
|
551
|
|
|
}, |
|
552
|
|
|
|
|
553
|
|
|
'playgroundgame_prize_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
554
|
|
|
$mapper = new \PlaygroundGame\Mapper\Prize( |
|
555
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
556
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
557
|
|
|
); |
|
558
|
|
|
|
|
559
|
|
|
return $mapper; |
|
560
|
|
|
}, |
|
561
|
|
|
|
|
562
|
|
|
'playgroundgame_prizecategory_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
563
|
|
|
$mapper = new \PlaygroundGame\Mapper\PrizeCategory( |
|
564
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
565
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
566
|
|
|
); |
|
567
|
|
|
|
|
568
|
|
|
return $mapper; |
|
569
|
|
|
}, |
|
570
|
|
|
|
|
571
|
|
|
'playgroundgame_prizecategoryuser_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
572
|
|
|
$mapper = new \PlaygroundGame\Mapper\PrizeCategoryUser( |
|
573
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
574
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
575
|
|
|
); |
|
576
|
|
|
|
|
577
|
|
|
return $mapper; |
|
578
|
|
|
}, |
|
579
|
|
|
|
|
580
|
|
|
'playgroundgame_invitation_mapper' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
581
|
|
|
$mapper = new \PlaygroundGame\Mapper\Invitation( |
|
582
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
|
|
|
|
|
583
|
|
|
$sm->get('playgroundgame_module_options') |
|
|
|
|
|
|
584
|
|
|
); |
|
585
|
|
|
|
|
586
|
|
|
return $mapper; |
|
587
|
|
|
}, |
|
588
|
|
|
|
|
589
|
|
|
'playgroundgame_mission_mapper' => function ($sm) { |
|
590
|
|
|
$mapper = new Mapper\Mission( |
|
591
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
592
|
|
|
$sm->get('playgroundgame_module_options') |
|
593
|
|
|
); |
|
594
|
|
|
|
|
595
|
|
|
return $mapper; |
|
596
|
|
|
}, |
|
597
|
|
|
|
|
598
|
|
|
'playgroundgame_mission_game_mapper' => function ($sm) { |
|
599
|
|
|
$mapper = new Mapper\MissionGame( |
|
600
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
601
|
|
|
$sm->get('playgroundgame_module_options') |
|
602
|
|
|
); |
|
603
|
|
|
|
|
604
|
|
|
return $mapper; |
|
605
|
|
|
}, |
|
606
|
|
|
|
|
607
|
|
|
'playgroundgame_mission_game_condition_mapper' => function ($sm) { |
|
608
|
|
|
$mapper = new Mapper\MissionGameCondition( |
|
609
|
|
|
$sm->get('doctrine.entitymanager.orm_default'), |
|
610
|
|
|
$sm->get('playgroundgame_module_options') |
|
611
|
|
|
); |
|
612
|
|
|
|
|
613
|
|
|
return $mapper; |
|
614
|
|
|
}, |
|
615
|
|
|
|
|
616
|
|
|
'playgroundgame_mission_form' => function ($sm) { |
|
617
|
|
|
$translator = $sm->get('translator'); |
|
618
|
|
|
$form = new Form\Admin\Mission(null, $sm, $translator); |
|
619
|
|
|
$mission = new Entity\Mission(); |
|
620
|
|
|
$form->setInputFilter($mission->getInputFilter()); |
|
621
|
|
|
|
|
622
|
|
|
return $form; |
|
623
|
|
|
}, |
|
624
|
|
|
|
|
625
|
|
View Code Duplication |
'playgroundgame_mission_game_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
|
|
|
|
|
626
|
|
|
$translator = $sm->get('translator'); |
|
627
|
|
|
$form = new Form\Admin\MissionGameFieldset(null, $sm, $translator); |
|
|
|
|
|
|
628
|
|
|
$missionGame = new Entity\MissionGame(); |
|
629
|
|
|
$form->setInputFilter($missionGame->getInputFilter()); |
|
|
|
|
|
|
630
|
|
|
return $form; |
|
631
|
|
|
}, |
|
632
|
|
|
|
|
633
|
|
View Code Duplication |
'playgroundgame_game_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
|
|
|
|
|
634
|
|
|
$translator = $sm->get('translator'); |
|
635
|
|
|
$form = new Form\Admin\Game(null, $sm, $translator); |
|
|
|
|
|
|
636
|
|
|
$game = new Entity\Game(); |
|
637
|
|
|
$form->setInputFilter($game->getInputFilter()); |
|
638
|
|
|
|
|
639
|
|
|
return $form; |
|
640
|
|
|
}, |
|
641
|
|
|
|
|
642
|
|
|
'playgroundgame_register_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
643
|
|
|
$translator = $sm->get('translator'); |
|
644
|
|
|
$zfcUserOptions = $sm->get('zfcuser_module_options'); |
|
645
|
|
|
$form = new Form\Frontend\Register(null, $zfcUserOptions, $translator, $sm); |
|
|
|
|
|
|
646
|
|
|
$form->setInputFilter(new \ZfcUser\Form\RegisterFilter( |
|
647
|
|
|
new \ZfcUser\Validator\NoRecordExists(array( |
|
648
|
|
|
'mapper' => $sm->get('zfcuser_user_mapper'), |
|
649
|
|
|
'key' => 'email' |
|
650
|
|
|
)), |
|
651
|
|
|
new \ZfcUser\Validator\NoRecordExists(array( |
|
652
|
|
|
'mapper' => $sm->get('zfcuser_user_mapper'), |
|
653
|
|
|
'key' => 'username' |
|
654
|
|
|
)), |
|
655
|
|
|
$zfcUserOptions |
|
|
|
|
|
|
656
|
|
|
)); |
|
657
|
|
|
|
|
658
|
|
|
return $form; |
|
659
|
|
|
}, |
|
660
|
|
|
|
|
661
|
|
|
'playgroundgame_import_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
662
|
|
|
$translator = $sm->get('translator'); |
|
663
|
|
|
$form = new Form\Admin\Import(null, $sm, $translator); |
|
|
|
|
|
|
664
|
|
|
|
|
665
|
|
|
return $form; |
|
666
|
|
|
}, |
|
667
|
|
|
|
|
668
|
|
View Code Duplication |
'playgroundgame_lottery_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
|
|
|
|
|
669
|
|
|
$translator = $sm->get('translator'); |
|
670
|
|
|
$form = new Form\Admin\Lottery(null, $sm, $translator); |
|
|
|
|
|
|
671
|
|
|
$lottery = new Entity\Lottery(); |
|
672
|
|
|
$form->setInputFilter($lottery->getInputFilter()); |
|
673
|
|
|
|
|
674
|
|
|
return $form; |
|
675
|
|
|
}, |
|
676
|
|
|
|
|
677
|
|
View Code Duplication |
'playgroundgame_quiz_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
|
|
|
|
|
678
|
|
|
$translator = $sm->get('translator'); |
|
679
|
|
|
$form = new Form\Admin\Quiz(null, $sm, $translator); |
|
|
|
|
|
|
680
|
|
|
$quiz = new Entity\Quiz(); |
|
681
|
|
|
$form->setInputFilter($quiz->getInputFilter()); |
|
682
|
|
|
|
|
683
|
|
|
return $form; |
|
684
|
|
|
}, |
|
685
|
|
|
|
|
686
|
|
View Code Duplication |
'playgroundgame_instantwin_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
|
|
|
|
|
687
|
|
|
$translator = $sm->get('translator'); |
|
688
|
|
|
$form = new Form\Admin\InstantWin(null, $sm, $translator); |
|
|
|
|
|
|
689
|
|
|
$instantwin = new Entity\InstantWin(); |
|
690
|
|
|
$form->setInputFilter($instantwin->getInputFilter()); |
|
691
|
|
|
|
|
692
|
|
|
return $form; |
|
693
|
|
|
}, |
|
694
|
|
|
|
|
695
|
|
View Code Duplication |
'playgroundgame_quizquestion_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
|
|
|
|
|
696
|
|
|
$translator = $sm->get('translator'); |
|
697
|
|
|
$form = new Form\Admin\QuizQuestion(null, $sm, $translator); |
|
|
|
|
|
|
698
|
|
|
$quizQuestion = new Entity\QuizQuestion(); |
|
699
|
|
|
$form->setInputFilter($quizQuestion->getInputFilter()); |
|
700
|
|
|
|
|
701
|
|
|
return $form; |
|
702
|
|
|
}, |
|
703
|
|
|
|
|
704
|
|
View Code Duplication |
'playgroundgame_instantwinoccurrence_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
|
|
|
|
|
705
|
|
|
$translator = $sm->get('translator'); |
|
706
|
|
|
$form = new Form\Admin\InstantWinOccurrence(null, $sm, $translator); |
|
|
|
|
|
|
707
|
|
|
$instantwinOccurrence = new Entity\InstantWinOccurrence(); |
|
708
|
|
|
$form->setInputFilter($instantwinOccurrence->getInputFilter()); |
|
709
|
|
|
|
|
710
|
|
|
return $form; |
|
711
|
|
|
}, |
|
712
|
|
|
|
|
713
|
|
|
'playgroundgame_instantwinoccurrenceimport_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
714
|
|
|
$translator = $sm->get('translator'); |
|
715
|
|
|
$form = new Form\Admin\InstantWinOccurrenceImport(null, $sm, $translator); |
|
|
|
|
|
|
716
|
|
|
return $form; |
|
717
|
|
|
}, |
|
718
|
|
|
|
|
719
|
|
|
'playgroundgame_instantwinoccurrencecode_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
720
|
|
|
$translator = $sm->get('translator'); |
|
721
|
|
|
$form = new Form\Frontend\InstantWinOccurrenceCode(null, $sm, $translator); |
|
|
|
|
|
|
722
|
|
|
$filter = new Form\Frontend\InstantWinOccurrenceCodeFilter(); |
|
723
|
|
|
$form->setInputFilter($filter); |
|
724
|
|
|
return $form; |
|
725
|
|
|
}, |
|
726
|
|
|
|
|
727
|
|
View Code Duplication |
'playgroundgame_postvote_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
|
|
|
|
|
728
|
|
|
$translator = $sm->get('translator'); |
|
729
|
|
|
$form = new Form\Admin\PostVote(null, $sm, $translator); |
|
|
|
|
|
|
730
|
|
|
$postVote = new Entity\PostVote(); |
|
731
|
|
|
$form->setInputFilter($postVote->getInputFilter()); |
|
732
|
|
|
|
|
733
|
|
|
return $form; |
|
734
|
|
|
}, |
|
735
|
|
|
|
|
736
|
|
View Code Duplication |
'playgroundgame_prizecategory_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
|
|
|
|
|
737
|
|
|
$translator = $sm->get('translator'); |
|
738
|
|
|
$form = new Form\Admin\PrizeCategory(null, $sm, $translator); |
|
|
|
|
|
|
739
|
|
|
$prizeCategory = new Entity\PrizeCategory(); |
|
740
|
|
|
$form->setInputFilter($prizeCategory->getInputFilter()); |
|
741
|
|
|
|
|
742
|
|
|
return $form; |
|
743
|
|
|
}, |
|
744
|
|
|
|
|
745
|
|
|
'playgroundgame_prizecategoryuser_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
746
|
|
|
$translator = $sm->get('translator'); |
|
747
|
|
|
$form = new Form\Frontend\PrizeCategoryUser(null, $sm, $translator); |
|
|
|
|
|
|
748
|
|
|
|
|
749
|
|
|
return $form; |
|
750
|
|
|
}, |
|
751
|
|
|
|
|
752
|
|
|
'playgroundgame_sharemail_form' => function (\Zend\ServiceManager\ServiceManager $sm) { |
|
753
|
|
|
$translator = $sm->get('translator'); |
|
754
|
|
|
$form = new Form\Frontend\ShareMail(null, $sm, $translator); |
|
|
|
|
|
|
755
|
|
|
$form->setInputFilter(new Form\Frontend\ShareMailFilter()); |
|
756
|
|
|
|
|
757
|
|
|
return $form; |
|
758
|
|
|
}, |
|
759
|
|
|
), |
|
760
|
|
|
); |
|
761
|
|
|
} |
|
762
|
|
|
} |
|
763
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: