1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PlaygroundGame\Controller\Frontend; |
4
|
|
|
|
5
|
|
|
use Zend\Form\Form; |
6
|
|
|
|
7
|
|
|
class PostVoteController extends GameController |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var gameService |
11
|
|
|
*/ |
12
|
|
|
protected $gameService; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* --DONE-- 1. try to change the Game Id (on le redirige vers la home du jeu) |
16
|
|
|
* --DONE-- 2. try to modify questions (the form is recreated and verified in the controller) |
17
|
|
|
* --DONE-- 3. don't answer to questions (form is checked controller side) |
18
|
|
|
* 4. try to game the chrono |
19
|
|
|
* 5. try to play again |
20
|
|
|
* 6. try to change answers |
21
|
|
|
* --DONE-- 7. essaie de répondre sans être inscrit (on le redirige vers la home du jeu) |
22
|
|
|
*/ |
23
|
|
|
public function playAction() |
24
|
|
|
{ |
25
|
|
|
$sg = $this->getGameService(); |
26
|
|
|
|
27
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
28
|
|
|
$channel = $this->getEvent()->getRouteMatch()->getParam('channel'); |
29
|
|
|
|
30
|
|
|
$game = $sg->checkGame($identifier); |
31
|
|
|
if (! $game || $game->isClosed()) { |
32
|
|
|
return $this->notFoundAction(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$redirectFb = $this->checkFbRegistration($this->zfcUserAuthentication()->getIdentity(), $game, $channel); |
|
|
|
|
36
|
|
|
if ($redirectFb) { |
37
|
|
|
return $redirectFb; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
41
|
|
|
|
42
|
|
View Code Duplication |
if (!$user && !$game->getAnonymousAllowed()) { |
|
|
|
|
43
|
|
|
$redirect = urlencode( |
44
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
45
|
|
|
$game->getClassType() . '/play', |
46
|
|
|
array('id' => $game->getIdentifier(), 'channel' => $channel), |
47
|
|
|
array('force_canonical' => true) |
48
|
|
|
) |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
return $this->redirect()->toUrl( |
52
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
53
|
|
|
'zfcuser/register', |
54
|
|
|
array('channel' => $channel) |
55
|
|
|
) . '?redirect='.$redirect |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$entry = $sg->play($game, $user); |
60
|
|
|
|
61
|
|
|
if (!$entry) { |
62
|
|
|
$lastEntry = $sg->findLastInactiveEntry($game, $user); |
63
|
|
|
if ($lastEntry === null) { |
64
|
|
|
return $this->redirect()->toUrl( |
65
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
66
|
|
|
'postvote', |
67
|
|
|
array( |
68
|
|
|
'id' => $identifier, |
69
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
70
|
|
|
) |
71
|
|
|
) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$lastEntryId = $lastEntry->getId(); |
76
|
|
|
$lastPost = $sg->getPostVotePostMapper()->findOneBy(array('entry' => $lastEntryId)); |
77
|
|
|
$postId = $lastPost->getId(); |
78
|
|
|
if ($lastPost->getStatus() == 2) { |
79
|
|
|
// the user has already taken part of this game and the participation limit has been reached |
80
|
|
|
$this->flashMessenger()->addMessage( |
81
|
|
|
$this->getServiceLocator()->get('translator')->translate('You have already a Post') |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
return $this->redirect()->toUrl( |
85
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
86
|
|
|
'postvote/post', |
87
|
|
|
array( |
88
|
|
|
'id' => $identifier, |
89
|
|
|
'post' => $postId, |
90
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
91
|
|
|
) |
92
|
|
|
) |
93
|
|
|
); |
94
|
|
|
} else { |
95
|
|
|
$this->flashMessenger()->addMessage( |
96
|
|
|
$this->getServiceLocator()->get('translator')->translate('Your Post is waiting for validation') |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
return $this->redirect()->toUrl( |
100
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
101
|
|
|
'postvote/post', |
102
|
|
|
array( |
103
|
|
|
'id' => $identifier, |
104
|
|
|
'post' => $postId, |
105
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
106
|
|
|
) |
107
|
|
|
) |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
if (! $game->getForm()) { |
113
|
|
|
return $this->redirect()->toUrl( |
114
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
115
|
|
|
'postvote', |
116
|
|
|
array( |
117
|
|
|
'id' => $identifier, |
118
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
119
|
|
|
) |
120
|
|
|
) |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$form = $sg->createFormFromJson($game->getForm()->getForm(), 'postvoteForm'); |
125
|
|
|
|
126
|
|
|
// Je recherche le post associé à entry + status == 0. Si non trouvé, je redirige vers home du jeu. |
127
|
|
|
$post = $sg->getPostVotePostMapper()->findOneBy(array('entry' => $entry, 'status' => 0)); |
128
|
|
|
if ($post) { |
129
|
|
|
foreach ($post->getPostElements() as $element) { |
130
|
|
|
try { |
131
|
|
|
$form->get($element->getName())->setValue($element->getValue()); |
132
|
|
|
|
133
|
|
|
$elementType = $form->get($element->getName())->getAttribute('type'); |
134
|
|
|
if ($elementType == 'file' && $element->getValue() != '') { |
135
|
|
|
$filter = $form->getInputFilter(); |
136
|
|
|
$elementInput = $filter->get($element->getName()); |
137
|
|
|
$elementInput->setRequired(false); |
138
|
|
|
$form->get($element->getName())->setAttribute('required', false); |
139
|
|
|
} |
140
|
|
|
} catch (\Zend\Form\Exception\InvalidElementException $e) { |
|
|
|
|
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$viewModel = $this->buildView($game); |
146
|
|
|
|
147
|
|
|
if ($this->getRequest()->isPost()) { |
|
|
|
|
148
|
|
|
// POST Request: Process form |
149
|
|
|
$data = array_merge_recursive( |
150
|
|
|
$this->getRequest()->getPost()->toArray(), |
|
|
|
|
151
|
|
|
$this->getRequest()->getFiles()->toArray() |
|
|
|
|
152
|
|
|
); |
153
|
|
|
|
154
|
|
|
$form->setData($data); |
155
|
|
|
|
156
|
|
|
if ($form->isValid()) { |
157
|
|
|
$data = $form->getData(); |
158
|
|
|
$post = $this->getGameService()->createPost($data, $game, $user, $form); |
159
|
|
|
|
160
|
|
|
if ($post && !empty($game->nextStep('play'))) { |
161
|
|
|
// determine the route where the user should go |
162
|
|
|
$redirectUrl = $this->frontendUrl()->fromRoute( |
|
|
|
|
163
|
|
|
'postvote/'.$game->nextStep('play'), |
164
|
|
|
array( |
165
|
|
|
'id' => $game->getIdentifier(), |
166
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
167
|
|
|
) |
168
|
|
|
); |
169
|
|
|
|
170
|
|
|
return $this->redirect()->toUrl($redirectUrl); |
171
|
|
|
} |
172
|
|
|
} else { |
173
|
|
|
$messages = $form->getMessages(); |
174
|
|
|
$viewModel = $this->buildView($game); |
175
|
|
|
$viewModel->setVariables(array( |
|
|
|
|
176
|
|
|
'success' => false, |
177
|
|
|
'message' => implode(',', $messages['title']), |
178
|
|
|
)); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$viewModel->setVariables(array( |
183
|
|
|
'playerData' => $entry->getPlayerData(), |
184
|
|
|
'form' => $form, |
185
|
|
|
'post' => $post, |
186
|
|
|
)); |
187
|
|
|
|
188
|
|
|
return $viewModel; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function previewAction() |
192
|
|
|
{ |
193
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
194
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
195
|
|
|
$sg = $this->getGameService(); |
196
|
|
|
|
197
|
|
|
$game = $sg->checkGame($identifier); |
198
|
|
|
if (! $game) { |
199
|
|
|
return $this->notFoundAction(); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
$entry = $sg->findLastActiveEntry($game, $user); |
203
|
|
|
|
204
|
|
|
if (!$entry) { |
205
|
|
|
// the user has already taken part of this game and the participation limit has been reached |
206
|
|
|
return $this->redirect()->toUrl( |
207
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
208
|
|
|
'postvote/'.$game->nextStep('preview'), |
209
|
|
|
array( |
210
|
|
|
'id' => $identifier, |
211
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
212
|
|
|
) |
213
|
|
|
) |
214
|
|
|
); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
// Je recherche le post associé à entry + status == 0. Si non trouvé, je redirige vers home du jeu. |
218
|
|
|
$post = $sg->getPostVotePostMapper()->findOneBy(array('entry' => $entry, 'status' => 0)); |
219
|
|
|
|
220
|
|
|
if (! $post) { |
221
|
|
|
return $this->redirect()->toUrl( |
222
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
223
|
|
|
'postvote', |
224
|
|
|
array( |
225
|
|
|
'id' => $identifier, |
226
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
227
|
|
|
) |
228
|
|
|
) |
229
|
|
|
); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
if ($this->getRequest()->isPost()) { |
|
|
|
|
233
|
|
|
$post = $this->getGameService()->confirmPost($game, $user); |
234
|
|
|
|
235
|
|
|
if ($post) { |
236
|
|
|
if (!($step = $game->nextStep('play'))) { |
237
|
|
|
$step = 'result'; |
238
|
|
|
} |
239
|
|
|
$redirectUrl = $this->frontendUrl()->fromRoute( |
|
|
|
|
240
|
|
|
'postvote/'.$step, |
241
|
|
|
array( |
242
|
|
|
'id' => $game->getIdentifier(), |
243
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
244
|
|
|
) |
245
|
|
|
); |
246
|
|
|
|
247
|
|
|
return $this->redirect()->toUrl($redirectUrl); |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
$viewModel = $this->buildView($game); |
252
|
|
|
$viewModel->setVariables(array('post' => $post)); |
|
|
|
|
253
|
|
|
|
254
|
|
|
return $viewModel; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* View the Post page |
259
|
|
|
* @return multitype:|\Zend\Http\Response|\Zend\View\Model\ViewModel |
|
|
|
|
260
|
|
|
*/ |
261
|
|
|
public function postAction() |
262
|
|
|
{ |
263
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
264
|
|
|
$postId = $this->getEvent()->getRouteMatch()->getParam('post'); |
265
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
266
|
|
|
$sg = $this->getGameService(); |
267
|
|
|
$voted = false; |
268
|
|
|
|
269
|
|
|
$statusMail = false; |
270
|
|
|
$mailService = $this->getServiceLocator()->get('playgroundgame_message'); |
271
|
|
|
$to = ''; |
272
|
|
|
$skinUrl = $sg->getServiceManager()->get('ViewRenderer')->url( |
273
|
|
|
'frontend', |
274
|
|
|
array( |
275
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
276
|
|
|
), |
277
|
|
|
array('force_canonical' => true) |
278
|
|
|
); |
279
|
|
|
$config = $this->getGameService()->getServiceManager()->get('config'); |
280
|
|
|
if (isset($config['moderation']['email'])) { |
281
|
|
|
$to = $config['moderation']['email']; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
$game = $sg->checkGame($identifier, false); |
285
|
|
|
|
286
|
|
|
if (! $postId) { |
287
|
|
|
return $this->notFoundAction(); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
// Je recherche le post associé à entry + status == 0. Si non trouvé, je redirige vers home du jeu. |
291
|
|
|
$post = $sg->getPostVotePostMapper()->findById($postId); |
292
|
|
|
|
293
|
|
|
if (! $post || $post->getStatus() === 9) { |
294
|
|
|
return $this->redirect()->toUrl( |
295
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
296
|
|
|
'postvote', |
297
|
|
|
array( |
298
|
|
|
'id' => $identifier, |
299
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
300
|
|
|
) |
301
|
|
|
) |
302
|
|
|
); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
$formModeration = new Form(); |
306
|
|
|
$formModeration->setAttribute('method', 'post'); |
307
|
|
|
|
308
|
|
|
$formModeration->add(array( |
309
|
|
|
'name' => 'moderation', |
310
|
|
|
'attributes' => array( |
311
|
|
|
'type' => 'hidden', |
312
|
|
|
'value' => '1' |
313
|
|
|
), |
314
|
|
|
)); |
315
|
|
|
|
316
|
|
|
$form = new \PlaygroundGame\Form\Frontend\PostVoteVote( |
317
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
318
|
|
|
'postvote/post/captcha', |
319
|
|
|
array( |
320
|
|
|
'id' => $identifier, |
321
|
|
|
'post' => $postId, |
322
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
323
|
|
|
) |
324
|
|
|
) |
325
|
|
|
); |
326
|
|
|
|
327
|
|
|
if ($user) { |
328
|
|
|
$form->remove('captcha'); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
$alreadyVoted = ''; |
332
|
|
|
$reportId = ''; |
333
|
|
|
|
334
|
|
|
$request = $this->getRequest(); |
335
|
|
|
if ($request->isPost()) { |
336
|
|
|
$data = $request->getPost()->toArray(); |
337
|
|
|
if (isset($data['moderation'])) { |
338
|
|
|
$formModeration->setData($data); |
339
|
|
|
if ($formModeration->isValid()) { |
340
|
|
|
$from = $to; |
341
|
|
|
$subject= 'Moderation Post and Vote'; |
342
|
|
|
$result = $mailService->createHtmlMessage( |
343
|
|
|
$from, |
344
|
|
|
$to, |
345
|
|
|
$subject, |
346
|
|
|
'playground-game/email/moderation', |
347
|
|
|
array('data' => $data, 'skinUrl' => $skinUrl) |
348
|
|
|
); |
349
|
|
|
$mailService->send($result); |
350
|
|
|
if ($result) { |
351
|
|
|
$statusMail = true; |
352
|
|
|
$reportId = $data['reportid']; |
353
|
|
|
} |
354
|
|
|
} |
355
|
|
|
} else { |
356
|
|
|
$form->setData($request->getPost()); |
357
|
|
|
if ($form->isValid()) { |
358
|
|
|
if ($sg->addVote($user, $this->getRequest()->getServer('REMOTE_ADDR'), $post)) { |
|
|
|
|
359
|
|
|
$voted = true; |
360
|
|
|
} else { |
361
|
|
|
$alreadyVoted = 'Vous avez déjà voté!'; |
362
|
|
|
} |
363
|
|
|
} |
364
|
|
|
} |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
$viewModel = $this->buildView($game); |
368
|
|
|
$viewModel->setVariables( |
|
|
|
|
369
|
|
|
array( |
370
|
|
|
'post' => $post, |
371
|
|
|
'voted' => $voted, |
372
|
|
|
'form' => $form, |
373
|
|
|
'formModeration' => $formModeration, |
374
|
|
|
'statusMail' => $statusMail, |
375
|
|
|
'alreadyVoted' => $alreadyVoted, |
376
|
|
|
'reportId' => $reportId, |
377
|
|
|
) |
378
|
|
|
); |
379
|
|
|
|
380
|
|
|
return $viewModel; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* |
385
|
|
|
*/ |
386
|
|
|
public function resultAction() |
387
|
|
|
{ |
388
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
389
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
390
|
|
|
$channel = $this->getEvent()->getRouteMatch()->getParam('channel'); |
391
|
|
|
|
392
|
|
|
$statusMail = null; |
393
|
|
|
|
394
|
|
|
if (!$identifier) { |
395
|
|
|
return $this->notFoundAction(); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
$postVoteMapper = $this->getGameService()->getPostVoteMapper(); |
399
|
|
|
$game = $postVoteMapper->findByIdentifier($identifier); |
400
|
|
|
|
401
|
|
|
if (!$game || $game->isClosed()) { |
402
|
|
|
return $this->notFoundAction(); |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
// Has the user finished the game ? |
406
|
|
|
$lastEntry = $this->getGameService()->findLastInactiveEntry($game, $user); |
407
|
|
|
|
408
|
|
|
if ($lastEntry === null) { |
409
|
|
|
return $this->redirect()->toUrl( |
410
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
411
|
|
|
'postvote', |
412
|
|
|
array( |
413
|
|
|
'id' => $identifier, |
414
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
415
|
|
|
) |
416
|
|
|
) |
417
|
|
|
); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
View Code Duplication |
if (!$user && !$game->getAnonymousAllowed()) { |
|
|
|
|
421
|
|
|
$redirect = urlencode( |
422
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
423
|
|
|
'postvote/result', |
424
|
|
|
array( |
425
|
|
|
'id' => $game->getIdentifier(), |
426
|
|
|
'channel' => $channel |
427
|
|
|
) |
428
|
|
|
) |
429
|
|
|
); |
430
|
|
|
return $this->redirect()->toUrl( |
431
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
432
|
|
|
'zfcuser/register', |
433
|
|
|
array('channel' => $channel) |
434
|
|
|
) . '?redirect='.$redirect |
435
|
|
|
); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
$form = $this->getServiceLocator()->get('playgroundgame_sharemail_form'); |
439
|
|
|
$form->setAttribute('method', 'post'); |
440
|
|
|
|
441
|
|
View Code Duplication |
if ($this->getRequest()->isPost()) { |
|
|
|
|
442
|
|
|
$data = $this->getRequest()->getPost()->toArray(); |
|
|
|
|
443
|
|
|
$form->setData($data); |
444
|
|
|
if ($form->isValid()) { |
445
|
|
|
$result = $this->getGameService()->sendShareMail($data, $game, $user, $lastEntry); |
446
|
|
|
if ($result) { |
447
|
|
|
$statusMail = true; |
448
|
|
|
} |
449
|
|
|
} |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
// Je recherche le post associé à entry + status == 0. Si non trouvé, je redirige vers home du jeu. |
453
|
|
|
$post = $this->getGameService()->getPostVotePostMapper()->findOneBy(array('entry' => $lastEntry)); |
454
|
|
|
|
455
|
|
|
if (! $post) { |
456
|
|
|
return $this->redirect()->toUrl( |
457
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
458
|
|
|
'postvote', |
459
|
|
|
array( |
460
|
|
|
'id' => $identifier, |
461
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
462
|
|
|
) |
463
|
|
|
) |
464
|
|
|
); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
$viewModel = $this->buildView($game); |
468
|
|
|
|
469
|
|
|
$viewModel->setVariables(array( |
|
|
|
|
470
|
|
|
'statusMail' => $statusMail, |
471
|
|
|
'post' => $post, |
472
|
|
|
'form' => $form, |
473
|
|
|
)); |
474
|
|
|
|
475
|
|
|
return $viewModel; |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* Example of AJAX File Upload with Session Progress and partial validation. |
480
|
|
|
* It's now possible to send a base64 image in this case the call is the form : |
481
|
|
|
* this._ajax( |
482
|
|
|
* { |
483
|
|
|
* url: url.dataset.url, |
484
|
|
|
* method: 'post', |
485
|
|
|
* body: 'photo=' + image |
486
|
|
|
* }, |
487
|
|
|
* |
488
|
|
|
* @return \Zend\Stdlib\ResponseInterface |
489
|
|
|
*/ |
490
|
|
|
public function ajaxuploadAction() |
491
|
|
|
{ |
492
|
|
|
// Call this for the session lock to be released (other ajax calls can then be made) |
493
|
|
|
session_write_close(); |
494
|
|
|
|
495
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
496
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
497
|
|
|
$sg = $this->getGameService(); |
498
|
|
|
$request = $this->getRequest(); |
499
|
|
|
$response = $this->getResponse(); |
500
|
|
|
|
501
|
|
|
$game = $sg->checkGame($identifier); |
502
|
|
|
if (! $game) { |
503
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
504
|
|
|
'success' => 0 |
505
|
|
|
))); |
506
|
|
|
|
507
|
|
|
return $response; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
$entry = $sg->findLastActiveEntry($game, $user); |
511
|
|
|
if (!$entry) { |
512
|
|
|
// the user has already taken part of this game and the participation limit has been reached |
513
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
514
|
|
|
'success' => 0 |
515
|
|
|
))); |
516
|
|
|
|
517
|
|
|
return $response; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
if ($request->isPost()) { |
521
|
|
|
$data = $this->getRequest()->getFiles()->toArray(); |
|
|
|
|
522
|
|
|
|
523
|
|
|
if (empty($data)) { |
524
|
|
|
$data = $this->getRequest()->getPost()->toArray(); |
|
|
|
|
525
|
|
|
|
526
|
|
|
$key = key($data); |
527
|
|
|
|
528
|
|
|
$uploadImage = array('name' => $key.'.png', 'error' => 0, 'base64' => $data[$key]); |
529
|
|
|
$data = array($key => $uploadImage); |
530
|
|
|
} |
531
|
|
|
$uploadFile = $sg->uploadFileToPost($data, $game, $user); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
535
|
|
|
'success' => true, |
536
|
|
|
'fileUrl' => $uploadFile |
|
|
|
|
537
|
|
|
))); |
538
|
|
|
|
539
|
|
|
return $response; |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
public function ajaxdeleteAction() |
543
|
|
|
{ |
544
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
545
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
546
|
|
|
$sg = $this->getGameService(); |
547
|
|
|
$request = $this->getRequest(); |
548
|
|
|
$response = $this->getResponse(); |
549
|
|
|
|
550
|
|
|
$game = $sg->checkGame($identifier); |
551
|
|
|
if (! $game) { |
552
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
553
|
|
|
'success' => 0 |
554
|
|
|
))); |
555
|
|
|
|
556
|
|
|
return $response; |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
$entry = $sg->findLastActiveEntry($game, $user); |
560
|
|
|
if (!$entry) { |
561
|
|
|
// the user has already taken part of this game and the participation limit has been reached |
562
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
563
|
|
|
'success' => 0 |
564
|
|
|
))); |
565
|
|
|
|
566
|
|
|
return $response; |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
if ($request->isPost()) { |
570
|
|
|
$data = $request->getPost()->toArray(); |
571
|
|
|
$sg->deleteFilePosted($data, $game, $user); |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
575
|
|
|
'success' => true, |
576
|
|
|
))); |
577
|
|
|
|
578
|
|
|
return $response; |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
public function listAction() |
582
|
|
|
{ |
583
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
584
|
|
|
$filter = $this->getEvent()->getRouteMatch()->getParam('filter'); |
585
|
|
|
$search = $this->params()->fromQuery('name'); |
586
|
|
|
$sg = $this->getGameService(); |
587
|
|
|
$postId = $this->params()->fromQuery('id'); |
588
|
|
|
|
589
|
|
|
$statusMail = false; |
590
|
|
|
$mailService = $this->getServiceLocator()->get('playgroundgame_message'); |
591
|
|
|
$to = ''; |
592
|
|
|
$skinUrl = $sg->getServiceManager()->get('ViewRenderer')->url( |
593
|
|
|
'frontend', |
594
|
|
|
array('channel' => $this->getEvent()->getRouteMatch()->getParam('channel')), |
595
|
|
|
array('force_canonical' => true) |
596
|
|
|
); |
597
|
|
|
$config = $this->getGameService()->getServiceManager()->get('config'); |
598
|
|
|
if (isset($config['moderation']['email'])) { |
599
|
|
|
$to = $config['moderation']['email']; |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
$request = $this->getRequest(); |
603
|
|
|
|
604
|
|
|
$game = $sg->checkGame($identifier, false); |
605
|
|
|
|
606
|
|
|
// Je recherche les posts validés associés à ce jeu |
607
|
|
|
$posts = $sg->findArrayOfValidatedPosts($game, $filter, $search); |
608
|
|
|
|
609
|
|
|
if (is_array($posts)) { |
610
|
|
|
$paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($posts)); |
611
|
|
|
$paginator->setItemCountPerPage($game->getPostDisplayNumber()); |
612
|
|
|
$paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p')); |
613
|
|
|
} else { |
614
|
|
|
$paginator = $posts; |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
$form = new Form(); |
618
|
|
|
$form->setAttribute('method', 'post'); |
619
|
|
|
|
620
|
|
|
$form->add(array( |
621
|
|
|
'name' => 'moderation', |
622
|
|
|
'attributes' => array( |
623
|
|
|
'type' => 'hidden', |
624
|
|
|
'value' => '1' |
625
|
|
|
), |
626
|
|
|
)); |
627
|
|
|
|
628
|
|
|
$reportId =''; |
629
|
|
|
|
630
|
|
|
if ($request->isPost()) { |
631
|
|
|
$data = $request->getPost()->toArray(); |
632
|
|
|
|
633
|
|
|
if (isset($data['moderation'])) { |
634
|
|
|
$from = $to; |
635
|
|
|
$subject= 'Moderation Post and Vote'; |
636
|
|
|
$result = $mailService->createHtmlMessage( |
637
|
|
|
$from, |
638
|
|
|
$to, |
639
|
|
|
$subject, |
640
|
|
|
'playground-game/email/moderation', |
641
|
|
|
array('data' => $data, 'skinUrl' => $skinUrl) |
642
|
|
|
); |
643
|
|
|
$mailService->send($result); |
644
|
|
|
if ($result) { |
645
|
|
|
$statusMail = true; |
646
|
|
|
$reportId = $data['reportid']; |
647
|
|
|
} |
648
|
|
|
} |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
$viewModel = $this->buildView($game); |
652
|
|
|
|
653
|
|
|
if ($postId) { |
654
|
|
|
$postTarget = $sg->getPostVotePostMapper()->findById($postId); |
655
|
|
|
if ($postTarget) { |
656
|
|
View Code Duplication |
foreach ($postTarget->getPostElements() as $element) { |
|
|
|
|
657
|
|
|
$fbShareImage = $this->frontendUrl()->fromRoute( |
|
|
|
|
658
|
|
|
'', |
659
|
|
|
array('channel' => ''), |
660
|
|
|
array('force_canonical' => true), |
661
|
|
|
false |
662
|
|
|
) . $element->getValue(); |
663
|
|
|
break; |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
$secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15)); |
667
|
|
|
|
668
|
|
|
// Without bit.ly shortener |
669
|
|
|
$socialLinkUrl = $this->frontendUrl()->fromRoute( |
|
|
|
|
670
|
|
|
'postvote/list', |
671
|
|
|
array( |
672
|
|
|
'id' => $game->getIdentifier(), |
673
|
|
|
'filter' => 'date', |
674
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
675
|
|
|
), |
676
|
|
|
array('force_canonical' => true) |
677
|
|
|
).'?id='.$postTarget->getId().'&key='.$secretKey; |
678
|
|
|
// With core shortener helper |
679
|
|
|
$socialLinkUrl = $this->shortenUrl()->shortenUrl($socialLinkUrl); |
|
|
|
|
680
|
|
|
|
681
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('og:image', $fbShareImage); |
|
|
|
|
682
|
|
|
|
683
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:card', "photo"); |
684
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:site', "@alfie_selfie"); |
685
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:title', $game->getTwShareMessage()); |
686
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:description', ""); |
687
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:image', $fbShareImage); |
688
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:url', $socialLinkUrl); |
689
|
|
|
} |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
$viewModel->setVariables(array( |
|
|
|
|
693
|
|
|
'posts' => $paginator, |
694
|
|
|
'form' => $form, |
695
|
|
|
'statusMail' => $statusMail, |
696
|
|
|
'reportId' => $reportId, |
697
|
|
|
'filter' => $filter, |
698
|
|
|
'search' => $search, |
699
|
|
|
)); |
700
|
|
|
|
701
|
|
|
return $viewModel; |
702
|
|
|
} |
703
|
|
|
|
704
|
|
|
public function ajaxVoteAction() |
705
|
|
|
{ |
706
|
|
|
// Call this for the session lock to be released (other ajax calls can then be made) |
707
|
|
|
session_write_close(); |
708
|
|
|
|
709
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
710
|
|
|
$postId = $this->getEvent()->getRouteMatch()->getParam('post'); |
711
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
712
|
|
|
$sg = $this->getGameService(); |
713
|
|
|
|
714
|
|
|
$game = $sg->checkGame($identifier); |
715
|
|
|
if (! $game) { |
716
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
|
|
|
|
717
|
|
|
'success' => 0 |
718
|
|
|
))); |
719
|
|
|
|
720
|
|
|
return $response; |
|
|
|
|
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
$request = $this->getRequest(); |
724
|
|
|
$response = $this->getResponse(); |
725
|
|
|
|
726
|
|
|
if (!$this->zfcUserAuthentication()->hasIdentity()) { |
|
|
|
|
727
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
728
|
|
|
'success' => 0 |
729
|
|
|
))); |
730
|
|
|
} else { |
731
|
|
|
if ($request->isPost()) { |
732
|
|
|
$post = $sg->getPostvotePostMapper()->findById($postId); |
733
|
|
|
if ($sg->addVote($user, $this->getRequest()->getServer('REMOTE_ADDR'), $post)) { |
|
|
|
|
734
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
735
|
|
|
'success' => 1 |
736
|
|
|
))); |
737
|
|
|
} else { |
738
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
739
|
|
|
'success' => 0 |
740
|
|
|
))); |
741
|
|
|
} |
742
|
|
|
} |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
return $response; |
746
|
|
|
} |
747
|
|
|
|
748
|
|
|
public function captchaAction() |
749
|
|
|
{ |
750
|
|
|
$response = $this->getResponse(); |
751
|
|
|
$response->getHeaders()->addHeaderLine('Content-Type', "image/png"); |
752
|
|
|
|
753
|
|
|
$id = $this->params('id', false); |
754
|
|
|
|
755
|
|
|
if ($id) { |
756
|
|
|
$image = './data/captcha/' . $id; |
757
|
|
|
|
758
|
|
|
if (file_exists($image) !== false) { |
759
|
|
|
$imagegetcontent = file_get_contents($image); |
760
|
|
|
|
761
|
|
|
$response->setStatusCode(200); |
762
|
|
|
$response->setContent($imagegetcontent); |
763
|
|
|
|
764
|
|
|
if (file_exists($image) === true) { |
765
|
|
|
unlink($image); |
766
|
|
|
} |
767
|
|
|
} |
768
|
|
|
} |
769
|
|
|
|
770
|
|
|
return $response; |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
public function shareAction() |
774
|
|
|
{ |
775
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
776
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
777
|
|
|
$sg = $this->getGameService(); |
778
|
|
|
|
779
|
|
|
$statusMail = null; |
780
|
|
|
|
781
|
|
|
if (!$identifier) { |
782
|
|
|
return $this->notFoundAction(); |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
$gameMapper = $this->getGameService()->getGameMapper(); |
786
|
|
|
$game = $gameMapper->findByIdentifier($identifier); |
787
|
|
|
|
788
|
|
|
if (!$game || $game->isClosed()) { |
789
|
|
|
return $this->notFoundAction(); |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
// Has the user finished the game ? |
793
|
|
|
$lastEntry = $this->getGameService()->findLastInactiveEntry($game, $user); |
794
|
|
|
|
795
|
|
|
if ($lastEntry === null) { |
796
|
|
|
return $this->redirect()->toUrl( |
797
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
798
|
|
|
'postvote', |
799
|
|
|
array( |
800
|
|
|
'id' => $identifier, |
801
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
802
|
|
|
) |
803
|
|
|
) |
804
|
|
|
); |
805
|
|
|
} |
806
|
|
|
|
807
|
|
|
$post = $sg->getPostVotePostMapper()->findOneBy(array('entry' => $lastEntry)); |
808
|
|
|
|
809
|
|
|
$secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15)); |
810
|
|
|
$socialLinkUrl = $this->frontendUrl()->fromRoute( |
|
|
|
|
811
|
|
|
'postvote/post', |
812
|
|
|
array( |
813
|
|
|
'id' => $identifier, |
814
|
|
|
'post' => $post->getId(), |
815
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
816
|
|
|
), |
817
|
|
|
array('force_canonical' => true) |
818
|
|
|
).'?key='.$secretKey; |
819
|
|
|
// With core shortener helper |
820
|
|
|
$socialLinkUrl = $this->shortenUrl()->shortenUrl($socialLinkUrl); |
|
|
|
|
821
|
|
|
|
822
|
|
View Code Duplication |
if (!$user && !$game->getAnonymousAllowed()) { |
|
|
|
|
823
|
|
|
$redirect = urlencode( |
824
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
825
|
|
|
'postvote/result', |
826
|
|
|
array('id' => $game->getIdentifier(), 'channel' => $channel) |
|
|
|
|
827
|
|
|
) |
828
|
|
|
); |
829
|
|
|
return $this->redirect()->toUrl( |
830
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
831
|
|
|
'zfcuser/register', |
832
|
|
|
array('channel' => $channel) |
833
|
|
|
) . '?redirect='.$redirect |
834
|
|
|
); |
835
|
|
|
} |
836
|
|
|
|
837
|
|
|
$form = $this->getServiceLocator()->get('playgroundgame_sharemail_form'); |
838
|
|
|
$form->setAttribute('method', 'post'); |
839
|
|
|
|
840
|
|
View Code Duplication |
if ($this->getRequest()->isPost()) { |
|
|
|
|
841
|
|
|
$data = $this->getRequest()->getPost()->toArray(); |
|
|
|
|
842
|
|
|
$form->setData($data); |
843
|
|
|
if ($form->isValid()) { |
844
|
|
|
$result = $this->getGameService()->sendShareMail($data, $game, $user, $lastEntry); |
845
|
|
|
if ($result) { |
846
|
|
|
$statusMail = true; |
847
|
|
|
} |
848
|
|
|
} |
849
|
|
|
} |
850
|
|
|
|
851
|
|
|
$viewModel = $this->buildView($game); |
852
|
|
|
|
853
|
|
View Code Duplication |
foreach ($post->getPostElements() as $element) { |
|
|
|
|
854
|
|
|
$fbShareImage = $this->frontendUrl()->fromRoute( |
|
|
|
|
855
|
|
|
'', |
856
|
|
|
array('channel' => ''), |
857
|
|
|
array('force_canonical' => true), |
858
|
|
|
false |
859
|
|
|
) . $element->getValue(); |
860
|
|
|
break; |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
$secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15)); |
864
|
|
|
|
865
|
|
|
// Without bit.ly shortener |
866
|
|
|
$socialLinkUrl = $this->frontendUrl()->fromRoute( |
|
|
|
|
867
|
|
|
'postvote/list', |
868
|
|
|
array( |
869
|
|
|
'id' => $game->getIdentifier(), |
870
|
|
|
'filter' => 'date', |
871
|
|
|
'channel' => $this->getEvent()->getRouteMatch()->getParam('channel') |
872
|
|
|
), |
873
|
|
|
array('force_canonical' => true) |
874
|
|
|
).'?id='.$post->getId().'&key='.$secretKey; |
875
|
|
|
// With core shortener helper |
876
|
|
|
$socialLinkUrl = $this->shortenUrl()->shortenUrl($socialLinkUrl); |
|
|
|
|
877
|
|
|
|
878
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('og:image', $fbShareImage); |
|
|
|
|
879
|
|
|
|
880
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:card', "photo"); |
881
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:site', "@playground"); |
882
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:title', $game->getTwShareMessage()); |
883
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:description', ""); |
884
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:image', $fbShareImage); |
885
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:url', $socialLinkUrl); |
886
|
|
|
|
887
|
|
|
$viewModel->setVariables(array( |
|
|
|
|
888
|
|
|
'statusMail' => $statusMail, |
889
|
|
|
'form' => $form, |
890
|
|
|
'socialLinkUrl' => $socialLinkUrl, |
891
|
|
|
'post' => $post |
892
|
|
|
)); |
893
|
|
|
|
894
|
|
|
return $viewModel; |
895
|
|
|
} |
896
|
|
|
|
897
|
|
|
public function getGameService() |
898
|
|
|
{ |
899
|
|
|
if (!$this->gameService) { |
900
|
|
|
$this->gameService = $this->getServiceLocator()->get('playgroundgame_postvote_service'); |
|
|
|
|
901
|
|
|
} |
902
|
|
|
|
903
|
|
|
return $this->gameService; |
904
|
|
|
} |
905
|
|
|
} |
906
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: