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