1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PlaygroundGame\Service; |
4
|
|
|
|
5
|
|
|
use Zend\ServiceManager\ServiceManagerAwareInterface; |
6
|
|
|
use Zend\Stdlib\ErrorHandler; |
7
|
|
|
|
8
|
|
|
class PostVote extends Game implements ServiceManagerAwareInterface |
9
|
|
|
{ |
10
|
|
|
protected $postvoteMapper; |
11
|
|
|
protected $postvoteformMapper; |
12
|
|
|
protected $postVotePostMapper; |
13
|
|
|
protected $postVoteVoteMapper; |
14
|
|
|
protected $postVoteCommentMapper; |
15
|
|
|
protected $postVotePostElementMapper; |
16
|
|
|
|
17
|
|
|
public function getGameEntity() |
18
|
|
|
{ |
19
|
|
|
return new \PlaygroundGame\Entity\PostVote; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getPath($post) |
23
|
|
|
{ |
24
|
|
|
$path = $this->getOptions()->getMediaPath() . DIRECTORY_SEPARATOR; |
25
|
|
|
$path .= 'game' . $post->getPostVote()->getId() . DIRECTORY_SEPARATOR; |
26
|
|
|
if (!is_dir($path)) { |
27
|
|
|
mkdir($path, 0777, true); |
28
|
|
|
} |
29
|
|
|
$path .= 'post'. $post->getId() . DIRECTORY_SEPARATOR; |
30
|
|
|
if (!is_dir($path)) { |
31
|
|
|
mkdir($path, 0777, true); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return $path; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getMediaUrl($post) |
38
|
|
|
{ |
39
|
|
|
$media_url = $this->getOptions()->getMediaUrl() . '/'; |
40
|
|
|
$media_url .= 'game' . $post->getPostVote()->getId() . '/' . 'post'. $post->getId() . '/'; |
41
|
|
|
|
42
|
|
|
return $media_url; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param boolean $entry |
47
|
|
|
*/ |
48
|
|
|
public function checkPost($entry) |
49
|
|
|
{ |
50
|
|
|
$post = $this->getPostVotePostMapper()->findOneBy(array('entry' => $entry)); |
51
|
|
|
|
52
|
|
|
if (! $post) { |
53
|
|
|
$post = new \PlaygroundGame\Entity\PostVotePost(); |
54
|
|
|
$post->setPostvote($entry->getGame()); |
|
|
|
|
55
|
|
|
$post->setUser($entry->getUser()); |
|
|
|
|
56
|
|
|
$post->setEntry($entry); |
57
|
|
|
$post = $this->getPostVotePostMapper()->insert($post); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $post; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function uploadFileToPost($data, $game, $user) |
64
|
|
|
{ |
65
|
|
|
$result = false; |
66
|
|
|
$entry = $this->findLastActiveEntry($game, $user); |
67
|
|
|
|
68
|
|
|
if (!$entry) { |
69
|
|
|
return '0'; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$post = $this->checkPost($entry); |
73
|
|
|
$path = $this->getPath($post); |
74
|
|
|
$media_url = $this->getMediaUrl($post); |
75
|
|
|
|
76
|
|
|
$key = key($data); |
77
|
|
|
$uploadFile = $this->uploadFile($path, $data[$key]); |
78
|
|
|
|
79
|
|
|
if ($uploadFile) { |
80
|
|
|
$postElement = $this->getPostVotePostElementMapper()->findOneBy(array('post' => $post, 'name' => $key)); |
81
|
|
|
if (! $postElement) { |
82
|
|
|
$postElement = new \PlaygroundGame\Entity\PostVotePostElement(); |
83
|
|
|
} |
84
|
|
|
$postElement->setName($key); |
85
|
|
|
$postElement->setPosition(0); |
86
|
|
|
$postElement->setValue($media_url.$uploadFile); |
87
|
|
|
$postElement->setPost($post); |
88
|
|
|
$postElement = $this->getPostVotePostElementMapper()->insert($postElement); |
|
|
|
|
89
|
|
|
|
90
|
|
|
$result = $media_url.$uploadFile; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $result; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function deleteFilePosted($data, $game, $user) |
97
|
|
|
{ |
98
|
|
|
$postvotePostMapper = $this->getPostVotePostMapper(); |
99
|
|
|
$postVotePostElementMapper = $this->getPostVotePostElementMapper(); |
100
|
|
|
|
101
|
|
|
$entry = $this->findLastActiveEntry($game, $user); |
102
|
|
|
|
103
|
|
|
if (!$entry) { |
104
|
|
|
return 'falsefin0'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$post = $postvotePostMapper->findOneBy(array('entry' => $entry)); |
108
|
|
|
$element = $postVotePostElementMapper->findOneBy(array('post' => $post->getId(), 'name' => $data['name'])); |
109
|
|
|
|
110
|
|
|
if ($element) { |
111
|
|
|
$element = $postVotePostElementMapper->remove($element); |
112
|
|
|
if ($element) { |
113
|
|
|
return true; |
114
|
|
|
} else { |
115
|
|
|
return false; |
116
|
|
|
} |
117
|
|
|
} else { |
118
|
|
|
return false; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* |
124
|
|
|
* @param array $data |
125
|
|
|
* @return \PlaygroundGame\Entity\Game |
126
|
|
|
*/ |
127
|
|
|
public function createPost(array $data, $game, $user, $form) |
128
|
|
|
{ |
129
|
|
|
$postvotePostMapper = $this->getPostVotePostMapper(); |
130
|
|
|
$postVotePostElementMapper = $this->getPostVotePostElementMapper(); |
131
|
|
|
|
132
|
|
|
$entry = $this->findLastActiveEntry($game, $user); |
133
|
|
|
|
134
|
|
|
if (!$entry) { |
135
|
|
|
return false; |
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$post = $this->checkPost($entry); |
139
|
|
|
$path = $this->getPath($post); |
140
|
|
|
$media_url = $this->getMediaUrl($post); |
141
|
|
|
$position=1; |
142
|
|
|
|
143
|
|
|
foreach ($data as $name => $value) { |
144
|
|
|
$postElement = $postVotePostElementMapper->findOneBy(array('post' => $post, 'name' => $name)); |
145
|
|
|
if (! $postElement) { |
146
|
|
|
$postElement = new \PlaygroundGame\Entity\PostVotePostElement(); |
147
|
|
|
} |
148
|
|
|
$postElement->setName($name); |
149
|
|
|
$postElement->setPosition($position); |
150
|
|
|
|
151
|
|
|
if (is_array($value) && isset($value['tmp_name'])) { |
152
|
|
|
// The file upload has been done in ajax but some weird bugs remain without it |
153
|
|
|
|
154
|
|
|
if (! $value['error']) { |
155
|
|
|
ErrorHandler::start(); |
156
|
|
|
$value['name'] = $this->fileNewname($path, $value['name'], true); |
157
|
|
|
move_uploaded_file($value['tmp_name'], $path . $value['name']); |
158
|
|
|
$image = $this->getServiceManager()->get('playgroundcore_image_service'); |
159
|
|
|
$image->setImage($path . $value['name']); |
160
|
|
|
|
161
|
|
|
if ($image->canCorrectOrientation()) { |
162
|
|
|
$image->correctOrientation()->save(); |
163
|
|
|
} |
164
|
|
|
$postElement->setValue($media_url . $value['name']); |
165
|
|
|
|
166
|
|
|
if (class_exists("Imagick")) { |
167
|
|
|
$ext = pathinfo($value['name'], PATHINFO_EXTENSION); |
168
|
|
|
$img = new \Imagick($path . $value['name']); |
169
|
|
|
$img->cropThumbnailImage(100, 100); |
170
|
|
|
$img->setImageCompression(\Imagick::COMPRESSION_JPEG); |
171
|
|
|
$img->setImageCompressionQuality(75); |
172
|
|
|
// Strip out unneeded meta data |
173
|
|
|
$img->stripImage(); |
174
|
|
|
$img->writeImage($path . str_replace('.'.$ext, '-thumbnail.'.$ext, $value['name'])); |
175
|
|
|
ErrorHandler::stop(true); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
} elseif (is_array($value) || $form->get($name) instanceof \Zend\Form\Element\Select) { |
179
|
|
|
$arValues = $form->get($name)->getValueOptions(); |
180
|
|
|
$postElement->setValue($arValues[$value[0]]); |
181
|
|
|
} elseif (!empty($value)) { |
182
|
|
|
$postElement->setValue($value); |
183
|
|
|
} |
184
|
|
|
$postElement->setPost($post); |
185
|
|
|
$postVotePostElementMapper->insert($postElement); |
186
|
|
|
$position++; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
$postvotePostMapper->update($post); |
190
|
|
|
|
191
|
|
|
// If a preview step is not proposed, I confirmPost on this step |
192
|
|
|
$steps = $game->getStepsArray(); |
193
|
|
|
$previewKey = array_search('preview', $steps); |
194
|
|
|
if (!$previewKey) { |
195
|
|
|
$post = $this->confirmPost($game, $user); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
$this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, array( |
199
|
|
|
'user' => $user, |
200
|
|
|
'game' => $game, |
201
|
|
|
'post' => $post, |
202
|
|
|
'entry' => $entry |
203
|
|
|
)); |
204
|
|
|
|
205
|
|
|
return $post; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* |
210
|
|
|
* @return \PlaygroundGame\Entity\Game |
211
|
|
|
*/ |
212
|
|
|
public function confirmPost($game, $user) |
213
|
|
|
{ |
214
|
|
|
$postvotePostMapper = $this->getPostVotePostMapper(); |
215
|
|
|
|
216
|
|
|
$entryMapper = $this->getEntryMapper(); |
217
|
|
|
$entry = $this->findLastActiveEntry($game, $user); |
218
|
|
|
|
219
|
|
|
if (!$entry) { |
220
|
|
|
return false; |
|
|
|
|
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
$post = $postvotePostMapper->findOneBy(array('entry' => $entry)); |
224
|
|
|
|
225
|
|
|
if (! $post) { |
226
|
|
|
return false; |
|
|
|
|
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
// The post is confirmed by user. I update the status and close the associated entry |
230
|
|
|
// Post are validated by default, unless pre-moderation is enable for the game |
231
|
|
|
if ($game->getModerationType()) { |
232
|
|
|
$post->setStatus(1); |
233
|
|
|
} else { |
234
|
|
|
$post->setStatus(2); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
$postvotePostMapper->update($post); |
238
|
|
|
|
239
|
|
|
$entry->setActive(0); |
|
|
|
|
240
|
|
|
$entryMapper->update($entry); |
241
|
|
|
|
242
|
|
|
$this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, array( |
243
|
|
|
'user' => $user, |
244
|
|
|
'game' => $game, |
245
|
|
|
'entry' => $entry, |
246
|
|
|
'post' => $post |
247
|
|
|
)); |
248
|
|
|
|
249
|
|
|
// sending a mail after Post creation should be optional |
250
|
|
|
// if ($user) { |
251
|
|
|
// // send mail for participation |
252
|
|
|
// $this->sendGameMail($game, $user, $post, 'postvote'); |
253
|
|
|
// } |
254
|
|
|
|
255
|
|
|
return $post; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* |
260
|
|
|
* This service is ready for all types of games |
261
|
|
|
* |
262
|
|
|
* @param array $data |
263
|
|
|
* @return \PlaygroundGame\Entity\Game |
264
|
|
|
*/ |
265
|
|
View Code Duplication |
public function createForm(array $data, $game, $form = null) |
|
|
|
|
266
|
|
|
{ |
267
|
|
|
$title =''; |
268
|
|
|
$description = ''; |
269
|
|
|
|
270
|
|
|
if ($data['form_jsonified']) { |
271
|
|
|
$jsonPV = json_decode($data['form_jsonified']); |
272
|
|
|
foreach ($jsonPV as $element) { |
273
|
|
|
if ($element->form_properties) { |
274
|
|
|
$attributes = $element->form_properties[0]; |
275
|
|
|
$title = $attributes->title; |
276
|
|
|
$description = $attributes->description; |
277
|
|
|
|
278
|
|
|
break; |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
} |
282
|
|
|
if (!$form) { |
283
|
|
|
$form = new \PlaygroundGame\Entity\PostVoteForm(); |
284
|
|
|
} |
285
|
|
|
$form->setPostvote($game); |
286
|
|
|
$form->setTitle($title); |
287
|
|
|
$form->setDescription($description); |
288
|
|
|
$form->setForm($data['form_jsonified']); |
289
|
|
|
$form->setFormTemplate($data['form_template']); |
290
|
|
|
|
291
|
|
|
$form = $this->getPostVoteFormMapper()->insert($form); |
292
|
|
|
|
293
|
|
|
return $form; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
public function findArrayOfValidatedPosts($game, $user, $filter, $search = '') |
297
|
|
|
{ |
298
|
|
|
$em = $this->getServiceManager()->get('doctrine.entitymanager.orm_default'); |
299
|
|
|
$qb = $em->createQueryBuilder(); |
300
|
|
|
$and = $qb->expr()->andx(); |
301
|
|
|
|
302
|
|
|
$and->add($qb->expr()->eq('p.status', 2)); |
303
|
|
|
|
304
|
|
|
$and->add($qb->expr()->eq('g.id', ':game')); |
305
|
|
|
$qb->setParameter('game', $game); |
306
|
|
|
|
307
|
|
|
if ($search != '') { |
308
|
|
|
$and->add( |
309
|
|
|
$qb->expr()->orX( |
310
|
|
|
$qb->expr()->like('u.username', $qb->expr()->literal('%:search%')), |
311
|
|
|
$qb->expr()->like('u.firstname', $qb->expr()->literal('%:search%')), |
312
|
|
|
$qb->expr()->like('u.lastname', $qb->expr()->literal('%:search%')), |
313
|
|
|
$qb->expr()->like('e.value', $qb->expr()->literal('%:search%')), |
314
|
|
|
$qb->expr()->isNull('g.publicationDate') |
315
|
|
|
) |
316
|
|
|
); |
317
|
|
|
$qb->setParameter('search', $search); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
if ('push' == $filter) { |
321
|
|
|
$and->add( |
322
|
|
|
$qb->expr()->andX( |
323
|
|
|
$qb->expr()->eq('p.pushed', 1) |
324
|
|
|
) |
325
|
|
|
); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
$qb->select('p, COUNT(DISTINCT v) AS votesCount, COUNT(distinct av) AS voted') |
329
|
|
|
->from('PlaygroundGame\Entity\PostVotePost', 'p') |
330
|
|
|
->innerJoin('p.postvote', 'g') |
331
|
|
|
->leftJoin('p.user', 'u') |
332
|
|
|
->innerJoin('p.postElements', 'e') |
333
|
|
|
->leftJoin('p.votes', 'v') |
334
|
|
|
->leftJoin('p.votes', 'av', 'WITH', 'av.user = :user') |
335
|
|
|
->where($and) |
336
|
|
|
->groupBy('p.id'); |
337
|
|
|
|
338
|
|
|
if($user){ |
339
|
|
|
$qb->setParameter('user', $user); |
340
|
|
|
} else { |
341
|
|
|
$qb->setParameter('user', null); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
switch ($filter) { |
345
|
|
|
case 'random': |
346
|
|
|
$qb->orderBy('e.value', 'ASC'); |
347
|
|
|
break; |
348
|
|
|
case 'vote': |
349
|
|
|
$qb->orderBy('votesCount', 'DESC'); |
350
|
|
|
break; |
351
|
|
|
case 'date': |
352
|
|
|
$qb->orderBy('p.createdAt', 'DESC'); |
353
|
|
|
break; |
354
|
|
|
case 'push': |
355
|
|
|
$qb->orderBy('p.createdAt', 'DESC'); |
356
|
|
|
break; |
357
|
|
|
case 'id': |
358
|
|
|
$qb->orderBy('p.createdAt', 'ASC'); |
359
|
|
|
break; |
360
|
|
|
default: |
361
|
|
|
$qb->orderBy('p.createdAt', 'ASC'); |
362
|
|
|
break; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
$query = $qb->getQuery(); |
366
|
|
|
|
367
|
|
|
$posts = $query->getResult(); |
368
|
|
|
$arrayPosts = array(); |
369
|
|
|
$i=0; |
370
|
|
|
foreach ($posts as $postRaw) { |
371
|
|
|
$data = array(); |
372
|
|
|
$post = $postRaw[0]; |
373
|
|
|
if ($post) { |
374
|
|
|
foreach ($post->getPostElements() as $element) { |
375
|
|
|
$data[$element->getPosition()] = $element->getValue(); |
376
|
|
|
} |
377
|
|
|
$arrayPosts[$i]['post'] = $post; |
378
|
|
|
$arrayPosts[$i]['data'] = $data; |
379
|
|
|
$arrayPosts[$i]['votes'] = count($post->getVotes()); |
380
|
|
|
$arrayPosts[$i]['voted'] = $postRaw['voted']; |
381
|
|
|
$arrayPosts[$i]['id'] = $post->getId(); |
382
|
|
|
$arrayPosts[$i]['user'] = $post->getUser(); |
383
|
|
|
$arrayPosts[$i]['createdAt'] = $post->getCreatedAt(); |
384
|
|
|
$i++; |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
return $arrayPosts; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
public function addVote($user, $ipAddress, $post) |
392
|
|
|
{ |
393
|
|
|
$postvoteVoteMapper = $this->getPostVoteVoteMapper(); |
394
|
|
|
$postId = $post->getId(); |
395
|
|
|
|
396
|
|
|
if ($user) { |
397
|
|
|
$entryUser = count($postvoteVoteMapper->findBy(array('user' => $user, 'post' =>$postId))); |
398
|
|
|
} else { |
399
|
|
|
$entryUser =count($postvoteVoteMapper->findBy(array('ip' => $ipAddress, 'post' =>$postId))); |
400
|
|
|
} |
401
|
|
|
if ($entryUser && $entryUser > 0) { |
402
|
|
|
|
403
|
|
|
return false; |
404
|
|
|
} else { |
405
|
|
|
$vote = new \PlaygroundGame\Entity\PostVoteVote(); |
406
|
|
|
$vote->setPost($post); |
407
|
|
|
$vote->setIp($ipAddress); |
408
|
|
|
$vote->setNote(1); |
|
|
|
|
409
|
|
|
$vote->setPostvote($post->getPostvote()); |
410
|
|
|
if ($user) { |
411
|
|
|
$vote->setUser($user); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
$postvoteVoteMapper->insert($vote); |
415
|
|
|
$game = $post->getPostvote(); |
416
|
|
|
$this->getEventManager()->trigger( |
417
|
|
|
__FUNCTION__ .'.post', |
418
|
|
|
$this, |
419
|
|
|
array('user' => $user, 'game' => $game, 'post' => $post, 'vote' => $vote) |
420
|
|
|
); |
421
|
|
|
|
422
|
|
|
return true; |
423
|
|
|
} |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
public function addComment($user, $ipAddress, $post, $message = '') |
427
|
|
|
{ |
428
|
|
|
$postvoteCommentMapper = $this->getPostVoteCommentMapper(); |
429
|
|
|
$postId = $post->getId(); |
|
|
|
|
430
|
|
|
$game = $post->getPostvote(); |
431
|
|
|
$comment = new \PlaygroundGame\Entity\PostVoteComment(); |
432
|
|
|
$comment->setPost($post); |
433
|
|
|
$comment->setIp($ipAddress); |
434
|
|
|
$message = strip_tags($message); |
435
|
|
|
$comment->setMessage($message); |
|
|
|
|
436
|
|
|
$comment->setPostvote($game); |
437
|
|
|
if ($user) { |
438
|
|
|
$comment->setUser($user); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
$postvoteCommentMapper->insert($comment); |
442
|
|
|
|
443
|
|
|
$this->getEventManager()->trigger( |
444
|
|
|
__FUNCTION__ .'.post', |
445
|
|
|
$this, |
446
|
|
|
array('user' => $user, 'game' => $game, 'post' => $post, 'comment' => $comment) |
447
|
|
|
); |
448
|
|
|
|
449
|
|
|
return true; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
|
453
|
|
|
public function addShare($post) |
454
|
|
|
{ |
455
|
|
|
$postvotePostMapper = $this->getPostVotePostMapper(); |
456
|
|
|
$post->setShares($post->getShares()+1); |
457
|
|
|
$postvotePostMapper->update($post); |
458
|
|
|
|
459
|
|
|
$this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, array( |
460
|
|
|
'post' => $post |
461
|
|
|
)); |
462
|
|
|
|
463
|
|
|
return true; |
464
|
|
|
} |
465
|
|
|
/** |
466
|
|
|
* Get all comments for this game |
467
|
|
|
*/ |
468
|
|
|
public function getCommentsForPostvote($postvote) |
469
|
|
|
{ |
470
|
|
|
$postvoteCommentMapper = $this->getPostVoteCommentMapper(); |
471
|
|
|
$comments = $postvoteCommentMapper->findBy(array('postvote' => $postvote), array('createdAt' => 'DESC')); |
472
|
|
|
|
473
|
|
|
return $comments ; |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
public function removeComment($user, $ipAddress, $messageId) |
|
|
|
|
477
|
|
|
{ |
478
|
|
|
$postvoteCommentMapper = $this->getPostVoteCommentMapper(); |
479
|
|
|
$comment = $postvoteCommentMapper->findOneBy(array('id' => $messageId)); |
480
|
|
|
if($comment->getUser()->getId() === $user->getId()){ |
481
|
|
|
$postvoteCommentMapper->remove($comment); |
482
|
|
|
$this->getEventManager()->trigger( |
483
|
|
|
'remove_comment_postvote.post', |
484
|
|
|
$this, |
485
|
|
|
array('user' => $user,'comment' => $comment) |
486
|
|
|
); |
487
|
|
|
|
488
|
|
|
return true; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
return false; |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
public function getEntriesHeader($game) |
495
|
|
|
{ |
496
|
|
|
$header = parent::getEntriesHeader($game); |
497
|
|
|
if ($game->getForm()) { |
498
|
|
|
$form = json_decode($game->getForm()->getForm(), true); |
499
|
|
View Code Duplication |
foreach ($form as $element) { |
|
|
|
|
500
|
|
|
foreach ($element as $k => $v) { |
501
|
|
|
if ($k !== 'form_properties') { |
502
|
|
|
$header[$v[0]['name']] = 1; |
503
|
|
|
} |
504
|
|
|
} |
505
|
|
|
} |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
return $header; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
View Code Duplication |
public function getEntriesQuery($game) |
|
|
|
|
512
|
|
|
{ |
513
|
|
|
$em = $this->getServiceManager()->get('doctrine.entitymanager.orm_default'); |
514
|
|
|
|
515
|
|
|
$qb = $em->createQueryBuilder(); |
516
|
|
|
$qb->select(' |
517
|
|
|
p.id, |
518
|
|
|
u.username, |
519
|
|
|
u.title, |
520
|
|
|
u.firstname, |
521
|
|
|
u.lastname, |
522
|
|
|
u.email, |
523
|
|
|
u.optin, |
524
|
|
|
u.optinPartner, |
525
|
|
|
u.address, |
526
|
|
|
u.address2, |
527
|
|
|
u.postalCode, |
528
|
|
|
u.city, |
529
|
|
|
u.telephone, |
530
|
|
|
u.mobile, |
531
|
|
|
u.created_at, |
532
|
|
|
u.dob, |
533
|
|
|
e.winner, |
534
|
|
|
e.socialShares, |
535
|
|
|
e.playerData, |
536
|
|
|
e.updated_at, |
537
|
|
|
p.status, |
538
|
|
|
p |
539
|
|
|
') |
540
|
|
|
->from('PlaygroundGame\Entity\PostVotePost', 'p') |
541
|
|
|
->innerJoin('p.entry', 'e') |
542
|
|
|
->leftJoin('p.user', 'u') |
543
|
|
|
->where($qb->expr()->eq('e.game', ':game')); |
544
|
|
|
|
545
|
|
|
$qb->setParameter('game', $game); |
546
|
|
|
|
547
|
|
|
return $qb->getQuery(); |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* getGameEntries : All entries of a game |
552
|
|
|
* |
553
|
|
|
* @return Array of PlaygroundGame\Entity\Game |
554
|
|
|
*/ |
555
|
|
|
public function getGameEntries($header, $entries, $game) |
556
|
|
|
{ |
557
|
|
|
$results = array(); |
558
|
|
|
|
559
|
|
|
foreach ($entries as $k => $entry) { |
560
|
|
|
$entryData = json_decode($entry['playerData'], true); |
561
|
|
|
$postElements = $entry[0]->getPostElements(); |
562
|
|
|
|
563
|
|
|
foreach ($header as $key => $v) { |
564
|
|
|
if (isset($entryData[$key]) && $key !=='id') { |
565
|
|
|
$results[$k][$key] = (is_array($entryData[$key]))?implode(', ', $entryData[$key]):$entryData[$key]; |
566
|
|
|
} elseif (array_key_exists($key, $entry)) { |
567
|
|
|
$results[$k][$key] = ($entry[$key] instanceof \DateTime)?$entry[$key]->format('Y-m-d'):$entry[$key]; |
568
|
|
|
} else { |
569
|
|
|
$results[$k][$key] = ''; |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
foreach ($postElements as $e) { |
573
|
|
|
if ($key === $e->getName()) { |
574
|
|
|
$results[$k][$key] = (is_array($e->getValue()))?implode(', ', $e->getValue()):$e->getValue(); |
575
|
|
|
break; |
576
|
|
|
} |
577
|
|
|
} |
578
|
|
|
} |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
return $results; |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
public function getPostVoteFormMapper() |
585
|
|
|
{ |
586
|
|
|
if (null === $this->postvoteformMapper) { |
587
|
|
|
$this->postvoteformMapper = $this->getServiceManager()->get('playgroundgame_postvoteform_mapper'); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
return $this->postvoteformMapper; |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
public function setPostVoteFormMapper($postvoteformMapper) |
594
|
|
|
{ |
595
|
|
|
$this->postvoteformMapper = $postvoteformMapper; |
596
|
|
|
|
597
|
|
|
return $this; |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
public function getPostVotePostElementMapper() |
601
|
|
|
{ |
602
|
|
|
if (null === $this->postVotePostElementMapper) { |
603
|
|
|
$this->postVotePostElementMapper = $this->getServiceManager()->get( |
604
|
|
|
'playgroundgame_postvotepostelement_mapper' |
605
|
|
|
); |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
return $this->postVotePostElementMapper; |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
public function setPostVotePostElementMapper($postVotePostElementMapper) |
612
|
|
|
{ |
613
|
|
|
$this->postVotePostElementMapper = $postVotePostElementMapper; |
614
|
|
|
|
615
|
|
|
return $this; |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
public function getPostVoteVoteMapper() |
619
|
|
|
{ |
620
|
|
|
if (null === $this->postVoteVoteMapper) { |
621
|
|
|
$this->postVoteVoteMapper = $this->getServiceManager()->get('playgroundgame_postvotevote_mapper'); |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
return $this->postVoteVoteMapper; |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
public function setPostVoteVoteMapper($postVoteVoteMapper) |
628
|
|
|
{ |
629
|
|
|
$this->postVoteVoteMapper = $postVoteVoteMapper; |
630
|
|
|
|
631
|
|
|
return $this; |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
public function getPostVoteCommentMapper() |
635
|
|
|
{ |
636
|
|
|
if (null === $this->postVoteCommentMapper) { |
637
|
|
|
$this->postVoteCommentMapper = $this->getServiceManager()->get('playgroundgame_postvotecomment_mapper'); |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
return $this->postVoteCommentMapper; |
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
public function setPostVoteCommentMapper($postVoteCommentMapper) |
644
|
|
|
{ |
645
|
|
|
$this->postVoteCommentMapper = $postVoteCommentMapper; |
646
|
|
|
|
647
|
|
|
return $this; |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
public function getPostVotePostMapper() |
651
|
|
|
{ |
652
|
|
|
if (null === $this->postVotePostMapper) { |
653
|
|
|
$this->postVotePostMapper = $this->getServiceManager()->get('playgroundgame_postvotepost_mapper'); |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
return $this->postVotePostMapper; |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
public function setPostVotePostMapper($postVotePostMapper) |
660
|
|
|
{ |
661
|
|
|
$this->postVotePostMapper = $postVotePostMapper; |
662
|
|
|
|
663
|
|
|
return $this; |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
public function getPostVoteMapper() |
667
|
|
|
{ |
668
|
|
|
if (null === $this->postvoteMapper) { |
669
|
|
|
$this->postvoteMapper = $this->getServiceManager()->get('playgroundgame_postvote_mapper'); |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
return $this->postvoteMapper; |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
/** |
676
|
|
|
* setQuizQuestionMapper |
677
|
|
|
* |
678
|
|
|
* @return PostVote |
679
|
|
|
*/ |
680
|
|
|
public function setPostVoteMapper($postvoteMapper) |
681
|
|
|
{ |
682
|
|
|
$this->postvoteMapper = $postvoteMapper; |
683
|
|
|
|
684
|
|
|
return $this; |
685
|
|
|
} |
686
|
|
|
} |
687
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.