Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like GameController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GameController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class GameController extends AbstractActionController |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var \PlaygroundGame\Service\GameService |
||
| 18 | */ |
||
| 19 | protected $gameService; |
||
| 20 | |||
| 21 | protected $prizeService; |
||
| 22 | |||
| 23 | protected $options; |
||
| 24 | |||
| 25 | protected $game; |
||
| 26 | |||
| 27 | protected $user; |
||
| 28 | |||
| 29 | protected $withGame = array( |
||
| 30 | 'home', |
||
| 31 | 'index', |
||
| 32 | 'terms', |
||
| 33 | 'conditions', |
||
| 34 | 'leaderboard', |
||
| 35 | 'register', |
||
| 36 | 'bounce', |
||
| 37 | 'prizes', |
||
| 38 | 'prize', |
||
| 39 | 'fangate', |
||
| 40 | 'share', |
||
| 41 | 'optin', |
||
| 42 | 'login', |
||
| 43 | 'ajaxforgot', |
||
| 44 | 'play', |
||
| 45 | 'result', |
||
| 46 | 'preview', |
||
| 47 | 'list' |
||
| 48 | ); |
||
| 49 | |||
| 50 | protected $withOnlineGame = array( |
||
| 51 | 'leaderboard', |
||
| 52 | 'register', |
||
| 53 | 'bounce', |
||
| 54 | 'play', |
||
| 55 | 'result' |
||
| 56 | ); |
||
| 57 | |||
| 58 | protected $withAnyUser = array( |
||
| 59 | 'share', |
||
| 60 | 'result', |
||
| 61 | 'play' |
||
| 62 | ); |
||
| 63 | |||
| 64 | public function setEventManager(\Zend\EventManager\EventManagerInterface $events) |
||
| 65 | { |
||
| 66 | parent::setEventManager($events); |
||
| 67 | |||
| 68 | $controller = $this; |
||
| 69 | $events->attach('dispatch', function (\Zend\Mvc\MvcEvent $e) use ($controller) { |
||
| 70 | |||
| 71 | $identifier = $e->getRouteMatch()->getParam('id'); |
||
| 72 | $controller->game = $controller->getGameService()->checkGame($identifier, false); |
||
| 73 | if (!$controller->game && |
||
| 74 | in_array($controller->params('action'), $controller->withGame) |
||
| 75 | ) { |
||
| 76 | return $controller->notFoundAction(); |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($controller->game && |
||
| 80 | $controller->game->isClosed() && |
||
| 81 | in_array($controller->params('action'), $controller->withOnlineGame) |
||
| 82 | ) { |
||
| 83 | return $controller->notFoundAction(); |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($controller->game) { |
||
| 87 | // this is possible to create a specific game design in /design/frontend/default/custom. |
||
| 88 | //It will precede all others templates. |
||
| 89 | $templatePathResolver = $controller->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack'); |
||
| 90 | $l = $templatePathResolver->getPaths(); |
||
| 91 | $templatePathResolver->addPath($l[0].'custom/'.$controller->game->getIdentifier()); |
||
| 92 | } |
||
| 93 | |||
| 94 | $controller->user = $controller->zfcUserAuthentication()->getIdentity(); |
||
|
|
|||
| 95 | if ($controller->game && |
||
| 96 | !$controller->user && |
||
| 97 | !$controller->game->getAnonymousAllowed() && |
||
| 98 | in_array($controller->params('action'), $controller->withAnyUser) |
||
| 99 | ) { |
||
| 100 | $redirect = urlencode( |
||
| 101 | $controller->url()->fromRoute( |
||
| 102 | 'frontend/'.$controller->game->getClassType() . '/' . $controller->params('action'), |
||
| 103 | array('id' => $controller->game->getIdentifier()), |
||
| 104 | array('force_canonical' => true) |
||
| 105 | ) |
||
| 106 | ); |
||
| 107 | |||
| 108 | $urlRegister = $controller->url()->fromRoute( |
||
| 109 | 'frontend/zfcuser/register', |
||
| 110 | array(), |
||
| 111 | array('force_canonical' => true) |
||
| 112 | ) . '?redirect='.$redirect; |
||
| 113 | |||
| 114 | // code permettant d'identifier un custom game |
||
| 115 | // ligne $config = $controller->getGameService()->getServiceManager()->get('config'); |
||
| 116 | // ligne $customUrl = str_replace('frontend.', '', $e->getRouteMatch()->getParam('area', '')); |
||
| 117 | // ligne if ($config['custom_games'][$controller->game->getIdentifier()] && |
||
| 118 | // ligne $controller->getRequest()->getUri()->getHost() === $customUrl |
||
| 119 | // ligne ) { |
||
| 120 | return $controller->redirect()->toUrl($urlRegister); |
||
| 121 | } |
||
| 122 | |||
| 123 | return; |
||
| 124 | }, 100); // execute before executing action logic |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Action called if matched action does not exist |
||
| 129 | * For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy |
||
| 130 | * it has to be rendered in the controller. Hence the code below. |
||
| 131 | * |
||
| 132 | * This action is injected as a catchall action for each custom_games definition |
||
| 133 | * This way, when a custom_game is created, the 404 is it's responsability and the |
||
| 134 | * view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml |
||
| 135 | * |
||
| 136 | * |
||
| 137 | * @return \Zend\Stdlib\ResponseInterface |
||
| 138 | */ |
||
| 139 | public function notFoundAction() |
||
| 140 | { |
||
| 141 | $templatePathResolver = $this->getServiceLocator()->get('Zend\View\Resolver\TemplatePathStack'); |
||
| 142 | |||
| 143 | // I create a template path in which I can find a custom template |
||
| 144 | $controller = explode('\\', get_class($this)); |
||
| 145 | $controllerPath = str_replace('Controller', '', end($controller)); |
||
| 146 | $controllerPath = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '-\\1', $controllerPath)); |
||
| 147 | $template = 'playground-game/'.$controllerPath . '/custom' .$this->getRequest()->getUri()->getPath(); |
||
| 148 | |||
| 149 | if (false === $templatePathResolver->resolve($template)) { |
||
| 150 | $viewRender = $this->getServiceLocator()->get('ViewRenderer'); |
||
| 151 | |||
| 152 | $this->getEvent()->getRouteMatch()->setParam('action', 'not-found'); |
||
| 153 | $this->response->setStatusCode(404); |
||
| 154 | |||
| 155 | $res = 'error/404'; |
||
| 156 | |||
| 157 | $viewModel = $this->buildView($this->game); |
||
| 158 | $viewModel->setTemplate($res); |
||
| 159 | |||
| 160 | $this->layout()->setVariable("content", $viewRender->render($viewModel)); |
||
| 161 | $this->response->setContent($viewRender->render($this->layout())); |
||
| 162 | |||
| 163 | return $this->response; |
||
| 164 | } |
||
| 165 | |||
| 166 | $viewModel = $this->buildView($this->game); |
||
| 167 | $viewModel->setTemplate($template); |
||
| 168 | |||
| 169 | return $viewModel; |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * This action acts as a hub : Depending on the first step of the game, it will forward the action to this step |
||
| 174 | */ |
||
| 175 | public function homeAction() |
||
| 176 | { |
||
| 177 | // This fix exists only for safari in FB on Windows : we need to redirect the user to the page |
||
| 178 | // outside of iframe for the cookie to be accepted. PlaygroundCore redirects to the FB Iframed page when |
||
| 179 | // it discovers that the user arrives for the first time on the game in FB. |
||
| 180 | // When core redirects, it adds a 'redir_fb_page_id' var in the querystring |
||
| 181 | // Here, we test if this var exist, and then send the user back to the game in FB. |
||
| 182 | // Now the cookie will be accepted by Safari... |
||
| 183 | $pageId = $this->params()->fromQuery('redir_fb_page_id'); |
||
| 184 | if (!empty($pageId)) { |
||
| 185 | $appId = 'app_'.$this->game->getFbAppId(); |
||
| 186 | $url = '//www.facebook.com/pages/game/'.$pageId.'?sk='.$appId; |
||
| 187 | |||
| 188 | return $this->redirect()->toUrl($url); |
||
| 189 | } |
||
| 190 | |||
| 191 | // If an entry has already been done during this session, I reset the anonymous_identifier cookie |
||
| 192 | // so that another person can play the same game (if game conditions are fullfilled) |
||
| 193 | $session = new Container('anonymous_identifier'); |
||
| 194 | if ($session->offsetExists('anonymous_identifier')) { |
||
| 195 | $session->offsetUnset('anonymous_identifier'); |
||
| 196 | } |
||
| 197 | |||
| 198 | return $this->forward()->dispatch( |
||
| 199 | 'playgroundgame_'.$this->game->getClassType(), |
||
| 200 | array( |
||
| 201 | 'controller' => 'playgroundgame_'.$this->game->getClassType(), |
||
| 202 | 'action' => $this->game->firstStep(), |
||
| 203 | 'id' => $this->game->getIdentifier() |
||
| 204 | ) |
||
| 205 | ); |
||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Homepage of the game |
||
| 210 | */ |
||
| 211 | public function indexAction() |
||
| 212 | { |
||
| 213 | $isSubscribed = false; |
||
| 214 | |||
| 215 | $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user); |
||
| 216 | if ($entry) { |
||
| 217 | $isSubscribed = true; |
||
| 218 | } |
||
| 219 | |||
| 220 | $viewModel = $this->buildView($this->game); |
||
| 221 | $viewModel->setVariables(array( |
||
| 222 | 'isSubscribed' => $isSubscribed |
||
| 223 | )); |
||
| 224 | |||
| 225 | return $viewModel; |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
| 229 | * leaderboardAction |
||
| 230 | * |
||
| 231 | * @return ViewModel $viewModel |
||
| 232 | */ |
||
| 233 | public function leaderboardAction() |
||
| 255 | |||
| 256 | /** |
||
| 257 | * This action has been designed to be called by other controllers |
||
| 258 | * It gives the ability to display an information form and persist it in the game entry |
||
| 259 | * |
||
| 260 | * @return \Zend\View\Model\ViewModel |
||
| 261 | */ |
||
| 262 | public function registerAction() |
||
| 263 | { |
||
| 264 | $form = $this->getGameService()->createFormFromJson($this->game->getPlayerForm()->getForm(), 'playerForm'); |
||
| 265 | |||
| 266 | if ($this->getRequest()->isPost()) { |
||
| 267 | // POST Request: Process form |
||
| 268 | $data = array_merge_recursive( |
||
| 269 | $this->getRequest()->getPost()->toArray(), |
||
| 270 | $this->getRequest()->getFiles()->toArray() |
||
| 271 | ); |
||
| 272 | |||
| 273 | $form->setData($data); |
||
| 274 | |||
| 275 | if ($form->isValid()) { |
||
| 276 | // steps of the game |
||
| 277 | $steps = $this->game->getStepsArray(); |
||
| 278 | // sub steps of the game |
||
| 279 | $viewSteps = $this->game->getStepsViewsArray(); |
||
| 280 | |||
| 281 | // register position |
||
| 282 | $key = array_search($this->params('action'), $viewSteps); |
||
| 283 | View Code Duplication | if (!$key) { |
|
| 284 | // register is not a substep of the game so it's a step |
||
| 285 | $key = array_search($this->params('action'), $steps); |
||
| 286 | $keyStep = true; |
||
| 287 | } else { |
||
| 288 | // register was a substep, i search the index of its parent |
||
| 289 | $key = array_search($key, $steps); |
||
| 290 | $keyStep = false; |
||
| 291 | } |
||
| 292 | |||
| 293 | // play position |
||
| 294 | $keyplay = array_search('play', $viewSteps); |
||
| 295 | |||
| 296 | View Code Duplication | if (!$keyplay) { |
|
| 297 | // play is not a substep, so it's a step |
||
| 298 | $keyplay = array_search('play', $steps); |
||
| 299 | $keyplayStep = true; |
||
| 300 | } else { |
||
| 301 | // play is a substep so I search the index of its parent |
||
| 302 | $keyplay = array_search($keyplay, $steps); |
||
| 303 | $keyplayStep = false; |
||
| 304 | } |
||
| 305 | |||
| 306 | // If register step before play, I don't have no entry yet. I have to create one |
||
| 307 | // If register after play step, I search for the last entry created by play step. |
||
| 308 | |||
| 309 | if ($key < $keyplay || ($keyStep && !$keyplayStep && $key <= $keyplay)) { |
||
| 310 | $entry = $this->getGameService()->play($this->game, $this->user); |
||
| 311 | View Code Duplication | if (!$entry) { |
|
| 312 | // the user has already taken part of this game and the participation limit has been reached |
||
| 313 | $this->flashMessenger()->addMessage('Vous avez déjà participé'); |
||
| 314 | |||
| 315 | return $this->redirect()->toUrl( |
||
| 316 | $this->frontendUrl()->fromRoute( |
||
| 317 | $this->game->getClassType().'/result', |
||
| 318 | array( |
||
| 319 | 'id' => $this->game->getIdentifier(), |
||
| 320 | |||
| 321 | ) |
||
| 322 | ) |
||
| 323 | ); |
||
| 324 | } |
||
| 325 | } else { |
||
| 326 | // I'm looking for an entry without anonymousIdentifier (the active entry in fact). |
||
| 327 | $entry = $this->getGameService()->findLastEntry($this->game, $this->user); |
||
| 328 | if ($this->getGameService()->hasReachedPlayLimit($this->game, $this->user)) { |
||
| 329 | // the user has already taken part of this game and the participation limit has been reached |
||
| 330 | $this->flashMessenger()->addMessage('Vous avez déjà participé'); |
||
| 331 | |||
| 332 | return $this->redirect()->toUrl( |
||
| 333 | $this->frontendUrl()->fromRoute( |
||
| 334 | $this->game->getClassType().'/result', |
||
| 335 | array( |
||
| 336 | 'id' => $this->game->getIdentifier(), |
||
| 337 | |||
| 338 | ) |
||
| 339 | ) |
||
| 340 | ); |
||
| 341 | } |
||
| 342 | } |
||
| 343 | |||
| 344 | $this->getGameService()->updateEntryPlayerForm($form->getData(), $this->game, $this->user, $entry); |
||
| 345 | |||
| 346 | if (!empty($this->game->nextStep($this->params('action')))) { |
||
| 347 | return $this->redirect()->toUrl( |
||
| 348 | $this->frontendUrl()->fromRoute( |
||
| 349 | $this->game->getClassType() .'/' . $this->game->nextStep($this->params('action')), |
||
| 350 | array('id' => $this->game->getIdentifier()), |
||
| 351 | array('force_canonical' => true) |
||
| 352 | ) |
||
| 353 | ); |
||
| 354 | } |
||
| 355 | } |
||
| 356 | } |
||
| 357 | |||
| 358 | $viewModel = $this->buildView($this->game); |
||
| 359 | $viewModel->setVariables(array( |
||
| 360 | 'form' => $form |
||
| 361 | )); |
||
| 362 | |||
| 363 | return $viewModel; |
||
| 364 | } |
||
| 365 | |||
| 366 | /** |
||
| 367 | * This action takes care of the terms of the game |
||
| 368 | */ |
||
| 369 | public function termsAction() |
||
| 370 | { |
||
| 371 | $viewModel = $this->buildView($this->game); |
||
| 372 | |||
| 373 | return $viewModel; |
||
| 374 | } |
||
| 375 | |||
| 376 | /** |
||
| 377 | * This action takes care of the conditions of the game |
||
| 378 | */ |
||
| 379 | public function conditionsAction() |
||
| 380 | { |
||
| 381 | $viewModel = $this->buildView($this->game); |
||
| 382 | |||
| 383 | return $viewModel; |
||
| 384 | } |
||
| 385 | |||
| 386 | /** |
||
| 387 | * This action takes care of bounce page of the game |
||
| 388 | */ |
||
| 389 | public function bounceAction() |
||
| 390 | { |
||
| 391 | $availableGames = $this->getGameService()->getAvailableGames($this->user); |
||
| 392 | |||
| 393 | $rssUrl = ''; |
||
| 394 | $config = $this->getGameService()->getServiceManager()->get('config'); |
||
| 395 | if (isset($config['rss']['url'])) { |
||
| 396 | $rssUrl = $config['rss']['url']; |
||
| 397 | } |
||
| 398 | |||
| 399 | $viewModel = $this->buildView($this->game); |
||
| 400 | $viewModel->setVariables(array( |
||
| 401 | 'rssUrl' => $rssUrl, |
||
| 402 | 'user' => $this->user, |
||
| 403 | 'availableGames' => $availableGames, |
||
| 404 | )); |
||
| 405 | |||
| 406 | return $viewModel; |
||
| 407 | } |
||
| 408 | |||
| 409 | |||
| 410 | /** |
||
| 411 | * This action displays the Prizes page associated to the game |
||
| 412 | */ |
||
| 413 | public function prizesAction() |
||
| 414 | { |
||
| 415 | if (count($this->game->getPrizes()) == 0) { |
||
| 416 | return $this->notFoundAction(); |
||
| 417 | } |
||
| 418 | |||
| 419 | $viewModel = $this->buildView($this->game); |
||
| 420 | |||
| 421 | return $viewModel; |
||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * This action displays a specific Prize page among those associated to the game |
||
| 426 | */ |
||
| 427 | public function prizeAction() |
||
| 428 | { |
||
| 429 | $prizeIdentifier = $this->getEvent()->getRouteMatch()->getParam('prize'); |
||
| 430 | $prize = $this->getPrizeService()->getPrizeMapper()->findByIdentifier($prizeIdentifier); |
||
| 431 | |||
| 432 | if (!$prize) { |
||
| 433 | return $this->notFoundAction(); |
||
| 434 | } |
||
| 435 | |||
| 436 | $viewModel = $this->buildView($this->game); |
||
| 437 | $viewModel->setVariables(array('prize'=> $prize)); |
||
| 438 | |||
| 439 | return $viewModel; |
||
| 440 | } |
||
| 441 | |||
| 442 | public function gameslistAction() |
||
| 443 | { |
||
| 444 | $layoutViewModel = $this->layout(); |
||
| 445 | |||
| 446 | $slider = new ViewModel(); |
||
| 447 | $slider->setTemplate('playground-game/common/top_promo'); |
||
| 448 | |||
| 449 | $sliderItems = $this->getGameService()->getActiveSliderGames(); |
||
| 450 | |||
| 451 | $slider->setVariables(array('sliderItems' => $sliderItems)); |
||
| 452 | |||
| 453 | $layoutViewModel->addChild($slider, 'slider'); |
||
| 454 | |||
| 455 | $games = $this->getGameService()->getActiveGames(false, '', 'endDate'); |
||
| 456 | if (is_array($games)) { |
||
| 457 | $paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($games)); |
||
| 458 | } else { |
||
| 459 | $paginator = $games; |
||
| 460 | } |
||
| 461 | |||
| 462 | $paginator->setItemCountPerPage(7); |
||
| 463 | $paginator->setCurrentPageNumber($this->getEvent()->getRouteMatch()->getParam('p')); |
||
| 464 | |||
| 465 | $bitlyclient = $this->getOptions()->getBitlyUrl(); |
||
| 466 | $bitlyuser = $this->getOptions()->getBitlyUsername(); |
||
| 467 | $bitlykey = $this->getOptions()->getBitlyApiKey(); |
||
| 468 | |||
| 469 | $this->getViewHelper('HeadMeta')->setProperty('bt:client', $bitlyclient); |
||
| 470 | $this->getViewHelper('HeadMeta')->setProperty('bt:user', $bitlyuser); |
||
| 471 | $this->getViewHelper('HeadMeta')->setProperty('bt:key', $bitlykey); |
||
| 472 | |||
| 473 | $this->layout()->setVariables( |
||
| 474 | array( |
||
| 475 | 'sliderItems' => $sliderItems, |
||
| 476 | 'currentPage' => array( |
||
| 477 | 'pageGames' => 'games', |
||
| 478 | 'pageWinners' => '' |
||
| 479 | ), |
||
| 480 | ) |
||
| 481 | ); |
||
| 482 | |||
| 483 | return new ViewModel( |
||
| 484 | array( |
||
| 485 | 'games' => $paginator |
||
| 486 | ) |
||
| 487 | ); |
||
| 488 | } |
||
| 489 | |||
| 490 | public function fangateAction() |
||
| 491 | { |
||
| 492 | $viewModel = $this->buildView($this->game); |
||
| 493 | |||
| 494 | return $viewModel; |
||
| 495 | } |
||
| 496 | |||
| 497 | public function shareAction() |
||
| 498 | { |
||
| 499 | $statusMail = null; |
||
| 500 | $lastEntry = null; |
||
| 501 | |||
| 502 | // steps of the game |
||
| 503 | $steps = $this->game->getStepsArray(); |
||
| 504 | // sub steps of the game |
||
| 505 | $viewSteps = $this->game->getStepsViewsArray(); |
||
| 506 | |||
| 507 | // share position |
||
| 508 | $key = array_search($this->params('action'), $viewSteps); |
||
| 509 | View Code Duplication | if (!$key) { |
|
| 510 | // share is not a substep of the game so it's a step |
||
| 511 | $key = array_search($this->params('action'), $steps); |
||
| 512 | $keyStep = true; |
||
| 513 | } else { |
||
| 514 | // share was a substep, I search the index of its parent |
||
| 515 | $key = array_search($key, $steps); |
||
| 516 | $keyStep = false; |
||
| 517 | } |
||
| 518 | |||
| 519 | // play position |
||
| 520 | $keyplay = array_search('play', $viewSteps); |
||
| 521 | |||
| 522 | View Code Duplication | if (!$keyplay) { |
|
| 523 | // play is not a substep, so it's a step |
||
| 524 | $keyplay = array_search('play', $steps); |
||
| 525 | $keyplayStep = true; |
||
| 526 | } else { |
||
| 527 | // play is a substep so I search the index of its parent |
||
| 528 | $keyplay = array_search($keyplay, $steps); |
||
| 529 | $keyplayStep = false; |
||
| 530 | } |
||
| 531 | |||
| 532 | if ($key && $keyplay && $keyplay <= $key) { |
||
| 533 | // Has the user finished the game ? |
||
| 534 | $lastEntry = $this->getGameService()->findLastInactiveEntry($this->game, $this->user); |
||
| 535 | |||
| 536 | if ($lastEntry === null) { |
||
| 537 | return $this->redirect()->toUrl( |
||
| 538 | $this->frontendUrl()->fromRoute( |
||
| 539 | $this->game->getClassType(), |
||
| 540 | array('id' => $this->game->getIdentifier()) |
||
| 541 | ) |
||
| 542 | ); |
||
| 543 | } |
||
| 544 | } |
||
| 545 | |||
| 546 | $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form'); |
||
| 547 | $form->setAttribute('method', 'post'); |
||
| 548 | |||
| 549 | // buildView must be before sendMail because it adds the game template path to the templateStack |
||
| 550 | $viewModel = $this->buildView($this->game); |
||
| 551 | |||
| 552 | View Code Duplication | if ($this->getRequest()->isPost()) { |
|
| 553 | $data = $this->getRequest()->getPost()->toArray(); |
||
| 554 | $form->setData($data); |
||
| 555 | if ($form->isValid()) { |
||
| 556 | $result = $this->getGameService()->sendShareMail($data, $this->game, $this->user, $lastEntry); |
||
| 557 | if ($result) { |
||
| 558 | $statusMail = true; |
||
| 559 | } |
||
| 560 | } |
||
| 561 | } |
||
| 562 | |||
| 563 | $viewModel->setVariables(array( |
||
| 564 | 'statusMail' => $statusMail, |
||
| 565 | 'form' => $form, |
||
| 566 | )); |
||
| 567 | |||
| 568 | return $viewModel; |
||
| 569 | } |
||
| 570 | |||
| 571 | View Code Duplication | public function fbshareAction() |
|
| 591 | |||
| 592 | public function fbrequestAction() |
||
| 593 | { |
||
| 594 | $viewModel = new ViewModel(); |
||
| 595 | $viewModel->setTerminal(true); |
||
| 596 | $fbId = $this->params()->fromQuery('fbId'); |
||
| 597 | $to = $this->params()->fromQuery('to'); |
||
| 598 | |||
| 599 | if (!$this->game) { |
||
| 600 | return $this->errorJson(); |
||
| 601 | } |
||
| 602 | $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user); |
||
| 603 | if (! $entry) { |
||
| 604 | return $this->errorJson(); |
||
| 605 | } |
||
| 606 | if (!$fbId) { |
||
| 607 | return $this->errorJson(); |
||
| 608 | } |
||
| 609 | |||
| 610 | $this->getGameService()->postFbRequest($fbId, $this->game, $this->user, $entry, $to); |
||
| 611 | |||
| 612 | return $this->successJson(); |
||
| 613 | } |
||
| 614 | |||
| 615 | public function tweetAction() |
||
| 634 | |||
| 635 | View Code Duplication | public function googleAction() |
|
| 636 | { |
||
| 637 | $viewModel = new ViewModel(); |
||
| 638 | $viewModel->setTerminal(true); |
||
| 639 | $googleId = $this->params()->fromQuery('googleId'); |
||
| 640 | |||
| 641 | if (!$this->game) { |
||
| 642 | return $this->errorJson(); |
||
| 643 | } |
||
| 644 | $entry = $this->getGameService()->checkExistingEntry($this->game, $this->user); |
||
| 645 | if (! $entry) { |
||
| 646 | return $this->errorJson(); |
||
| 647 | } |
||
| 648 | if (!$googleId) { |
||
| 649 | return $this->errorJson(); |
||
| 650 | } |
||
| 651 | |||
| 652 | $this->getGameService()->postGoogle($googleId, $this->game, $this->user, $entry); |
||
| 653 | |||
| 654 | return $this->successJson(); |
||
| 655 | } |
||
| 656 | |||
| 657 | public function optinAction() |
||
| 675 | |||
| 676 | public function loginAction() |
||
| 677 | { |
||
| 678 | $request = $this->getRequest(); |
||
| 679 | $form = $this->getServiceLocator()->get('zfcuser_login_form'); |
||
| 680 | |||
| 681 | if ($request->isPost()) { |
||
| 682 | $form->setData($request->getPost()); |
||
| 683 | |||
| 684 | if (!$form->isValid()) { |
||
| 685 | $this->flashMessenger()->addMessage( |
||
| 686 | 'Authentication failed. Please try again.' |
||
| 687 | ); |
||
| 688 | |||
| 689 | $viewModel = $this->buildView($this->game); |
||
| 690 | $viewModel->setVariables(array( |
||
| 739 | |||
| 740 | public function userregisterAction() |
||
| 967 | |||
| 968 | View Code Duplication | public function userProfileAction() |
|
| 986 | |||
| 987 | public function userresetAction() |
||
| 1007 | |||
| 1008 | View Code Duplication | public function ajaxforgotAction() |
|
| 1026 | |||
| 1027 | View Code Duplication | public function cmsPageAction() |
|
| 1046 | |||
| 1047 | View Code Duplication | public function cmsListAction() |
|
| 1066 | |||
| 1067 | /** |
||
| 1068 | * |
||
| 1069 | * @param \PlaygroundGame\Entity\Game $game |
||
| 1070 | * @param \PlaygroundUser\Entity\User $user |
||
| 1071 | */ |
||
| 1072 | public function checkFbRegistration($user, $game) |
||
| 1121 | |||
| 1122 | /** |
||
| 1123 | * This method create the basic Game view |
||
| 1124 | * @param \PlaygroundGame\Entity\Game $game |
||
| 1125 | */ |
||
| 1126 | public function buildView($game) |
||
| 1171 | |||
| 1172 | /** |
||
| 1173 | * @param \PlaygroundGame\Entity\Game $game |
||
| 1174 | */ |
||
| 1175 | public function addAdditionalView($game) |
||
| 1211 | |||
| 1212 | public function addMetaBitly() |
||
| 1222 | |||
| 1223 | /** |
||
| 1224 | * @param \PlaygroundGame\Entity\Game $game |
||
| 1225 | */ |
||
| 1226 | public function addGaEvent($game) |
||
| 1234 | |||
| 1235 | /** |
||
| 1236 | * @param \PlaygroundGame\Entity\Game $game |
||
| 1237 | */ |
||
| 1238 | public function addMetaTitle($game) |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * @param \PlaygroundGame\Entity\Game $game |
||
| 1261 | */ |
||
| 1262 | public function customizeGameDesign($game) |
||
| 1277 | |||
| 1278 | /** |
||
| 1279 | * @param \PlaygroundGame\Entity\Game $game |
||
| 1280 | */ |
||
| 1281 | public function getShareData($game) |
||
| 1367 | |||
| 1368 | /** |
||
| 1369 | * return ajax response in json format |
||
| 1370 | * |
||
| 1371 | * @param array $data |
||
| 1372 | * @return \Zend\View\Model\JsonModel |
||
| 1373 | */ |
||
| 1374 | View Code Duplication | protected function successJson($data = null) |
|
| 1382 | |||
| 1383 | /** |
||
| 1384 | * return ajax response in json format |
||
| 1385 | * |
||
| 1386 | * @param string $message |
||
| 1387 | * @return \Zend\View\Model\JsonModel |
||
| 1388 | */ |
||
| 1389 | View Code Duplication | protected function errorJson($message = null) |
|
| 1397 | |||
| 1398 | /** |
||
| 1399 | * @param string $helperName |
||
| 1400 | */ |
||
| 1401 | protected function getViewHelper($helperName) |
||
| 1405 | |||
| 1406 | public function getGameService() |
||
| 1414 | |||
| 1415 | public function setGameService(GameService $gameService) |
||
| 1421 | |||
| 1422 | public function getPrizeService() |
||
| 1430 | |||
| 1431 | public function setPrizeService(PrizeService $prizeService) |
||
| 1437 | |||
| 1438 | public function getOptions() |
||
| 1446 | |||
| 1447 | public function setOptions($options) |
||
| 1453 | } |
||
| 1454 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: