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