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