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 | 'play', |
||
44 | 'result', |
||
45 | 'preview', |
||
46 | 'list' |
||
47 | ); |
||
48 | |||
49 | protected $withOnlineGame = array( |
||
50 | 'leaderboard', |
||
51 | 'register', |
||
52 | 'bounce', |
||
53 | 'play', |
||
54 | 'result' |
||
55 | ); |
||
56 | |||
57 | protected $withAnyUser = array( |
||
58 | 'share', |
||
59 | 'result', |
||
60 | 'play' |
||
61 | ); |
||
62 | |||
63 | public function setEventManager(\Zend\EventManager\EventManagerInterface $events) |
||
125 | |||
126 | /** |
||
127 | * Action called if matched action does not exist |
||
128 | * For this view not to be catched by Zend\Mvc\View\RouteNotFoundStrategy |
||
129 | * it has to be rendered in the controller. Hence the code below. |
||
130 | * |
||
131 | * This action is injected as a catchall action for each custom_games definition |
||
132 | * This way, when a custom_game is created, the 404 is it's responsability and the |
||
133 | * view can be defined in design/frontend/default/custom/$slug/playground_game/$gametype/404.phtml |
||
134 | * |
||
135 | * |
||
136 | * @return \Zend\Stdlib\ResponseInterface |
||
137 | */ |
||
138 | public function notFoundAction() |
||
172 | |||
173 | /** |
||
174 | * This action acts as a hub : Depending on the first step of the game, it will forward the action to this step |
||
175 | */ |
||
176 | public function homeAction() |
||
208 | |||
209 | /** |
||
210 | * Homepage of the game |
||
211 | */ |
||
212 | public function indexAction() |
||
228 | |||
229 | /** |
||
230 | * leaderboardAction |
||
231 | * |
||
232 | * @return ViewModel $viewModel |
||
233 | */ |
||
234 | public function leaderboardAction() |
||
256 | |||
257 | /** |
||
258 | * This action has been designed to be called by other controllers |
||
259 | * It gives the ability to display an information form and persist it in the game entry |
||
260 | * |
||
261 | * @return \Zend\View\Model\ViewModel |
||
262 | */ |
||
263 | public function registerAction() |
||
264 | { |
||
265 | $form = $this->getGameService()->createFormFromJson($this->game->getPlayerForm()->getForm(), 'playerForm'); |
||
266 | |||
267 | if ($this->getRequest()->isPost()) { |
||
268 | // POST Request: Process form |
||
269 | $data = array_merge_recursive( |
||
270 | $this->getRequest()->getPost()->toArray(), |
||
271 | $this->getRequest()->getFiles()->toArray() |
||
272 | ); |
||
273 | |||
274 | $form->setData($data); |
||
275 | |||
276 | if ($form->isValid()) { |
||
277 | // steps of the game |
||
278 | $steps = $this->game->getStepsArray(); |
||
279 | // sub steps of the game |
||
280 | $viewSteps = $this->game->getStepsViewsArray(); |
||
281 | |||
282 | // register position |
||
283 | $key = array_search($this->params('action'), $viewSteps); |
||
284 | View Code Duplication | if (!$key) { |
|
285 | // register is not a substep of the game so it's a step |
||
286 | $key = array_search($this->params('action'), $steps); |
||
287 | $keyStep = true; |
||
288 | } else { |
||
289 | // register was a substep, i search the index of its parent |
||
290 | $key = array_search($key, $steps); |
||
291 | $keyStep = false; |
||
292 | } |
||
293 | |||
294 | // play position |
||
295 | $keyplay = array_search('play', $viewSteps); |
||
296 | |||
297 | View Code Duplication | if (!$keyplay) { |
|
298 | // play is not a substep, so it's a step |
||
299 | $keyplay = array_search('play', $steps); |
||
300 | $keyplayStep = true; |
||
301 | } else { |
||
302 | // play is a substep so I search the index of its parent |
||
303 | $keyplay = array_search($keyplay, $steps); |
||
304 | $keyplayStep = false; |
||
305 | } |
||
306 | |||
307 | // If register step before play, I don't have no entry yet. I have to create one |
||
308 | // If register after play step, I search for the last entry created by play step. |
||
309 | |||
310 | if ($key < $keyplay || ($keyStep && !$keyplayStep && $key <= $keyplay)) { |
||
311 | $entry = $this->getGameService()->play($this->game, $this->user); |
||
312 | if (!$entry) { |
||
313 | // the user has already taken part of this game and the participation limit has been reached |
||
314 | $this->flashMessenger()->addMessage('Vous avez déjà participé'); |
||
315 | |||
316 | return $this->redirect()->toUrl( |
||
317 | $this->frontendUrl()->fromRoute( |
||
318 | $this->game->getClassType().'/result', |
||
319 | array( |
||
320 | 'id' => $this->game->getIdentifier(), |
||
321 | |||
322 | ) |
||
323 | ) |
||
324 | ); |
||
325 | } |
||
326 | } else { |
||
327 | // I'm looking for an entry without anonymousIdentifier (the active entry in fact). |
||
328 | $entry = $this->getGameService()->findLastEntry($this->game, $this->user); |
||
329 | if ($this->getGameService()->hasReachedPlayLimit($this->game, $this->user)) { |
||
330 | // the user has already taken part of this game and the participation limit has been reached |
||
331 | $this->flashMessenger()->addMessage('Vous avez déjà participé'); |
||
332 | |||
333 | return $this->redirect()->toUrl( |
||
334 | $this->frontendUrl()->fromRoute( |
||
335 | $this->game->getClassType().'/result', |
||
336 | array( |
||
337 | 'id' => $this->game->getIdentifier(), |
||
338 | |||
339 | ) |
||
340 | ) |
||
341 | ); |
||
342 | } |
||
343 | } |
||
344 | |||
345 | $this->getGameService()->updateEntryPlayerForm($form->getData(), $this->game, $this->user, $entry); |
||
346 | |||
347 | if (!empty($this->game->nextStep($this->params('action')))) { |
||
348 | return $this->redirect()->toUrl( |
||
349 | $this->frontendUrl()->fromRoute( |
||
350 | $this->game->getClassType() .'/' . $this->game->nextStep($this->params('action')), |
||
351 | array('id' => $this->game->getIdentifier()), |
||
352 | array('force_canonical' => true) |
||
353 | ) |
||
354 | ); |
||
355 | } |
||
356 | } |
||
357 | } |
||
358 | |||
359 | $viewModel = $this->buildView($this->game); |
||
360 | $viewModel->setVariables(array( |
||
361 | 'form' => $form |
||
362 | )); |
||
363 | |||
364 | return $viewModel; |
||
365 | } |
||
366 | |||
367 | /** |
||
368 | * This action takes care of the terms of the game |
||
369 | */ |
||
370 | public function termsAction() |
||
371 | { |
||
372 | $viewModel = $this->buildView($this->game); |
||
373 | |||
374 | return $viewModel; |
||
375 | } |
||
376 | |||
377 | /** |
||
378 | * This action takes care of the conditions of the game |
||
379 | */ |
||
380 | public function conditionsAction() |
||
386 | |||
387 | /** |
||
388 | * This action takes care of bounce page of the game |
||
389 | */ |
||
390 | public function bounceAction() |
||
409 | |||
410 | |||
411 | /** |
||
412 | * This action displays the Prizes page associated to the game |
||
413 | */ |
||
414 | public function prizesAction() |
||
424 | |||
425 | /** |
||
426 | * This action displays a specific Prize page among those associated to the game |
||
427 | */ |
||
428 | public function prizeAction() |
||
442 | |||
443 | public function gameslistAction() |
||
490 | |||
491 | public function fangateAction() |
||
497 | |||
498 | public function shareAction() |
||
499 | { |
||
500 | $statusMail = null; |
||
501 | $lastEntry = null; |
||
502 | |||
503 | // steps of the game |
||
504 | $steps = $this->game->getStepsArray(); |
||
505 | // sub steps of the game |
||
506 | $viewSteps = $this->game->getStepsViewsArray(); |
||
507 | |||
508 | // share position |
||
509 | $key = array_search($this->params('action'), $viewSteps); |
||
510 | View Code Duplication | if (!$key) { |
|
511 | // share is not a substep of the game so it's a step |
||
512 | $key = array_search($this->params('action'), $steps); |
||
513 | $keyStep = true; |
||
514 | } else { |
||
515 | // share was a substep, I search the index of its parent |
||
516 | $key = array_search($key, $steps); |
||
517 | $keyStep = false; |
||
518 | } |
||
519 | |||
520 | // play position |
||
521 | $keyplay = array_search('play', $viewSteps); |
||
522 | |||
523 | View Code Duplication | if (!$keyplay) { |
|
524 | // play is not a substep, so it's a step |
||
525 | $keyplay = array_search('play', $steps); |
||
526 | $keyplayStep = true; |
||
527 | } else { |
||
528 | // play is a substep so I search the index of its parent |
||
529 | $keyplay = array_search($keyplay, $steps); |
||
530 | $keyplayStep = false; |
||
531 | } |
||
532 | |||
533 | if ($key && $keyplay && $keyplay <= $key) { |
||
534 | // Has the user finished the game ? |
||
535 | $lastEntry = $this->getGameService()->findLastInactiveEntry($this->game, $this->user); |
||
536 | |||
537 | View Code Duplication | if ($lastEntry === null) { |
|
538 | return $this->redirect()->toUrl( |
||
539 | $this->frontendUrl()->fromRoute( |
||
540 | $this->game->getClassType(), |
||
541 | array('id' => $this->game->getIdentifier()) |
||
542 | ) |
||
543 | ); |
||
544 | } |
||
545 | } |
||
546 | |||
547 | $form = $this->getServiceLocator()->get('playgroundgame_sharemail_form'); |
||
548 | $form->setAttribute('method', 'post'); |
||
549 | |||
550 | // buildView must be before sendMail because it adds the game template path to the templateStack |
||
551 | $viewModel = $this->buildView($this->game); |
||
552 | |||
553 | if ($this->getRequest()->isPost()) { |
||
554 | $data = $this->getRequest()->getPost()->toArray(); |
||
555 | $form->setData($data); |
||
556 | View Code Duplication | if ($form->isValid()) { |
|
557 | $result = $this->getGameService()->sendShareMail($data, $this->game, $this->user, $lastEntry); |
||
558 | if ($result) { |
||
559 | $statusMail = true; |
||
560 | } |
||
561 | } |
||
562 | } |
||
563 | |||
564 | $viewModel->setVariables(array( |
||
565 | 'statusMail' => $statusMail, |
||
566 | 'form' => $form, |
||
567 | )); |
||
568 | |||
569 | return $viewModel; |
||
570 | } |
||
571 | |||
572 | View Code Duplication | public function fbshareAction() |
|
592 | |||
593 | public function fbrequestAction() |
||
615 | |||
616 | public function tweetAction() |
||
635 | |||
636 | View Code Duplication | public function googleAction() |
|
657 | |||
658 | public function optinAction() |
||
659 | { |
||
660 | $userService = $this->getServiceLocator()->get('zfcuser_user_service'); |
||
661 | |||
662 | if ($this->getRequest()->isPost()) { |
||
663 | $data['optin'] = ($this->params()->fromPost('optin'))? 1:0; |
||
664 | $data['optinPartner'] = ($this->params()->fromPost('optinPartner'))? 1:0; |
||
665 | |||
666 | $userService->updateNewsletter($data); |
||
667 | } |
||
668 | |||
669 | return $this->redirect()->toUrl( |
||
670 | $this->frontendUrl()->fromRoute( |
||
671 | 'frontend/' . $this->game->getClassType() . '/index', |
||
672 | array('id' => $this->game->getIdentifier()) |
||
673 | ) |
||
674 | ); |
||
675 | } |
||
676 | |||
677 | public function loginAction() |
||
678 | { |
||
679 | $request = $this->getRequest(); |
||
680 | $form = $this->getServiceLocator()->get('zfcuser_login_form'); |
||
681 | |||
682 | if ($request->isPost()) { |
||
683 | $form->setData($request->getPost()); |
||
684 | |||
685 | if (!$form->isValid()) { |
||
686 | $this->flashMessenger()->addMessage( |
||
687 | 'Authentication failed. Please try again.' |
||
688 | ); |
||
689 | |||
690 | $viewModel = $this->buildView($this->game); |
||
691 | $viewModel->setVariables(array( |
||
692 | 'form' => $form, |
||
693 | 'flashMessages' => $this->flashMessenger()->getMessages(), |
||
694 | )); |
||
695 | |||
696 | return $viewModel; |
||
697 | } |
||
698 | |||
699 | // clear adapters |
||
700 | $this->zfcUserAuthentication()->getAuthAdapter()->resetAdapters(); |
||
701 | $this->zfcUserAuthentication()->getAuthService()->clearIdentity(); |
||
702 | |||
703 | $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate')); |
||
704 | |||
705 | if (!$logged) { |
||
706 | $this->flashMessenger()->addMessage( |
||
707 | 'Authentication failed. Please try again.' |
||
708 | ); |
||
709 | |||
710 | return $this->redirect()->toUrl( |
||
711 | $this->frontendUrl()->fromRoute( |
||
712 | $this->game->getClassType() . '/login', |
||
713 | array('id' => $this->game->getIdentifier()) |
||
714 | ) |
||
715 | ); |
||
716 | } else { |
||
717 | return $this->redirect()->toUrl( |
||
718 | $this->frontendUrl()->fromRoute( |
||
719 | $this->game->getClassType() . '/index', |
||
720 | array('id' => $this->game->getIdentifier()) |
||
721 | ) |
||
722 | ); |
||
723 | } |
||
724 | } |
||
725 | |||
726 | $form->setAttribute( |
||
727 | 'action', |
||
728 | $this->frontendUrl()->fromRoute( |
||
729 | $this->game->getClassType().'/login', |
||
730 | array('id' => $this->game->getIdentifier()) |
||
731 | ) |
||
732 | ); |
||
733 | $viewModel = $this->buildView($this->game); |
||
734 | $viewModel->setVariables(array( |
||
735 | 'form' => $form, |
||
736 | 'flashMessages' => $this->flashMessenger()->getMessages(), |
||
737 | )); |
||
738 | return $viewModel; |
||
739 | } |
||
740 | |||
741 | public function userregisterAction() |
||
742 | { |
||
743 | $userOptions = $this->getServiceLocator()->get('zfcuser_module_options'); |
||
744 | |||
745 | if ($this->zfcUserAuthentication()->hasIdentity()) { |
||
746 | return $this->redirect()->toUrl( |
||
747 | $this->frontendUrl()->fromRoute( |
||
748 | $this->game->getClassType().'/'.$this->game->nextStep('index'), |
||
749 | array('id' => $this->game->getIdentifier()) |
||
750 | ) |
||
751 | ); |
||
752 | } |
||
753 | $request = $this->getRequest(); |
||
754 | $service = $this->getServiceLocator()->get('zfcuser_user_service'); |
||
755 | $form = $this->getServiceLocator()->get('playgroundgame_register_form'); |
||
756 | $socialnetwork = $this->params()->fromRoute('socialnetwork', false); |
||
757 | $form->setAttribute( |
||
758 | 'action', |
||
759 | $this->frontendUrl()->fromRoute( |
||
760 | $this->game->getClassType().'/user-register', |
||
761 | array('id' => $this->game->getIdentifier()) |
||
762 | ) |
||
763 | ); |
||
764 | $params = array(); |
||
765 | $socialCredentials = array(); |
||
766 | |||
767 | if ($userOptions->getUseRedirectParameterIfPresent() && $request->getQuery()->get('redirect')) { |
||
768 | $redirect = $request->getQuery()->get('redirect'); |
||
769 | } else { |
||
770 | $redirect = false; |
||
771 | } |
||
772 | |||
773 | if ($socialnetwork) { |
||
774 | $infoMe = $this->getProviderService()->getInfoMe($socialnetwork); |
||
775 | |||
776 | if (!empty($infoMe)) { |
||
777 | $user = $this->getProviderService()->getUserProviderMapper()->findUserByProviderId( |
||
778 | $infoMe->identifier, |
||
779 | $socialnetwork |
||
780 | ); |
||
781 | |||
782 | if ($user || $service->getOptions()->getCreateUserAutoSocial() === true) { |
||
783 | //on le dirige vers l'action d'authentification |
||
784 | if (! $redirect && $userOptions->getLoginRedirectRoute() != '') { |
||
785 | $redirect = $this->frontendUrl()->fromRoute( |
||
786 | $this->game->getClassType().'/login', |
||
787 | array('id' => $this->game->getIdentifier()) |
||
788 | ); |
||
789 | } |
||
790 | $redir = $this->frontendUrl()->fromRoute( |
||
791 | $this->game->getClassType().'/login', |
||
792 | array('id' => $this->game->getIdentifier()) |
||
793 | ) .'/' . $socialnetwork . ($redirect ? '?redirect=' . $redirect : ''); |
||
794 | |||
795 | return $this->redirect()->toUrl($redir); |
||
796 | } |
||
797 | |||
798 | // Je retire la saisie du login/mdp |
||
799 | $form->setAttribute( |
||
800 | 'action', |
||
801 | $this->frontendUrl()->fromRoute( |
||
802 | $this->game->getClassType().'/user-register', |
||
803 | array( |
||
804 | 'id' => $this->game->getIdentifier(), |
||
805 | 'socialnetwork' => $socialnetwork, |
||
806 | |||
807 | ) |
||
808 | ) |
||
809 | ); |
||
810 | $form->remove('password'); |
||
811 | $form->remove('passwordVerify'); |
||
812 | |||
813 | $birthMonth = $infoMe->birthMonth; |
||
814 | if (strlen($birthMonth) <= 1) { |
||
815 | $birthMonth = '0'.$birthMonth; |
||
816 | } |
||
817 | $birthDay = $infoMe->birthDay; |
||
818 | if (strlen($birthDay) <= 1) { |
||
819 | $birthDay = '0'.$birthDay; |
||
820 | } |
||
821 | |||
822 | $gender = $infoMe->gender; |
||
823 | if ($gender == 'female') { |
||
824 | $title = 'Me'; |
||
825 | } else { |
||
826 | $title = 'M'; |
||
827 | } |
||
828 | |||
829 | $params = array( |
||
830 | //'birth_year' => $infoMe->birthYear, |
||
831 | 'title' => $title, |
||
832 | 'dob' => $birthDay.'/'.$birthMonth.'/'.$infoMe->birthYear, |
||
833 | 'firstname' => $infoMe->firstName, |
||
834 | 'lastname' => $infoMe->lastName, |
||
835 | 'email' => $infoMe->email, |
||
836 | 'postalCode' => $infoMe->zip, |
||
837 | ); |
||
838 | $socialCredentials = array( |
||
839 | 'socialNetwork' => strtolower($socialnetwork), |
||
840 | 'socialId' => $infoMe->identifier, |
||
841 | ); |
||
842 | } |
||
843 | } |
||
844 | |||
845 | $redirectUrl = $this->frontendUrl()->fromRoute( |
||
846 | $this->game->getClassType().'/user-register', |
||
847 | array('id' => $this->game->getIdentifier()) |
||
848 | ) .($socialnetwork ? '/' . $socialnetwork : ''). ($redirect ? '?redirect=' . $redirect : ''); |
||
849 | $prg = $this->prg($redirectUrl, true); |
||
850 | |||
851 | if ($prg instanceof Response) { |
||
852 | return $prg; |
||
853 | } elseif ($prg === false) { |
||
854 | $form->setData($params); |
||
855 | $viewModel = $this->buildView($this->game); |
||
856 | $viewModel->setVariables(array( |
||
857 | 'registerForm' => $form, |
||
858 | 'enableRegistration' => $userOptions->getEnableRegistration(), |
||
859 | 'redirect' => $redirect, |
||
860 | )); |
||
861 | return $viewModel; |
||
862 | } |
||
863 | |||
864 | $post = $prg; |
||
865 | $post = array_merge( |
||
866 | $post, |
||
867 | $socialCredentials |
||
868 | ); |
||
869 | |||
870 | if ($this->game->getOnInvitation()) { |
||
871 | $credential = trim( |
||
872 | $post[$this->getGameService()->getOptions()->getOnInvitationField()] |
||
873 | ); |
||
874 | if (!$credential) { |
||
875 | $credential = $this->params()->fromQuery( |
||
876 | $this->getGameService()->getOptions()->getOnInvitationField() |
||
877 | ); |
||
878 | } |
||
879 | $found = $this->getGameService()->getInvitationMapper()->findOneBy(array('requestKey'=>$credential)); |
||
880 | |||
881 | if (!$found || !empty($found->getUser())) { |
||
882 | $this->flashMessenger()->addMessage( |
||
883 | 'Authentication failed. Please try again.' |
||
884 | ); |
||
885 | $form->setData($post); |
||
886 | $viewModel = $this->buildView($this->game); |
||
887 | $viewModel->setVariables(array( |
||
888 | 'registerForm' => $form, |
||
889 | 'enableRegistration' => $userOptions->getEnableRegistration(), |
||
890 | 'redirect' => $redirect, |
||
891 | 'flashMessages' => $this->flashMessenger()->getMessages(), |
||
892 | 'flashErrors' => $this->flashMessenger()->getErrorMessages(), |
||
893 | )); |
||
894 | |||
895 | return $viewModel; |
||
896 | } |
||
897 | } |
||
898 | |||
899 | $user = $service->register($post, 'playgroundgame_register_form'); |
||
900 | |||
901 | if (! $user) { |
||
902 | $viewModel = $this->buildView($this->game); |
||
903 | $viewModel->setVariables(array( |
||
904 | 'registerForm' => $form, |
||
905 | 'enableRegistration' => $userOptions->getEnableRegistration(), |
||
906 | 'redirect' => $redirect, |
||
907 | )); |
||
908 | |||
909 | return $viewModel; |
||
910 | } |
||
911 | |||
912 | if ($this->game->getOnInvitation()) { |
||
913 | // user has been created, associate the code with the userId |
||
914 | $found->setUser($user); |
||
915 | $this->getGameService()->getInvitationMapper()->update($found); |
||
916 | } |
||
917 | |||
918 | if ($service->getOptions()->getEmailVerification()) { |
||
919 | $vm = new ViewModel(array('userEmail' => $user->getEmail())); |
||
920 | $vm->setTemplate('playground-user/register/registermail'); |
||
921 | |||
922 | return $vm; |
||
923 | } elseif ($service->getOptions()->getLoginAfterRegistration()) { |
||
924 | $identityFields = $service->getOptions()->getAuthIdentityFields(); |
||
925 | if (in_array('email', $identityFields)) { |
||
926 | $post['identity'] = $user->getEmail(); |
||
927 | } elseif (in_array('username', $identityFields)) { |
||
928 | $post['identity'] = $user->getUsername(); |
||
929 | } |
||
930 | $post['credential'] = isset($post['password'])?$post['password']:''; |
||
931 | $request->setPost(new Parameters($post)); |
||
932 | |||
933 | // clear adapters |
||
934 | $this->zfcUserAuthentication()->getAuthAdapter()->resetAdapters(); |
||
935 | $this->zfcUserAuthentication()->getAuthService()->clearIdentity(); |
||
936 | |||
937 | $logged = $this->forward()->dispatch('playgrounduser_user', array('action' => 'ajaxauthenticate')); |
||
938 | |||
939 | if ($logged) { |
||
940 | return $this->redirect()->toUrl( |
||
941 | $this->frontendUrl()->fromRoute( |
||
942 | $this->game->getClassType(), |
||
943 | array('id' => $this->game->getIdentifier()) |
||
944 | ) |
||
945 | ); |
||
946 | } else { |
||
947 | $this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage( |
||
948 | 'Authentication failed. Please try again.' |
||
949 | ); |
||
950 | return $this->redirect()->toUrl( |
||
951 | $this->frontendUrl()->fromRoute( |
||
952 | $this->game->getClassType() . '/login', |
||
953 | array('id' => $this->game->getIdentifier()) |
||
954 | ) |
||
955 | ); |
||
956 | } |
||
957 | } |
||
958 | |||
959 | $redirect = $this->frontendUrl()->fromRoute( |
||
960 | $this->game->getClassType().'/login', |
||
961 | array( |
||
962 | 'id' => $this->game->getIdentifier(), |
||
963 | |||
964 | ) |
||
965 | ) . ($socialnetwork ? '/' . $socialnetwork : ''). ($redirect ? '?redirect=' . $redirect : ''); |
||
966 | |||
967 | return $this->redirect()->toUrl($redirect); |
||
968 | } |
||
969 | |||
970 | View Code Duplication | public function userProfileAction() |
|
988 | |||
989 | View Code Duplication | public function cmsPageAction() |
|
1008 | |||
1009 | View Code Duplication | public function cmsListAction() |
|
1028 | |||
1029 | /** |
||
1030 | * |
||
1031 | * @param \PlaygroundGame\Entity\Game $game |
||
1032 | * @param \PlaygroundUser\Entity\User $user |
||
1033 | */ |
||
1034 | public function checkFbRegistration($user, $game) |
||
1083 | |||
1084 | /** |
||
1085 | * This method create the basic Game view |
||
1086 | * @param \PlaygroundGame\Entity\Game $game |
||
1087 | */ |
||
1088 | public function buildView($game) |
||
1089 | { |
||
1090 | if ($this->getRequest()->isXmlHttpRequest()) { |
||
1091 | $viewModel = new JsonModel(); |
||
1092 | if ($game) { |
||
1093 | $view = $this->addAdditionalView($game); |
||
1094 | if ($view && $view instanceof \Zend\View\Model\ViewModel) { |
||
1095 | $viewModel->setVariables($view->getVariables()); |
||
1096 | } |
||
1097 | } |
||
1098 | } else { |
||
1099 | $viewModel = new ViewModel(); |
||
1100 | |||
1101 | if ($game) { |
||
1102 | $this->addMetaTitle($game); |
||
1103 | $this->addMetaBitly(); |
||
1104 | $this->addGaEvent($game); |
||
1105 | |||
1106 | $this->customizeGameDesign($game); |
||
1107 | |||
1108 | $view = $this->addAdditionalView($game); |
||
1109 | if ($view && $view instanceof \Zend\View\Model\ViewModel) { |
||
1110 | $viewModel->addChild($view, 'additional'); |
||
1111 | } elseif ($view && $view instanceof \Zend\Http\PhpEnvironment\Response) { |
||
1112 | return $view; |
||
1113 | } |
||
1114 | |||
1115 | $this->layout()->setVariables( |
||
1116 | array( |
||
1117 | 'action' => $this->params('action'), |
||
1118 | 'game' => $game, |
||
1119 | 'flashMessages' => $this->flashMessenger()->getMessages(), |
||
1120 | |||
1121 | ) |
||
1122 | ); |
||
1123 | } |
||
1124 | } |
||
1125 | |||
1126 | if ($game) { |
||
1127 | $viewModel->setVariables($this->getShareData($game)); |
||
1128 | $viewModel->setVariables(array('game' => $game, 'user' => $this->user)); |
||
1129 | } |
||
1130 | |||
1131 | return $viewModel; |
||
1132 | } |
||
1133 | |||
1134 | /** |
||
1135 | * @param \PlaygroundGame\Entity\Game $game |
||
1136 | */ |
||
1137 | public function addAdditionalView($game) |
||
1138 | { |
||
1139 | $view = false; |
||
1140 | |||
1141 | $actionName = $this->getEvent()->getRouteMatch()->getParam('action', 'not-found'); |
||
1142 | $stepsViews = json_decode($game->getStepsViews(), true); |
||
1143 | if ($stepsViews && isset($stepsViews[$actionName])) { |
||
1144 | $beforeLayout = $this->layout()->getTemplate(); |
||
1145 | $actionData = $stepsViews[$actionName]; |
||
1146 | if (is_string($actionData)) { |
||
1147 | $action = $actionData; |
||
1148 | $controller = $this->getEvent()->getRouteMatch()->getParam('controller', 'playgroundgame_game'); |
||
1149 | $view = $this->forward()->dispatch( |
||
1150 | $controller, |
||
1151 | array( |
||
1152 | 'action' => $action, |
||
1153 | 'id' => $game->getIdentifier() |
||
1154 | ) |
||
1155 | ); |
||
1156 | } elseif (is_array($actionData) && count($actionData)>0) { |
||
1157 | $action = key($actionData); |
||
1158 | $controller = $actionData[$action]; |
||
1159 | $view = $this->forward()->dispatch( |
||
1160 | $controller, |
||
1161 | array( |
||
1162 | 'action' => $action, |
||
1163 | 'id' => $game->getIdentifier() |
||
1164 | ) |
||
1165 | ); |
||
1166 | } |
||
1167 | // suite au forward, le template de layout a changé, je dois le rétablir... |
||
1168 | $this->layout()->setTemplate($beforeLayout); |
||
1169 | } |
||
1170 | |||
1171 | return $view; |
||
1172 | } |
||
1173 | |||
1174 | public function addMetaBitly() |
||
1184 | |||
1185 | /** |
||
1186 | * @param \PlaygroundGame\Entity\Game $game |
||
1187 | */ |
||
1188 | public function addGaEvent($game) |
||
1196 | |||
1197 | /** |
||
1198 | * @param \PlaygroundGame\Entity\Game $game |
||
1199 | */ |
||
1200 | public function addMetaTitle($game) |
||
1220 | |||
1221 | /** |
||
1222 | * @param \PlaygroundGame\Entity\Game $game |
||
1223 | */ |
||
1224 | public function customizeGameDesign($game) |
||
1239 | |||
1240 | /** |
||
1241 | * @param \PlaygroundGame\Entity\Game $game |
||
1242 | */ |
||
1243 | public function getShareData($game) |
||
1329 | |||
1330 | /** |
||
1331 | * return ajax response in json format |
||
1332 | * |
||
1333 | * @param array $data |
||
1334 | * @return \Zend\View\Model\JsonModel |
||
1335 | */ |
||
1336 | View Code Duplication | protected function successJson($data = null) |
|
1344 | |||
1345 | /** |
||
1346 | * return ajax response in json format |
||
1347 | * |
||
1348 | * @param string $message |
||
1349 | * @return \Zend\View\Model\JsonModel |
||
1350 | */ |
||
1351 | View Code Duplication | protected function errorJson($message = null) |
|
1359 | |||
1360 | /** |
||
1361 | * @param string $helperName |
||
1362 | */ |
||
1363 | protected function getViewHelper($helperName) |
||
1367 | |||
1368 | public function getGameService() |
||
1376 | |||
1377 | public function setGameService(GameService $gameService) |
||
1383 | |||
1384 | public function getPrizeService() |
||
1392 | |||
1393 | public function setPrizeService(PrizeService $prizeService) |
||
1399 | |||
1400 | public function getOptions() |
||
1408 | |||
1409 | public function setOptions($options) |
||
1415 | } |
||
1416 |
If you implement
__call
and 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
__call
is implemented by a parent class and only the child class knows which methods exist: