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
|
|
|
|
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); |
|
|
|
|
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(), ), |
47
|
|
|
array('force_canonical' => true) |
48
|
|
|
) |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
return $this->redirect()->toUrl( |
52
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
53
|
|
|
'zfcuser/register', |
54
|
|
|
array() |
55
|
|
|
) . '?redirect='.$redirect |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$entry = $sg->play($game, $user); |
60
|
|
|
|
61
|
|
|
if (!$entry) { |
62
|
|
|
$lastEntry = $sg->findLastInactiveEntry($game, $user); |
63
|
|
View Code Duplication |
if ($lastEntry === null) { |
|
|
|
|
64
|
|
|
return $this->redirect()->toUrl( |
65
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
66
|
|
|
'postvote', |
67
|
|
|
array( |
68
|
|
|
'id' => $identifier, |
69
|
|
|
|
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
|
|
|
|
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
|
|
|
|
106
|
|
|
) |
107
|
|
|
) |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
View Code Duplication |
if (! $game->getForm()) { |
|
|
|
|
113
|
|
|
return $this->redirect()->toUrl( |
114
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
115
|
|
|
'postvote', |
116
|
|
|
array( |
117
|
|
|
'id' => $identifier, |
118
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
View Code Duplication |
if (! $post || $post->getStatus() === 9) { |
|
|
|
|
294
|
|
|
return $this->redirect()->toUrl( |
295
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
296
|
|
|
'postvote', |
297
|
|
|
array( |
298
|
|
|
'id' => $identifier, |
299
|
|
|
|
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
|
|
|
|
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
|
|
|
$statusMail = null; |
390
|
|
|
|
391
|
|
|
if (!$identifier) { |
392
|
|
|
return $this->notFoundAction(); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
$postVoteMapper = $this->getGameService()->getPostVoteMapper(); |
396
|
|
|
$game = $postVoteMapper->findByIdentifier($identifier); |
397
|
|
|
|
398
|
|
|
if (!$game || $game->isClosed()) { |
399
|
|
|
return $this->notFoundAction(); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
403
|
|
|
if (!$user && !$game->getAnonymousAllowed()) { |
404
|
|
|
$redirect = urlencode( |
405
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
406
|
|
|
'postvote/result', |
407
|
|
|
array( |
408
|
|
|
'id' => $game->getIdentifier(), |
409
|
|
|
|
410
|
|
|
) |
411
|
|
|
) |
412
|
|
|
); |
413
|
|
|
return $this->redirect()->toUrl( |
414
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
415
|
|
|
'zfcuser/register', |
416
|
|
|
array() |
417
|
|
|
) . '?redirect='.$redirect |
418
|
|
|
); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
// Has the user finished the game ? |
422
|
|
|
$lastEntry = $this->getGameService()->findLastInactiveEntry($game, $user); |
423
|
|
|
|
424
|
|
View Code Duplication |
if ($lastEntry === null) { |
|
|
|
|
425
|
|
|
return $this->redirect()->toUrl( |
426
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
427
|
|
|
'postvote', |
428
|
|
|
array('id' => $identifier) |
429
|
|
|
) |
430
|
|
|
); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
$form = $this->getServiceLocator()->get('playgroundgame_sharemail_form'); |
434
|
|
|
$form->setAttribute('method', 'post'); |
435
|
|
|
|
436
|
|
View Code Duplication |
if ($this->getRequest()->isPost()) { |
|
|
|
|
437
|
|
|
$data = $this->getRequest()->getPost()->toArray(); |
|
|
|
|
438
|
|
|
$form->setData($data); |
439
|
|
|
if ($form->isValid()) { |
440
|
|
|
$result = $this->getGameService()->sendShareMail($data, $game, $user, $lastEntry); |
441
|
|
|
if ($result) { |
442
|
|
|
$statusMail = true; |
443
|
|
|
} |
444
|
|
|
} |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
// Je recherche le post associé à entry + status == 0. Si non trouvé, je redirige vers home du jeu. |
448
|
|
|
$post = $this->getGameService()->getPostVotePostMapper()->findOneBy(array('entry' => $lastEntry)); |
449
|
|
|
|
450
|
|
|
if (! $post) { |
451
|
|
|
return $this->redirect()->toUrl( |
452
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
453
|
|
|
'postvote', |
454
|
|
|
array('id' => $identifier) |
455
|
|
|
) |
456
|
|
|
); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
$viewModel = $this->buildView($game); |
460
|
|
|
|
461
|
|
|
$viewModel->setVariables(array( |
|
|
|
|
462
|
|
|
'statusMail' => $statusMail, |
463
|
|
|
'post' => $post, |
464
|
|
|
'form' => $form, |
465
|
|
|
)); |
466
|
|
|
|
467
|
|
|
return $viewModel; |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* Example of AJAX File Upload with Session Progress and partial validation. |
472
|
|
|
* It's now possible to send a base64 image in this case the call is the form : |
473
|
|
|
* this._ajax( |
474
|
|
|
* { |
475
|
|
|
* url: url.dataset.url, |
476
|
|
|
* method: 'post', |
477
|
|
|
* body: 'photo=' + image |
478
|
|
|
* }, |
479
|
|
|
* |
480
|
|
|
* @return \Zend\Stdlib\ResponseInterface |
481
|
|
|
*/ |
482
|
|
|
public function ajaxuploadAction() |
483
|
|
|
{ |
484
|
|
|
// Call this for the session lock to be released (other ajax calls can then be made) |
485
|
|
|
session_write_close(); |
486
|
|
|
|
487
|
|
|
$game = $this->getGameService()->checkGame($this->getEvent()->getRouteMatch()->getParam('id')); |
488
|
|
|
if (! $game) { |
489
|
|
|
$this->getResponse()->setContent(\Zend\Json\Json::encode(array( |
490
|
|
|
'success' => 0 |
491
|
|
|
))); |
492
|
|
|
|
493
|
|
|
return $this->getResponse(); |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
$entry = $this->getGameService()->findLastActiveEntry($game, $this->zfcUserAuthentication()->getIdentity()); |
|
|
|
|
497
|
|
|
if (!$entry) { |
498
|
|
|
// the user has already taken part of this game and the participation limit has been reached |
499
|
|
|
$this->getResponse()->setContent(\Zend\Json\Json::encode(array( |
500
|
|
|
'success' => 0 |
501
|
|
|
))); |
502
|
|
|
|
503
|
|
|
return $this->getResponse(); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
if ($this->getRequest()->isPost()) { |
|
|
|
|
507
|
|
|
$data = $this->getRequest()->getFiles()->toArray(); |
|
|
|
|
508
|
|
|
|
509
|
|
|
if (empty($data)) { |
510
|
|
|
$data = $this->getRequest()->getPost()->toArray(); |
|
|
|
|
511
|
|
|
|
512
|
|
|
$key = key($data); |
513
|
|
|
|
514
|
|
|
$uploadImage = array('name' => $key.'.png', 'error' => 0, 'base64' => $data[$key]); |
515
|
|
|
$data = array($key => $uploadImage); |
516
|
|
|
} |
517
|
|
|
$uploadFile = $this->getGameService()->uploadFileToPost($data, $game, $this->zfcUserAuthentication()->getIdentity()); |
|
|
|
|
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
$this->getResponse()->setContent(\Zend\Json\Json::encode(array( |
521
|
|
|
'success' => true, |
522
|
|
|
'fileUrl' => $uploadFile |
|
|
|
|
523
|
|
|
))); |
524
|
|
|
|
525
|
|
|
return $this->getResponse(); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
public function ajaxdeleteAction() |
529
|
|
|
{ |
530
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
531
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
532
|
|
|
$sg = $this->getGameService(); |
533
|
|
|
$request = $this->getRequest(); |
534
|
|
|
$response = $this->getResponse(); |
535
|
|
|
|
536
|
|
|
$game = $sg->checkGame($identifier); |
537
|
|
|
if (! $game) { |
538
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
539
|
|
|
'success' => 0 |
540
|
|
|
))); |
541
|
|
|
|
542
|
|
|
return $response; |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
$entry = $sg->findLastActiveEntry($game, $user); |
546
|
|
|
if (!$entry) { |
547
|
|
|
// the user has already taken part of this game and the participation limit has been reached |
548
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
549
|
|
|
'success' => 0 |
550
|
|
|
))); |
551
|
|
|
|
552
|
|
|
return $response; |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
if ($request->isPost()) { |
556
|
|
|
$data = $request->getPost()->toArray(); |
557
|
|
|
$sg->deleteFilePosted($data, $game, $user); |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
561
|
|
|
'success' => true, |
562
|
|
|
))); |
563
|
|
|
|
564
|
|
|
return $response; |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
public function listAction() |
568
|
|
|
{ |
569
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
570
|
|
|
$filter = $this->getEvent()->getRouteMatch()->getParam('filter'); |
571
|
|
|
$search = $this->params()->fromQuery('name'); |
572
|
|
|
$sg = $this->getGameService(); |
573
|
|
|
$postId = $this->params()->fromQuery('id'); |
574
|
|
|
|
575
|
|
|
$statusMail = false; |
576
|
|
|
$mailService = $this->getServiceLocator()->get('playgroundgame_message'); |
577
|
|
|
$to = ''; |
578
|
|
|
$skinUrl = $sg->getServiceManager()->get('ViewRenderer')->url( |
579
|
|
|
'frontend', |
580
|
|
|
array(), |
581
|
|
|
array('force_canonical' => true) |
582
|
|
|
); |
583
|
|
|
$config = $this->getGameService()->getServiceManager()->get('config'); |
584
|
|
|
if (isset($config['moderation']['email'])) { |
585
|
|
|
$to = $config['moderation']['email']; |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
$request = $this->getRequest(); |
589
|
|
|
|
590
|
|
|
$game = $sg->checkGame($identifier, false); |
591
|
|
|
|
592
|
|
|
// Je recherche les posts validés associés à ce jeu |
593
|
|
|
$posts = $sg->findArrayOfValidatedPosts($game, $filter, $search); |
594
|
|
|
|
595
|
|
|
if (is_array($posts)) { |
596
|
|
|
$paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($posts)); |
597
|
|
|
$paginator->setItemCountPerPage($game->getPostDisplayNumber()); |
598
|
|
|
$paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p')); |
599
|
|
|
} else { |
600
|
|
|
$paginator = $posts; |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
$form = new Form(); |
604
|
|
|
$form->setAttribute('method', 'post'); |
605
|
|
|
|
606
|
|
|
$form->add(array( |
607
|
|
|
'name' => 'moderation', |
608
|
|
|
'attributes' => array( |
609
|
|
|
'type' => 'hidden', |
610
|
|
|
'value' => '1' |
611
|
|
|
), |
612
|
|
|
)); |
613
|
|
|
|
614
|
|
|
$reportId =''; |
615
|
|
|
|
616
|
|
|
if ($request->isPost()) { |
617
|
|
|
$data = $request->getPost()->toArray(); |
618
|
|
|
|
619
|
|
|
if (isset($data['moderation'])) { |
620
|
|
|
$from = $to; |
621
|
|
|
$subject= 'Moderation Post and Vote'; |
622
|
|
|
$result = $mailService->createHtmlMessage( |
623
|
|
|
$from, |
624
|
|
|
$to, |
625
|
|
|
$subject, |
626
|
|
|
'playground-game/email/moderation', |
627
|
|
|
array('data' => $data, 'skinUrl' => $skinUrl) |
628
|
|
|
); |
629
|
|
|
$mailService->send($result); |
630
|
|
|
if ($result) { |
631
|
|
|
$statusMail = true; |
632
|
|
|
$reportId = $data['reportid']; |
633
|
|
|
} |
634
|
|
|
} |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
$viewModel = $this->buildView($game); |
638
|
|
|
|
639
|
|
|
if ($postId) { |
640
|
|
|
$postTarget = $sg->getPostVotePostMapper()->findById($postId); |
641
|
|
|
if ($postTarget) { |
642
|
|
View Code Duplication |
foreach ($postTarget->getPostElements() as $element) { |
|
|
|
|
643
|
|
|
$fbShareImage = $this->frontendUrl()->fromRoute( |
|
|
|
|
644
|
|
|
'', |
645
|
|
|
array(), |
646
|
|
|
array('force_canonical' => true), |
647
|
|
|
false |
648
|
|
|
) . $element->getValue(); |
649
|
|
|
break; |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
$secretKey = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15)); |
653
|
|
|
|
654
|
|
|
// Without bit.ly shortener |
655
|
|
|
$socialLinkUrl = $this->frontendUrl()->fromRoute( |
|
|
|
|
656
|
|
|
'postvote/list', |
657
|
|
|
array( |
658
|
|
|
'id' => $game->getIdentifier(), |
659
|
|
|
'filter' => 'date', |
660
|
|
|
|
661
|
|
|
), |
662
|
|
|
array('force_canonical' => true) |
663
|
|
|
).'?id='.$postTarget->getId().'&key='.$secretKey; |
664
|
|
|
// With core shortener helper |
665
|
|
|
$socialLinkUrl = $this->shortenUrl()->shortenUrl($socialLinkUrl); |
|
|
|
|
666
|
|
|
|
667
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('og:image', $fbShareImage); |
|
|
|
|
668
|
|
|
|
669
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:card', "photo"); |
670
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:site', "@alfie_selfie"); |
671
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:title', $game->getTwShareMessage()); |
672
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:description', ""); |
673
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:image', $fbShareImage); |
674
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:url', $socialLinkUrl); |
675
|
|
|
} |
676
|
|
|
} |
677
|
|
|
|
678
|
|
|
$viewModel->setVariables(array( |
|
|
|
|
679
|
|
|
'posts' => $paginator, |
680
|
|
|
'form' => $form, |
681
|
|
|
'statusMail' => $statusMail, |
682
|
|
|
'reportId' => $reportId, |
683
|
|
|
'filter' => $filter, |
684
|
|
|
'search' => $search, |
685
|
|
|
)); |
686
|
|
|
|
687
|
|
|
return $viewModel; |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
public function ajaxVoteAction() |
691
|
|
|
{ |
692
|
|
|
// Call this for the session lock to be released (other ajax calls can then be made) |
693
|
|
|
session_write_close(); |
694
|
|
|
|
695
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
696
|
|
|
$postId = $this->getEvent()->getRouteMatch()->getParam('post'); |
697
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
698
|
|
|
$sg = $this->getGameService(); |
699
|
|
|
$request = $this->getRequest(); |
700
|
|
|
$response = $this->getResponse(); |
701
|
|
|
|
702
|
|
|
$game = $sg->checkGame($identifier); |
703
|
|
|
if (! $game) { |
704
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
705
|
|
|
'success' => 0 |
706
|
|
|
))); |
707
|
|
|
|
708
|
|
|
return $response; |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
if (!$this->zfcUserAuthentication()->hasIdentity()) { |
|
|
|
|
712
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
713
|
|
|
'success' => 0 |
714
|
|
|
))); |
715
|
|
|
} else { |
716
|
|
|
if ($request->isPost()) { |
717
|
|
|
$post = $sg->getPostvotePostMapper()->findById($postId); |
718
|
|
|
if ($sg->addVote($user, $this->getRequest()->getServer('REMOTE_ADDR'), $post)) { |
|
|
|
|
719
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
720
|
|
|
'success' => 1 |
721
|
|
|
))); |
722
|
|
|
} else { |
723
|
|
|
$response->setContent(\Zend\Json\Json::encode(array( |
724
|
|
|
'success' => 0 |
725
|
|
|
))); |
726
|
|
|
} |
727
|
|
|
} |
728
|
|
|
} |
729
|
|
|
|
730
|
|
|
return $response; |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
public function captchaAction() |
734
|
|
|
{ |
735
|
|
|
$response = $this->getResponse(); |
736
|
|
|
$response->getHeaders()->addHeaderLine('Content-Type', "image/png"); |
737
|
|
|
|
738
|
|
|
$id = $this->params('id', false); |
739
|
|
|
|
740
|
|
|
if ($id) { |
741
|
|
|
$image = './data/captcha/' . $id; |
742
|
|
|
|
743
|
|
|
if (file_exists($image) !== false) { |
744
|
|
|
$imagegetcontent = file_get_contents($image); |
745
|
|
|
|
746
|
|
|
$response->setStatusCode(200); |
747
|
|
|
$response->setContent($imagegetcontent); |
748
|
|
|
|
749
|
|
|
if (file_exists($image) === true) { |
750
|
|
|
unlink($image); |
751
|
|
|
} |
752
|
|
|
} |
753
|
|
|
} |
754
|
|
|
|
755
|
|
|
return $response; |
756
|
|
|
} |
757
|
|
|
|
758
|
|
|
public function shareAction() |
759
|
|
|
{ |
760
|
|
|
$identifier = $this->getEvent()->getRouteMatch()->getParam('id'); |
761
|
|
|
$sg = $this->getGameService(); |
762
|
|
|
|
763
|
|
|
$statusMail = null; |
764
|
|
|
|
765
|
|
|
if (!$identifier) { |
766
|
|
|
return $this->notFoundAction(); |
767
|
|
|
} |
768
|
|
|
|
769
|
|
|
$gameMapper = $this->getGameService()->getGameMapper(); |
770
|
|
|
$game = $gameMapper->findByIdentifier($identifier); |
771
|
|
|
|
772
|
|
|
if (!$game || $game->isClosed()) { |
773
|
|
|
return $this->notFoundAction(); |
774
|
|
|
} |
775
|
|
|
|
776
|
|
|
$user = $this->zfcUserAuthentication()->getIdentity(); |
|
|
|
|
777
|
|
|
if (!$user && !$game->getAnonymousAllowed()) { |
778
|
|
|
$redirect = urlencode( |
779
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
780
|
|
|
'postvote/result', |
781
|
|
|
array( |
782
|
|
|
'id' => $game->getIdentifier(), |
783
|
|
|
|
784
|
|
|
) |
785
|
|
|
) |
786
|
|
|
); |
787
|
|
|
return $this->redirect()->toUrl( |
788
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
789
|
|
|
'zfcuser/register', |
790
|
|
|
array() |
791
|
|
|
) . '?redirect='.$redirect |
792
|
|
|
); |
793
|
|
|
} |
794
|
|
|
|
795
|
|
|
// Has the user finished the game ? |
796
|
|
|
$lastEntry = $this->getGameService()->findLastInactiveEntry($game, $user); |
797
|
|
|
|
798
|
|
View Code Duplication |
if ($lastEntry === null) { |
|
|
|
|
799
|
|
|
return $this->redirect()->toUrl( |
800
|
|
|
$this->frontendUrl()->fromRoute( |
|
|
|
|
801
|
|
|
'postvote', |
802
|
|
|
array('id' => $identifier) |
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
|
|
|
|
816
|
|
|
), |
817
|
|
|
array('force_canonical' => true) |
818
|
|
|
).'?key='.$secretKey; |
819
|
|
|
// With core shortener helper |
820
|
|
|
$socialLinkUrl = $this->shortenUrl()->shortenUrl($socialLinkUrl); |
|
|
|
|
821
|
|
|
|
822
|
|
|
$form = $this->getServiceLocator()->get('playgroundgame_sharemail_form'); |
823
|
|
|
$form->setAttribute('method', 'post'); |
824
|
|
|
|
825
|
|
View Code Duplication |
if ($this->getRequest()->isPost()) { |
|
|
|
|
826
|
|
|
$data = $this->getRequest()->getPost()->toArray(); |
|
|
|
|
827
|
|
|
$form->setData($data); |
828
|
|
|
if ($form->isValid()) { |
829
|
|
|
$result = $this->getGameService()->sendShareMail($data, $game, $user, $lastEntry); |
830
|
|
|
if ($result) { |
831
|
|
|
$statusMail = true; |
832
|
|
|
} |
833
|
|
|
} |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
$viewModel = $this->buildView($game); |
837
|
|
|
|
838
|
|
View Code Duplication |
foreach ($post->getPostElements() as $element) { |
|
|
|
|
839
|
|
|
$fbShareImage = $this->frontendUrl()->fromRoute( |
|
|
|
|
840
|
|
|
'', |
841
|
|
|
array(), |
842
|
|
|
array('force_canonical' => true), |
843
|
|
|
false |
844
|
|
|
) . $element->getValue(); |
845
|
|
|
break; |
846
|
|
|
} |
847
|
|
|
|
848
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('og:image', $fbShareImage); |
|
|
|
|
849
|
|
|
|
850
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:card', "photo"); |
851
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:site', "@playground"); |
852
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:title', $game->getTwShareMessage()); |
853
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:description', ""); |
854
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:image', $fbShareImage); |
855
|
|
|
$this->getViewHelper('HeadMeta')->setProperty('twitter:url', $socialLinkUrl); |
856
|
|
|
|
857
|
|
|
$viewModel->setVariables(array( |
|
|
|
|
858
|
|
|
'statusMail' => $statusMail, |
859
|
|
|
'form' => $form, |
860
|
|
|
'socialLinkUrl' => $socialLinkUrl, |
861
|
|
|
'post' => $post |
862
|
|
|
)); |
863
|
|
|
|
864
|
|
|
return $viewModel; |
865
|
|
|
} |
866
|
|
|
|
867
|
|
|
public function getGameService() |
868
|
|
|
{ |
869
|
|
|
if (!$this->gameService) { |
870
|
|
|
$this->gameService = $this->getServiceLocator()->get('playgroundgame_postvote_service'); |
|
|
|
|
871
|
|
|
} |
872
|
|
|
|
873
|
|
|
return $this->gameService; |
874
|
|
|
} |
875
|
|
|
} |
876
|
|
|
|
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: