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