Completed
Push — develop ( 7ecade...971ef0 )
by greg
02:34
created

PostVote::moderatePost()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.0808
c 0
b 0
f 0
cc 5
nc 3
nop 2
1
<?php
2
3
namespace PlaygroundGame\Service;
4
5
use Zend\Stdlib\ErrorHandler;
6
use ZfcDatagrid\Column;
7
use ZfcDatagrid\Action;
8
use ZfcDatagrid\Column\Formatter;
9
use ZfcDatagrid\Column\Type;
10
use ZfcDatagrid\Column\Style;
11
use ZfcDatagrid\Filter;
12
use Doctrine\ORM\Query\Expr;
13
14
class PostVote extends Game
15
{
16
    protected $postvoteMapper;
17
    protected $postvoteformMapper;
18
    protected $postVotePostMapper;
19
    protected $postVoteVoteMapper;
20
    protected $postVoteCommentMapper;
21
    protected $postVotePostElementMapper;
22
    protected $postVoteShareMapper;
23
    protected $postVoteViewMapper;
24
25
    public function getGameEntity()
26
    {
27
        return new \PlaygroundGame\Entity\PostVote;
28
    }
29
30 View Code Duplication
    public function getPath($post)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        $path = $this->getOptions()->getMediaPath() . DIRECTORY_SEPARATOR;
33
        $path .= 'game' . $post->getPostVote()->getId() . DIRECTORY_SEPARATOR;
34
        if (!is_dir($path)) {
35
            mkdir($path, 0777, true);
36
        }
37
        $path .= 'post'. $post->getId() . DIRECTORY_SEPARATOR;
38
        if (!is_dir($path)) {
39
            mkdir($path, 0777, true);
40
        }
41
42
        return $path;
43
    }
44
45 View Code Duplication
    public function getMediaUrl($post)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $media_url = $this->getOptions()->getMediaUrl() . '/';
48
        $media_url .= 'game' . $post->getPostVote()->getId() . '/' . 'post'. $post->getId() . '/';
49
50
        return $media_url;
51
    }
52
53
    /**
54
     * @param boolean $entry
55
     */
56
    public function checkPost($entry)
57
    {
58
        $post = $this->getPostVotePostMapper()->findOneBy(array('entry' => $entry));
59
60
        if (! $post) {
61
            $post = new \PlaygroundGame\Entity\PostVotePost();
62
            $post->setPostvote($entry->getGame());
0 ignored issues
show
Bug introduced by
The method getGame cannot be called on $entry (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
63
            $post->setUser($entry->getUser());
0 ignored issues
show
Bug introduced by
The method getUser cannot be called on $entry (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
64
            $post->setEntry($entry);
65
            $post = $this->getPostVotePostMapper()->insert($post);
66
        }
67
68
        return $post;
69
    }
70
71
    public function uploadFileToPost($data, $game, $user)
72
    {
73
        $result = false;
74
        $entry = $this->findLastActiveEntry($game, $user);
75
76
        if (!$entry) {
77
            return '0';
78
        }
79
80
        $post = $this->checkPost($entry);
81
        $path = $this->getPath($post);
82
        $media_url = $this->getMediaUrl($post);
83
84
        $key = key($data);
85
        $uploadFile = $this->uploadFile($path, $data[$key]);
86
87
        if ($uploadFile) {
88
            $postElement = $this->getPostVotePostElementMapper()->findOneBy(array('post' => $post, 'name' => $key));
89
            if (! $postElement) {
90
                $postElement = new \PlaygroundGame\Entity\PostVotePostElement();
91
            }
92
            $postElement->setName($key);
93
            $postElement->setPosition(0);
94
            $postElement->setValue($media_url.$uploadFile);
95
            $postElement->setPost($post);
96
            $postElement = $this->getPostVotePostElementMapper()->insert($postElement);
0 ignored issues
show
Unused Code introduced by
$postElement is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
97
98
            $result = $media_url.$uploadFile;
99
        }
100
101
        return $result;
102
    }
103
104
    public function deleteFilePosted($data, $game, $user)
105
    {
106
        $postvotePostMapper = $this->getPostVotePostMapper();
107
        $postVotePostElementMapper = $this->getPostVotePostElementMapper();
108
109
        $entry = $this->findLastActiveEntry($game, $user);
110
111
        if (!$entry) {
112
            return 'falsefin0';
113
        }
114
115
        $post = $postvotePostMapper->findOneBy(array('entry' => $entry));
116
        $element = $postVotePostElementMapper->findOneBy(array('post' => $post->getId(), 'name' => $data['name']));
117
118
        if ($element) {
119
            $element = $postVotePostElementMapper->remove($element);
120
            if ($element) {
121
                return true;
122
            } else {
123
                return false;
124
            }
125
        } else {
126
            return false;
127
        }
128
    }
129
130
    /**
131
     *
132
     * @param  array $data
133
     * @return \PlaygroundGame\Entity\Game
134
     */
135
    public function createPost(array $data, $game, $user, $form)
136
    {
137
        $postvotePostMapper = $this->getPostVotePostMapper();
138
        $postVotePostElementMapper = $this->getPostVotePostElementMapper();
139
140
        $entry = $this->findLastActiveEntry($game, $user);
141
142
        if (!$entry) {
143
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by PlaygroundGame\Service\PostVote::createPost of type PlaygroundGame\Entity\Game.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
144
        }
145
146
        $post = $this->checkPost($entry);
147
        $path = $this->getPath($post);
148
        $media_url = $this->getMediaUrl($post);
149
        $position=1;
150
151
        foreach ($data as $name => $value) {
152
            $postElement = $postVotePostElementMapper->findOneBy(array('post' => $post, 'name' => $name));
153
            if (! $postElement) {
154
                $postElement = new \PlaygroundGame\Entity\PostVotePostElement();
155
            }
156
            $postElement->setName($name);
157
            foreach($form as $e) {
158
                if ($e->getName() == $name) {
159
                    $postElement->setLabel($e->getLabel());
160
                    break;
161
                }
162
            }
163
            $postElement->setPosition($position);
164
165
            if (is_array($value) && isset($value['tmp_name'])) {
166
                // The file upload has been done in ajax but some weird bugs remain without it
167
168
                if (! $value['error']) {
169
                    ErrorHandler::start();
170
                    $value['name'] = $this->fileNewname($path, $value['name'], true);
171
                    move_uploaded_file($value['tmp_name'], $path . $value['name']);
172
173
                    if (getimagesize($path . $value['name'])) {
174
                        $image = $this->serviceLocator->get('playgroundcore_image_service');
175
                        $image->setImage($path . $value['name']);
176
177
                        if ($image->canCorrectOrientation()) {
178
                            $image->correctOrientation()->save();
179
                        }
180
                        $postElement->setValue($media_url . $value['name']);
181
                        
182
                        if (class_exists("Imagick")) {
183
                            $ext = pathinfo($value['name'], PATHINFO_EXTENSION);
184
                            $img = new \Imagick($path . $value['name']);
185
                            $img->cropThumbnailImage(100, 100);
186
                            $img->setImageCompression(\Imagick::COMPRESSION_JPEG);
187
                            $img->setImageCompressionQuality(75);
188
                            // Strip out unneeded meta data
189
                            $img->stripImage();
190
                            $img->writeImage($path . str_replace('.'.$ext, '-thumbnail.'.$ext, $value['name']));
191
                            ErrorHandler::stop(true);
192
                        }
193
                    } else {
194
                        $postElement->setValue($media_url . $value['name']);
195
                    }
196
                }
197
            } elseif (is_array($value) || $form->get($name) instanceof \Zend\Form\Element\Select) {
198
                $arValues = $form->get($name)->getValueOptions();
199
                $postElement->setValue($arValues[$value[0]]);
200
            } elseif (!empty($value)) {
201
                $postElement->setValue($value);
202
            }
203
            $post->addPostElement($postElement);
204
            // $postElement->setPost($post);
205
            // $postVotePostElementMapper->insert($postElement);
206
            $position++;
207
        }
208
209
        $postvotePostMapper->update($post);
210
211
        // If a preview step is not proposed, I confirmPost on this step
212
        $steps = $game->getStepsArray();
213
        $previewKey = array_search('preview', $steps);
214
        if (!$previewKey) {
215
            $post = $this->confirmPost($game, $user);
216
        }
217
218
        $this->getEventManager()->trigger(
219
            __FUNCTION__ . '.post',
220
            $this,
221
            [
222
                'user' => $user,
223
                'game' => $game,
224
                'post' => $post,
225
                'entry' => $entry,
226
            ]
227
        );
228
229
        return $post;
230
    }
231
232
    /**
233
     *
234
     * @return \PlaygroundGame\Entity\Game
235
     */
236
    public function confirmPost($game, $user)
237
    {
238
        $postvotePostMapper = $this->getPostVotePostMapper();
239
240
        $entryMapper = $this->getEntryMapper();
241
        $entry = $this->findLastActiveEntry($game, $user);
242
243
        if (!$entry) {
244
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by PlaygroundGame\Service\PostVote::confirmPost of type PlaygroundGame\Entity\Game.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
245
        }
246
247
        $post = $postvotePostMapper->findOneBy(array('entry' => $entry));
248
249
        if (! $post) {
250
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by PlaygroundGame\Service\PostVote::confirmPost of type PlaygroundGame\Entity\Game.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
251
        }
252
253
        // The post is confirmed by user. I update the status and close the associated entry
254
        // Post are validated by default, unless pre-moderation is enable for the game
255
        if ($game->getModerationType()) {
256
            $post->setStatus(1);
257
        } else {
258
            $post->setStatus(2);
259
        }
260
261
        $post = $postvotePostMapper->update($post);
262
263
        $entry->setActive(0);
0 ignored issues
show
Bug introduced by
The method setActive cannot be called on $entry (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
264
        $entryMapper->update($entry);
265
266
        $this->getEventManager()->trigger(
267
            __FUNCTION__ . '.post',
268
            $this,
269
            [
270
                'user' => $user,
271
                'game' => $game,
272
                'entry' => $entry,
273
                'post' => $post,
274
            ]
275
        );
276
277
        return $post;
278
    }
279
280
    /**
281
     * This service moderate a post depending on the status
282
     */
283
    public function moderatePost($post, $status = null)
284
    {
285
        if ($status && strtolower($status) === 'validation') {
286
            $post->setStatus(2);
287
            $this->getPostVotePostMapper()->update($post);
288
289
            $this->getEventManager()->trigger(
290
                __FUNCTION__ .'.validation',
291
                $this,
292
                array('user' => $post->getUser(), 'game' => $post->getPostvote(), 'entry' => $post->getEntry(), 'post' => $post)
293
            );
294
        //} elseif ($status && strtolower($status) === 'rejection' && $post->getStatus() !== 9) {
295
        } elseif ($status && strtolower($status) === 'rejection') {
296
            // We reject the $post
297
            $post->setStatus(9);
298
            $this->getPostVotePostMapper()->update($post);
299
300
            // We signal we want to remove the initial points earned from the $post
301
            $entry = $post->getEntry();
302
            $entry->setPoints(-$entry->getPoints());
303
304
            $this->getEventManager()->trigger(
305
                __FUNCTION__ .'.rejection',
306
                $this,
307
                array('user' => $post->getUser(), 'game' => $post->getPostvote(), 'entry' => $entry, 'post' => $post)
308
            );
309
310
            // We set the points from the $entry to 0;
311
            $entry->setPoints(0);
312
            $entryMapper = $this->getEntryMapper();
313
            $entryMapper->update($entry);
314
        }
315
    }
316
317
    /**
318
     *
319
     * This service is ready for all types of games
320
     *
321
     * @param  array                  $data
322
     * @return \PlaygroundGame\Entity\Game
323
     */
324 View Code Duplication
    public function createForm(array $data, $game, $form = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
325
    {
326
        $title ='';
327
        $description = '';
328
329
        if ($data['form_jsonified']) {
330
            $jsonPV = json_decode($data['form_jsonified']);
331
            foreach ($jsonPV as $element) {
332
                if ($element->form_properties) {
333
                    $attributes  = $element->form_properties[0];
334
                    $title       = $attributes->title;
335
                    $description = $attributes->description;
336
337
                    break;
338
                }
339
            }
340
        }
341
        if (!$form) {
342
            $form = new \PlaygroundGame\Entity\PostVoteForm();
343
        }
344
        $form->setPostvote($game);
345
        $form->setTitle($title);
346
        $form->setDescription($description);
347
        $form->setForm($data['form_jsonified']);
348
        $form->setFormTemplate($data['form_template']);
349
350
        $form = $this->getPostVoteFormMapper()->insert($form);
351
352
        return $form;
353
    }
354
355
    public function findArrayOfValidatedPosts($game, $user, $filter, $search = '')
356
    {
357
        $em = $this->serviceLocator->get('doctrine.entitymanager.orm_default');
358
        $qb = $em->createQueryBuilder();
359
        $and = $qb->expr()->andx();
360
        
361
        $and->add($qb->expr()->eq('p.status', 2));
362
363
        $and->add($qb->expr()->eq('g.id', ':game'));
364
        $qb->setParameter('game', $game);
365
        
366
        if ($search != '') {
367
            $and->add(
368
                $qb->expr()->orX(
369
                    $qb->expr()->like('u.username', $qb->expr()->literal('%:search%')),
370
                    $qb->expr()->like('u.firstname', $qb->expr()->literal('%:search%')),
371
                    $qb->expr()->like('u.lastname', $qb->expr()->literal('%:search%')),
372
                    $qb->expr()->like('e.value', $qb->expr()->literal('%:search%')),
373
                    $qb->expr()->isNull('g.publicationDate')
374
                )
375
            );
376
            $qb->setParameter('search', $search);
377
        }
378
        
379
        if ('push' == $filter) {
380
            $and->add(
381
                $qb->expr()->andX(
382
                    $qb->expr()->eq('p.pushed', 1)
383
                )
384
            );
385
        }
386
        
387
        $qb->select('p, COUNT(DISTINCT v) AS votesCount, COUNT(distinct av) AS voted')
388
            ->from('PlaygroundGame\Entity\PostVotePost', 'p')
389
            ->innerJoin('p.postvote', 'g')
390
            ->leftJoin('p.user', 'u')
391
            ->innerJoin('p.postElements', 'e')
392
            ->leftJoin('p.votes', 'v')
393
            ->leftJoin('p.votes', 'av', 'WITH', 'av.user = :user')
394
            ->where($and)
395
            ->groupBy('p.id');
396
 
397
        if ($user) {
398
            $qb->setParameter('user', $user);
399
        } else {
400
            $qb->setParameter('user', null);
401
        }
402
403
        switch ($filter) {
404
            case 'random':
405
                $qb->orderBy('e.value', 'ASC');
406
                break;
407
            case 'vote':
408
                $qb->orderBy('votesCount', 'DESC');
409
                break;
410
            case 'date':
411
                $qb->orderBy('p.createdAt', 'DESC');
412
                break;
413
            case 'push':
414
                $qb->orderBy('p.createdAt', 'DESC');
415
                break;
416
            case 'id':
417
                $qb->orderBy('p.createdAt', 'ASC');
418
                break;
419
            default:
420
                $qb->orderBy('p.createdAt', 'ASC');
421
                break;
422
        }
423
        
424
        $query = $qb->getQuery();
425
        
426
        $posts = $query->getResult();
427
        $arrayPosts = array();
428
        $i=0;
429
        foreach ($posts as $postRaw) {
430
            $data = array();
431
            $post = $postRaw[0];
432
            if ($post) {
433
                foreach ($post->getPostElements() as $element) {
434
                    $data[$element->getPosition()] = $element->getValue();
435
                }
436
                $arrayPosts[$i]['post']  = $post;
437
                $arrayPosts[$i]['data']  = $data;
438
                $arrayPosts[$i]['votes'] = count($post->getVotes());
439
                $arrayPosts[$i]['voted'] = $postRaw['voted'];
440
                $arrayPosts[$i]['id']    = $post->getId();
441
                $arrayPosts[$i]['user']  = $post->getUser();
442
                $arrayPosts[$i]['createdAt']  = $post->getCreatedAt();
443
                $i++;
444
            }
445
        }
446
447
        return $arrayPosts;
448
    }
449
450 View Code Duplication
    public function toggleVote($user, $ipAddress, $post, $comment = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
451
    {
452
        $postvoteVoteMapper = $this->getPostVoteVoteMapper();
453
        $postId = $post->getId();
454
        $commentId = ($comment !== null) ? $comment->getId() : null;
455
        $vote = null;
0 ignored issues
show
Unused Code introduced by
$vote is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
456
        $game = $post->getPostvote();
457
458
        if ($user) {
459
            if ($comment == null) {
460
                $entryUser = count($postvoteVoteMapper->findBy(array('user' => $user, 'post' => $postId)));
461
                $vote = $postvoteVoteMapper->findOneBy(array('user' => $user, 'post' => $postId));
462
            } else {
463
                $entryUser = count($postvoteVoteMapper->findBy(array('user' => $user, 'post' => $postId, 'postComment' => $commentId)));
464
                $vote = $postvoteVoteMapper->findOneBy(array('user' => $user, 'post' => $postId, 'postComment' => $commentId));
465
            }
466
        } else {
467
            if ($comment == null) {
468
                $entryUser = count($postvoteVoteMapper->findBy(array('ip' => $ipAddress, 'post' => $postId)));
469
                $vote = $postvoteVoteMapper->findOneBy(array('ip' => $ipAddress, 'post' => $postId));
470
            } else {
471
                $entryUser = count($postvoteVoteMapper->findBy(array('ip' => $ipAddress, 'post' => $postId, 'postComment' => $commentId)));
472
                $vote = $postvoteVoteMapper->findOneBy(array('ip' => $ipAddress, 'post' => $postId, 'postComment' => $commentId));
473
            }
474
        }
475
476
        if ($entryUser && $entryUser > 0) {
477
            $postvoteVoteMapper->remove($vote);
478
479
            return 0;
480
        } else {
481
            $vote = new \PlaygroundGame\Entity\PostVoteVote();
482
            $vote->setPost($post);
483
            $vote->setIp($ipAddress);
484
            $vote->setNote(1);
485
            // If the vote is for a comment
486
            if ($comment != null) {
487
                $vote->setPostComment($comment);
488
                $vote->setPostvote($post->getPostvote());
489
            // else if the vote is for the post itself
490
            } else {
491
                $vote->setPostvote($post->getPostvote(), true);
492
            }
493
494
            if ($user) {
495
                $vote->setUser($user);
496
            }
497
498
            $postvoteVoteMapper->insert($vote);
499
        }
500
501
        $this->getEventManager()->trigger(
502
            __FUNCTION__ .'.post',
503
            $this,
504
            array('user' => $user, 'game' => $game, 'post' => $post, 'vote' => $vote)
505
        );
506
507
        return 1;
508
    }
509
510
    public function removeVote($user, $ipAddress, $post)
511
    {
512
        $postvoteVoteMapper = $this->getPostVoteVoteMapper();
513
        $postId = $post->getId();
514
        $commentId = ($comment !== null) ? $comment->getId() : null;
0 ignored issues
show
Bug introduced by
The variable $comment does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
515
        $vote = null;
0 ignored issues
show
Unused Code introduced by
$vote is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
516
        $game = $post->getPostvote();
517
518
        if ($user) {
519
            if ($comment == null) {
520
                $entryUser = count($postvoteVoteMapper->findBy(array('user' => $user, 'post' => $postId)));
0 ignored issues
show
Unused Code introduced by
$entryUser is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
521
                $vote = $postvoteVoteMapper->findOneBy(array('user' => $user, 'post' => $postId));
522
            } else {
523
                $entryUser = count($postvoteVoteMapper->findBy(array('user' => $user, 'post' => $postId, 'postComment' => $commentId)));
0 ignored issues
show
Unused Code introduced by
$entryUser is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
524
                $vote = $postvoteVoteMapper->findOneBy(array('user' => $user, 'post' => $postId, 'postComment' => $commentId));
525
            }
526
        } else {
527
            if ($comment == null) {
528
                $entryUser = count($postvoteVoteMapper->findBy(array('ip' => $ipAddress, 'post' => $postId)));
0 ignored issues
show
Unused Code introduced by
$entryUser is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
529
                $vote = $postvoteVoteMapper->findOneBy(array('ip' => $ipAddress, 'post' => $postId));
530
            } else {
531
                $entryUser = count($postvoteVoteMapper->findBy(array('ip' => $ipAddress, 'post' => $postId, 'postComment' => $commentId)));
0 ignored issues
show
Unused Code introduced by
$entryUser is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
532
                $vote = $postvoteVoteMapper->findOneBy(array('ip' => $ipAddress, 'post' => $postId, 'postComment' => $commentId));
533
            }
534
        }
535
536
        $this->getEventManager()->trigger(
537
            __FUNCTION__ .'.post',
538
            $this,
539
            array('user' => $user, 'game' => $game, 'post' => $post, 'vote' => $vote)
540
        );
541
542
        return true;
543
    }
544
545 View Code Duplication
    public function addVote($user, $ipAddress, $post)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
546
    {
547
        $postvoteVoteMapper = $this->getPostVoteVoteMapper();
548
        $postId = $post->getId();
549
        $commentId = ($comment !== null) ? $comment->getId() : null;
0 ignored issues
show
Bug introduced by
The variable $comment does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
550
        $vote = null;
0 ignored issues
show
Unused Code introduced by
$vote is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
551
        $game = $post->getPostvote();
0 ignored issues
show
Unused Code introduced by
$game is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
552
553
        if ($user) {
554
            if ($comment == null) {
555
                $entryUser = count($postvoteVoteMapper->findBy(array('user' => $user, 'post' => $postId)));
556
                $vote = $postvoteVoteMapper->findOneBy(array('user' => $user, 'post' => $postId));
0 ignored issues
show
Unused Code introduced by
$vote is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
557
            } else {
558
                $entryUser = count($postvoteVoteMapper->findBy(array('user' => $user, 'post' => $postId, 'postComment' => $commentId)));
559
                $vote = $postvoteVoteMapper->findOneBy(array('user' => $user, 'post' => $postId, 'postComment' => $commentId));
0 ignored issues
show
Unused Code introduced by
$vote is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
560
            }
561
        } else {
562
            if ($comment == null) {
563
                $entryUser = count($postvoteVoteMapper->findBy(array('ip' => $ipAddress, 'post' => $postId)));
564
                $vote = $postvoteVoteMapper->findOneBy(array('ip' => $ipAddress, 'post' => $postId));
0 ignored issues
show
Unused Code introduced by
$vote is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
565
            } else {
566
                $entryUser = count($postvoteVoteMapper->findBy(array('ip' => $ipAddress, 'post' => $postId, 'postComment' => $commentId)));
567
                $vote = $postvoteVoteMapper->findOneBy(array('ip' => $ipAddress, 'post' => $postId, 'postComment' => $commentId));
0 ignored issues
show
Unused Code introduced by
$vote is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
568
            }
569
        }
570
571
        if ($entryUser && $entryUser > 0) {
572
            return false;
573
        } else {
574
            $vote = new \PlaygroundGame\Entity\PostVoteVote();
575
            $vote->setPost($post);
576
            $vote->setIp($ipAddress);
577
            $vote->setNote(1);
578
            // If the vote is for a comment
579
            if ($comment != null) {
580
                $vote->setPostComment($comment);
581
                $vote->setPostvote($post->getPostvote());
582
            // else if the vote is for the post itself
583
            } else {
584
                $vote->setPostvote($post->getPostvote(), true);
585
            }
586
            if ($user) {
587
                $vote->setUser($user);
588
            }
589
590
            $postvoteVoteMapper->insert($vote);
591
            $game = $post->getPostvote();
592
            $this->getEventManager()->trigger(
593
                __FUNCTION__ .'.post',
594
                $this,
595
                array('user' => $user, 'game' => $game, 'post' => $post, 'vote' => $vote)
596
            );
597
598
            return true;
599
        }
600
    }
601
602
    public function addComment($user, $ipAddress, $post, $message = '', $category = null)
603
    {
604
        $postvoteCommentMapper = $this->getPostVoteCommentMapper();
605
        $game = $post->getPostvote();
606
        $comment = new \PlaygroundGame\Entity\PostVoteComment();
607
        $comment->setPost($post);
608
        $comment->setIp($ipAddress);
609
        $message = strip_tags($message);
610
        $comment->setMessage($message);
611
        if ($category !== null) {
612
            $comment->setCategory($category);
613
        }
614
        $comment->setPostvote($game);
615
        if ($user) {
616
            $comment->setUser($user);
617
        }
618
619
        $postvoteCommentMapper->insert($comment);
620
        
621
        $this->getEventManager()->trigger(
622
            __FUNCTION__ .'.post',
623
            $this,
624
            array('user' => $user, 'game' => $game, 'post' => $post, 'comment' => $comment)
625
        );
626
627
        return true;
628
    }
629
630 View Code Duplication
    public function addView($user, $ipAddress, $post)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
631
    {
632
        $postvoteViewMapper = $this->getPostVoteViewMapper();
633
        $postView = new \PlaygroundGame\Entity\PostVoteView();
634
        $postView->setPost($post)
635
            ->setPostvote($post->getPostvote())
636
            ->setUser($user)
637
            ->setIp($ipAddress);
638
        $postvoteViewMapper->insert($postView);
639
640
        $this->getEventManager()->trigger(
641
            __FUNCTION__ . '.post',
642
            $this,
643
            array(
644
                'post' => $post
645
            )
646
        );
647
648
        return true;
649
    }
650
651 View Code Duplication
    public function addShare($post, $user)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
652
    {
653
        $postvoteShareMapper = $this->getPostVoteShareMapper();
654
        $postShare = new \PlaygroundGame\Entity\PostVoteShare();
655
        $postShare->setPost($post)
656
            ->setPostvote($post->getPostvote())
657
            ->setUser($user)
658
            ->setOrigin('mail');
659
        $postvoteShareMapper->insert($postShare);
660
661
        $this->getEventManager()->trigger(
662
            __FUNCTION__ . '.post',
663
            $this,
664
            array(
665
                'post' => $post
666
            )
667
        );
668
669
        return true;
670
    }
671
672
    /**
673
     * Get all comments for this game
674
     */
675
    public function getCommentsForPostvote($postvote)
676
    {
677
        $postvoteCommentMapper = $this->getPostVoteCommentMapper();
678
        $comments = $postvoteCommentMapper->findBy(array('postvote' => $postvote), array('createdAt' => 'DESC'));
679
680
        return $comments ;
681
    }
682
683
    public function removeComment($user, $ipAddress, $messageId)
0 ignored issues
show
Unused Code introduced by
The parameter $ipAddress is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
684
    {
685
        $postvoteCommentMapper = $this->getPostVoteCommentMapper();
686
        $comment = $postvoteCommentMapper->findOneBy(array('id' => $messageId));
687
        if ($comment->getUser()->getId() === $user->getId()) {
688
            $postvoteCommentMapper->remove($comment);
689
            $this->getEventManager()->trigger(
690
                'remove_comment_postvote.post',
691
                $this,
692
                array('user' => $user, 'comment' => $comment)
693
            );
694
695
            return true;
696
        }
697
698
        return false;
699
    }
700
701
    /**
702
     * DEPRECATED
703
     */
704
    public function getEntriesHeader($game)
705
    {
706
        $header = parent::getEntriesHeader($game);
707
        if ($game->getForm()) {
708
            $form = json_decode($game->getForm()->getForm(), true);
709 View Code Duplication
            foreach ($form as $element) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
710
                foreach ($element as $k => $v) {
711
                    if ($k !== 'form_properties') {
712
                        $header[$v[0]['name']] = 1;
713
                    }
714
                }
715
            }
716
        }
717
        if ($game->getVoteActive()) {
718
            $header['p.votes'] = 1;
719
        }
720
721
        $header['p.views'] = 1;
722
        $header['p.shares'] = 1;
723
724
        return $header;
725
    }
726
727
    public function getGrid($game)
728
    {
729
        $qb = $this->getEntriesQuery($game);
730
731
        /* @var $grid \ZfcDatagrid\Datagrid */
732
        $grid = $this->serviceLocator->get('ZfcDatagrid\Datagrid');
733
        $grid->setTitle('Entries');
734
        $grid->setDataSource($qb);
735
736
        $col = new Column\Select('id', 'u');
737
        $col->setLabel('Id');
738
        $col->setIdentity(true);
739
        $grid->addColumn($col);
740
        
741
        $colType = new Type\DateTime(
742
            'Y-m-d H:i:s',
743
            \IntlDateFormatter::MEDIUM,
744
            \IntlDateFormatter::MEDIUM
745
        );
746
        $colType->setSourceTimezone('UTC');
747
748
        $col = new Column\Select('created_at', 'u');
749
        $col->setLabel('Created');
750
        $col->setType($colType);
751
        $grid->addColumn($col);
752
753
        $col = new Column\Select('username', 'u');
754
        $col->setLabel('Username');
755
        $grid->addColumn($col);
756
757
        $col = new Column\Select('email', 'u');
758
        $col->setLabel('Email');
759
        $grid->addColumn($col);
760
761
        $col = new Column\Select('firstname', 'u');
762
        $col->setLabel('Firstname');
763
        $grid->addColumn($col);
764
765
        $col = new Column\Select('lastname', 'u');
766
        $col->setLabel('Lastname');
767
        $grid->addColumn($col);
768
769
        $col = new Column\Select('winner', 'e');
770
        $col->setLabel('Status');
771
        $col->setReplaceValues(
772
            [
773
                0 => 'looser',
774
                1 => 'winner',
775
            ]
776
        );
777
        $grid->addColumn($col);
778
779
        if ($game->getForm()) {
780
            $form = json_decode($game->getForm()->getForm(), true);
781
            foreach ($form as $element) {
782
                foreach ($element as $k => $v) {
783
                    if ($k !== 'form_properties') {
784
                        $selectString .= "MAX(CASE WHEN f.name = '".$v[0]['name']."' THEN f.value ELSE '' END) AS " .$v[0]['name']. ",";
0 ignored issues
show
Bug introduced by
The variable $selectString does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
785
                        $querySelect = new Expr\Select("MAX(CASE WHEN f.name = '".$v[0]['name']."' THEN f.value ELSE '' END)");
786
                        $col = new Column\Select($querySelect, $v[0]['name']);
787
                        $col->setLabel($v[0]['name']);
788
                        $col->setUserFilterDisabled(true);
789
                        $grid->addColumn($col);
790
                    }
791
                }
792
            }
793
        }
794
795
        if ($game->getVoteActive()) {
796
            $col = new Column\Select('votes', 'p');
797
            $col->setLabel('Votes');
798
            $grid->addColumn($col);
799
        }
800
    
801
        // $col = new Column\Select('views', 'p');
802
        // $col->setLabel('Views');
803
        // $grid->addColumn($col);
804
805
        // $col = new Column\Select('shares', 'p');
806
        // $col->setLabel('Shares');
807
        // $grid->addColumn($col);
808
809
        return $grid;
810
    }
811
812
    public function getEntriesQuery($game)
813
    {
814
        $em = $this->serviceLocator->get('doctrine.entitymanager.orm_default');
815
816
        $qb = $em->createQueryBuilder();
817
818
        $selectString = '';
819
820
        if ($game->getForm()) {
821
            $form = json_decode($game->getForm()->getForm(), true);
822
            foreach ($form as $element) {
823
                foreach ($element as $k => $v) {
824
                    if ($k !== 'form_properties') {
825
                        $selectString .= "MAX(CASE WHEN f.name = '".$v[0]['name']."' THEN f.value ELSE '' END) AS " .$v[0]['name']. ",";
826
                    }
827
                }
828
            }
829
        }
830
        $selectString .= 'p, u, e';
831
        $qb->select($selectString)
832
            ->from('PlaygroundGame\Entity\PostVotePost', 'p')
833
            ->innerJoin('p.postElements', 'f')
834
            ->innerJoin('p.entry', 'e')
835
            ->leftJoin('p.user', 'u')
836
            ->where($qb->expr()->eq('e.game', ':game'))
837
            ->groupBy('p.id');
838
        
839
        $qb->setParameter('game', $game);
840
841
        return $qb;
842
    }
843
844
    /**
845
     * DEPRECATED
846
     * getGameEntries : All entries of a game
847
     *
848
     * @return Array of PlaygroundGame\Entity\Game
849
     */
850
    public function getGameEntries($header, $entries, $game)
851
    {
852
        $results = array();
853
854
        foreach ($entries as $k => $entry) {
855
            $entryData = json_decode($entry['playerData'], true);
856
            $postElements = $entry[0]->getPostElements();
857
858
            foreach ($header as $key => $v) {
859
                if (isset($entryData[$key]) && $key !=='id') {
860
                    $results[$k][$key] = (is_array($entryData[$key]))?implode(', ', $entryData[$key]):$entryData[$key];
861
                } elseif (array_key_exists($key, $entry)) {
862
                    $results[$k][$key] = ($entry[$key] instanceof \DateTime)?$entry[$key]->format('Y-m-d'):$entry[$key];
863
                } else {
864
                    $results[$k][$key] = '';
865
                }
866
867
                foreach ($postElements as $e) {
868
                    if ($key === $e->getName()) {
869
                        $results[$k][$key] = (is_array($e->getValue()))?implode(', ', $e->getValue()):$e->getValue();
870
                        break;
871
                    }
872
                }
873
874
                if ($key === 'votes') {
875
                    $results[$k][$key] = count($entry[0]->getVotes());
876
                }
877
                if ($key === 'views') {
878
                    $results[$k][$key] = count($entry[0]->getViews());
879
                }
880
                if ($key === 'shares') {
881
                    $results[$k][$key] = count($entry[0]->getShares());
882
                }
883
            }
884
        }
885
886
        return $results;
887
    }
888
889
    public function getPostVoteFormMapper()
890
    {
891
        if (null === $this->postvoteformMapper) {
892
            $this->postvoteformMapper = $this->serviceLocator->get('playgroundgame_postvoteform_mapper');
893
        }
894
895
        return $this->postvoteformMapper;
896
    }
897
898
    public function setPostVoteFormMapper($postvoteformMapper)
899
    {
900
        $this->postvoteformMapper = $postvoteformMapper;
901
902
        return $this;
903
    }
904
905
    public function getPostVotePostElementMapper()
906
    {
907
        if (null === $this->postVotePostElementMapper) {
908
            $this->postVotePostElementMapper = $this->serviceLocator->get(
909
                'playgroundgame_postvotepostelement_mapper'
910
            );
911
        }
912
913
        return $this->postVotePostElementMapper;
914
    }
915
916
    public function setPostVotePostElementMapper($postVotePostElementMapper)
917
    {
918
        $this->postVotePostElementMapper = $postVotePostElementMapper;
919
920
        return $this;
921
    }
922
923
    public function getPostVoteVoteMapper()
924
    {
925
        if (null === $this->postVoteVoteMapper) {
926
            $this->postVoteVoteMapper = $this->serviceLocator->get('playgroundgame_postvotevote_mapper');
927
        }
928
929
        return $this->postVoteVoteMapper;
930
    }
931
932
    public function setPostVoteVoteMapper($postVoteVoteMapper)
933
    {
934
        $this->postVoteVoteMapper = $postVoteVoteMapper;
935
936
        return $this;
937
    }
938
939
    public function getPostVoteCommentMapper()
940
    {
941
        if (null === $this->postVoteCommentMapper) {
942
            $this->postVoteCommentMapper = $this->serviceLocator->get('playgroundgame_postvotecomment_mapper');
943
        }
944
945
        return $this->postVoteCommentMapper;
946
    }
947
948
    public function setPostVoteCommentMapper($postVoteCommentMapper)
949
    {
950
        $this->postVoteCommentMapper = $postVoteCommentMapper;
951
952
        return $this;
953
    }
954
955
    public function getPostVotePostMapper()
956
    {
957
        if (null === $this->postVotePostMapper) {
958
            $this->postVotePostMapper = $this->serviceLocator->get('playgroundgame_postvotepost_mapper');
959
        }
960
961
        return $this->postVotePostMapper;
962
    }
963
964
    public function getPostVoteShareMapper()
965
    {
966
        if (null === $this->postVoteShareMapper) {
967
            $this->postVoteShareMapper = $this->serviceLocator->get('playgroundgame_postvoteshare_mapper');
968
        }
969
970
        return $this->postVoteShareMapper;
971
    }
972
973
    public function getPostVoteViewMapper()
974
    {
975
        if (null === $this->postVoteViewMapper) {
976
            $this->postVoteViewMapper = $this->serviceLocator->get('playgroundgame_postvoteview_mapper');
977
        }
978
979
        return $this->postVoteViewMapper;
980
    }
981
982
    public function setPostVotePostMapper($postVotePostMapper)
983
    {
984
        $this->postVotePostMapper = $postVotePostMapper;
985
986
        return $this;
987
    }
988
989
    public function getPostVoteMapper()
990
    {
991
        if (null === $this->postvoteMapper) {
992
            $this->postvoteMapper = $this->serviceLocator->get('playgroundgame_postvote_mapper');
993
        }
994
995
        return $this->postvoteMapper;
996
    }
997
998
    /**
999
     * setQuizQuestionMapper
1000
     *
1001
     * @return PostVote
1002
     */
1003
    public function setPostVoteMapper($postvoteMapper)
1004
    {
1005
        $this->postvoteMapper = $postvoteMapper;
1006
1007
        return $this;
1008
    }
1009
}
1010