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