| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace PlaygroundGame\Controller\Frontend; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use PlaygroundGame\Controller\Frontend\GameController; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use PlaygroundGame\Service\GameService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Zend\Session\Container; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Zend\ServiceManager\ServiceLocatorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class MissionController extends GameController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * @var gameService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     protected $gameService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     protected $mission; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     public function __construct(ServiceLocatorInterface $locator) | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         parent::__construct($locator); | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * Homepage of the game | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     public function indexAction() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $games = $this->getGameService()->getMissionGames($this->game, $this->user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $viewModel = $this->buildView($this->game); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $viewModel->setVariables( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             'user'          => $this->user, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             'games'         => $games, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             'entry'         => $entry, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             'flashMessages' => $this->flashMessenger()->getMessages(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         return $viewModel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     public function playAction() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $subGameIdentifier = $this->getEvent()->getRouteMatch()->getParam('gameId'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $entry             = $this->getGameService()->play($this->game, $this->user); | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 49 |  | View Code Duplication |         if (!$entry) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |           // the user has already taken part of this game and the participation limit has been reached | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $this->flashMessenger()->addMessage('You have already played'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             return $this->redirect()->toUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 $this->frontendUrl()->fromRoute( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                     'mission/result', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                     array('id' => $this->game->getIdentifier()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         if (!$subGameIdentifier) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             $subGame = $this->game->getNextPlayableGame($entry); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             $subGame = $this->getGameService()->checkGame($subGameIdentifier); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         if (!$this->game->isPlayable($subGame, $entry)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |           // this subgame is not playable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             $this->flashMessenger()->addMessage('No game found'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             return $this->redirect()->toUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                 $this->frontendUrl()->fromRoute( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                     'mission', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                     array('id' => $this->game->getIdentifier()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $session = new Container('facebook'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |       // Redirect to fan gate if the game require to 'like' the page before playing | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         if ($session->offsetExists('signed_request')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             if ($this->game->getFbFan()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                 if ($this->getGameService()->checkIsFan($this->game) === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                     return $this->redirect()->toRoute( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                         $this->game->getClassType().'/fangate', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                         array('id' => $this->game->getIdentifier()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         if (!$this->user) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |           // The game is deployed on Facebook, and played from Facebook : retrieve/register user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             if ($session->offsetExists('signed_request')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |               // Get Playground user from Facebook info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                 $beforeLayout = $this->layout()->getTemplate(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                 $view = $this->forward()->dispatch( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                     'playgrounduser_user', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                     array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                     'controller' => 'playgrounduser_user', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                     'action'     => 'registerFacebookUser', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                     'provider'   => 'facebook', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                 $this->layout()->setTemplate($beforeLayout); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                 $this->user = $view->user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |               // If the user cannot be created/retrieved from Facebook info, redirect to login/register form | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 111 |  | View Code Duplication |                 if (!$this->user) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                     $redirect = urlencode( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |                         $this->frontendUrl()->fromRoute( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |                             'mission/play', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                             array('id'              => $this->game->getIdentifier()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |                             array('force_canonical' => true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |                     if (array_search('login', $this->game->getStepsArray())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                         return $this->redirect()->toUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                             $this->frontendUrl()->fromRoute('mission/login').'?redirect='.$redirect | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |                         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                         return $this->redirect()->toUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                             $this->frontendUrl()->fromRoute('zfcuser/register').'?redirect='.$redirect | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |                         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |               // The game is not played from Facebook : redirect to login/register form | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 131 |  | View Code Duplication |             } elseif (!$this->game->getAnonymousAllowed()) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |                 $redirect = urlencode( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |                     $this->frontendUrl()->fromRoute( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |                         'mission/play', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                         array('id'              => $this->game->getIdentifier()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                         array('force_canonical' => true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |                     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |                 if (array_search('login', $this->game->getStepsArray())) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |                     return $this->redirect()->toUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |                         $this->frontendUrl()->fromRoute('mission/login').'?redirect='.$redirect | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |                     return $this->redirect()->toUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |                         $this->frontendUrl()->fromRoute('zfcuser/register').'?redirect='.$redirect | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         $beforeLayout = $this->layout()->getTemplate(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         $classGame = __NAMESPACE__ . '\\' . ucfirst($subGame->getClassType()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         $subViewModel = $this->forward()->dispatch( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |             $classGame, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |             array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             'controller' => $classGame, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             'action'     => 'play', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             'id'         => $subGame->getIdentifier() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         if ($this->getResponse()->getStatusCode() == 302) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             return $this->redirect()->toUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |                 $this->frontendUrl()->fromRoute( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |                     'mission/result', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |                     array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |                     'id'     => $this->game->getIdentifier(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |                     'gameId' => $subGame->getIdentifier() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |                     ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |                     array('force_canonical' => true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |       // suite au forward, le template de layout a changé, je dois le rétablir... | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         $this->layout()->setTemplate($beforeLayout); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |       // give the ability to the mission to have its customized look and feel. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         $l                    = $templatePathResolver->getPaths(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |       // I've already added the path for the game so the base path is $l[1] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         $templatePathResolver->addPath($l[1].'custom/'.$this->game->getIdentifier()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         $subViewModel->mission = $this->game; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         return $subViewModel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |     public function resultAction() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         $subGameIdentifier = $this->getEvent()->getRouteMatch()->getParam('gameId'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |         $subGame           = $this->getGameService()->checkGame($subGameIdentifier); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $secretKey     = strtoupper(substr(sha1(uniqid('pg_', true).'####'.time()), 0, 15)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         $socialLinkUrl = $this->frontendUrl()->fromRoute( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |             'mission', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |             array('id'              => $this->game->getIdentifier()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |             array('force_canonical' => true) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         ).'?key='.$secretKey; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |         // With core shortener helper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         $socialLinkUrl = $this->shortenUrl()->shortenUrl($socialLinkUrl); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 206 |  | View Code Duplication |         if (!$this->user && !$this->game->getAnonymousAllowed()) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |             $redirect = urlencode( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |                 $this->frontendUrl()->fromRoute( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |                     'mission/result', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |                     array('id' => $this->game->getIdentifier()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |             return $this->redirect()->toUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |                 $this->frontendUrl()->fromRoute('zfcuser/register').'?redirect='.$redirect | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |         $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         $form->setAttribute('method', 'post'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         $beforeLayout = $this->layout()->getTemplate(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         $classGame = __NAMESPACE__ . '\\' . ucfirst($subGame->getClassType()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |         $subViewModel = $this->forward()->dispatch( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |             $classGame, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |             array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |                 'controller' => $classGame, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |                 'action'     => 'result', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |                 'id'         => $subGameIdentifier | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |         if ($this->getResponse()->getStatusCode() == 302) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |             $this->getResponse()->setStatusCode('200'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |             $classGame = __NAMESPACE__ . '\\' . ucfirst($subGame->getClassType()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |             $subViewModel = $this->forward()->dispatch( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |                 $classGame, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |                 array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |                     'controller' => $classGame, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |                     'action'     => 'result', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |                     'id'         => $subGameIdentifier | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |         // suite au forward, le template de layout a changé, je dois le rétablir... | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |         $this->layout()->setTemplate($beforeLayout); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |         // give the ability to the mission to have its customized look and feel. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |         $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         $l                    = $templatePathResolver->getPaths(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |         // I've already added the path for the game so the base path is $l[1] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |         $templatePathResolver->addPath($l[1].'custom/'.$this->game->getIdentifier()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |         $subViewModel->mission = $this->game; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |         return $subViewModel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 259 |  | View Code Duplication |     public function fbshareAction() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |         $sg         = $this->getGameService(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |         $result     = parent::fbshareAction(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |         $bonusEntry = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |         if ($result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |             $identifier = $this->getEvent()->getRouteMatch()->getParam('id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |             $user       = $this->zfcUserAuthentication()->getIdentity(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |             $game       = $sg->checkGame($identifier); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |             $bonusEntry = $sg->addAnotherChance($game, $user, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |         $response = $this->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |         $response->setContent(\Zend\Json\Json::encode(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |                     'success'   => $result, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |                     'playBonus' => $bonusEntry, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |                 ))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         return $response; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 281 |  | View Code Duplication |     public function fbrequestAction() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |         $sg         = $this->getGameService(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |         $result     = parent::fbrequestAction(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |         $bonusEntry = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |         if ($result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |             $identifier = $this->getEvent()->getRouteMatch()->getParam('id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |             $user       = $this->zfcUserAuthentication()->getIdentity(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |             $game       = $sg->checkGame($identifier); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |             $bonusEntry = $sg->addAnotherChance($game, $user, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |         $response = $this->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |         $response->setContent(\Zend\Json\Json::encode(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |                     'success'   => $result, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |                     'playBonus' => $bonusEntry, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |                 ))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |         return $response; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 303 |  | View Code Duplication |     public function tweetAction() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |         $sg         = $this->getGameService(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |         $result     = parent::tweetAction(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |         $bonusEntry = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |         if ($result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |             $identifier = $this->getEvent()->getRouteMatch()->getParam('id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |             $user       = $this->zfcUserAuthentication()->getIdentity(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |             $game       = $sg->checkGame($identifier); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |             $bonusEntry = $sg->addAnotherChance($game, $user, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |         $response = $this->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |         $response->setContent(\Zend\Json\Json::encode(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |                     'success'   => $result, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |                     'playBonus' => $bonusEntry, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |                 ))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |         return $response; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 325 |  | View Code Duplication |     public function googleAction() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |         $sg         = $this->getGameService(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |         $result     = parent::googleAction(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |         $bonusEntry = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |         if ($result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |             $identifier = $this->getEvent()->getRouteMatch()->getParam('id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |             $user       = $this->zfcUserAuthentication()->getIdentity(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |             $game       = $sg->checkGame($identifier); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |             $bonusEntry = $sg->addAnotherChance($game, $user, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |         $response = $this->getResponse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |         $response->setContent(\Zend\Json\Json::encode(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |                     'success'   => $result, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |                     'playBonus' => $bonusEntry, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |                 ))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |         return $response; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |     public function getGameService() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |         if (!$this->gameService) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |             $this->gameService = $this->getServiceLocator()->get('playgroundgame_mission_service'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |         return $this->gameService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |     public function setGameService(GameService $gameService) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |         $this->gameService = $gameService; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 362 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 363 |  |  |  | 
            
                        
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: