/Classes/Controller/GameController.php

https://bitbucket.org/trotzek/uua_lan · PHP · 151 lines · 67 code · 16 blank · 68 comment · 5 complexity · 306d18ada6dce68dd9e4c58d922a7e1a MD5 · raw file

  1. <?php
  2. namespace UUA\Lan\Controller;
  3. use TYPO3\CMS\Core\Messaging\FlashMessage;
  4. use UUA\Lan\Domain\Model\Game;
  5. use UUA\Lan\Domain\Model\LanParty;
  6. use UUA\Lan\Domain\Model\Participant;
  7. /***************************************************************
  8. * Copyright notice
  9. *
  10. * (c) 2013
  11. * All rights reserved
  12. *
  13. * This script is part of the TYPO3 project. The TYPO3 project is
  14. * free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * The GNU General Public License can be found at
  20. * http://www.gnu.org/copyleft/gpl.html.
  21. *
  22. * This script is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * This copyright notice MUST APPEAR in all copies of the script!
  28. ***************************************************************/
  29. /**
  30. *
  31. *
  32. * @package lan
  33. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
  34. *
  35. */
  36. class GameController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
  37. /**
  38. * gameRepository
  39. *
  40. * @var \UUA\Lan\Domain\Repository\GameRepository
  41. * @inject
  42. */
  43. protected $gameRepository;
  44. /**
  45. * participantRepository
  46. *
  47. * @var \UUA\Lan\Domain\Repository\ParticipantRepository
  48. * @inject
  49. */
  50. protected $participantRepository;
  51. /**
  52. * @var \UUA\Lan\Domain\Repository\LanPartyRepository
  53. * @inject
  54. */
  55. protected $lanPartyRepository;
  56. /**
  57. * action list
  58. */
  59. public function listAction() {
  60. $fe_user = $GLOBALS['TSFE']->fe_user->user;
  61. $fe_user = $this->participantRepository->findByUid($fe_user['uid']);
  62. $games = $this->gameRepository->findByLanParty($this->settings['activeLanParty']);
  63. $this->view->assign('loggedInUser', $fe_user);
  64. $this->view->assign('games', $games);
  65. }
  66. /**
  67. * action new
  68. *
  69. * @param \UUA\Lan\Domain\Model\Game $newGame
  70. * @dontvalidate $newGame
  71. */
  72. public function newAction($newGame = NULL) {
  73. $this->view->assign('newGame', $newGame);
  74. }
  75. /**
  76. * action create
  77. *
  78. * @param \UUA\Lan\Domain\Model\Game $newGame
  79. */
  80. public function createAction($newGame) {
  81. /** @var Participant $participant */
  82. $participant = $this->participantRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
  83. /** @var LanParty $lanParty */
  84. $lanParty = $this->lanPartyRepository->findByUid(intval($this->settings['activeLanParty']));
  85. $newGame->addCreator($participant);
  86. $newGame->setLanParty($lanParty);
  87. if ($this->gameRepository->containsGame($newGame, $this->settings['activeLanParty'])){
  88. $this->addFlashMessage("Dieses Spiel ist in der Liste bereits vorhanden", "Fehler", FlashMessage::ERROR);
  89. }elseif($newGame->getDescription() === ""){
  90. $this->addFlashMessage("Bitte gib einen Spieletitel an", "Fehler", FlashMessage::ERROR);
  91. }else{
  92. $this->gameRepository->add($newGame);
  93. $this->addFlashMessage('Das Spiel "'.$newGame->getDescription().'" wurde der Liste erfolgreich hinzugefügt.', "Spiel hinzugefügt", FlashMessage::OK);
  94. }
  95. $this->redirect('list');
  96. }
  97. /**
  98. * @param array $owner
  99. * @param array $voter
  100. * @return void
  101. */
  102. public function updateVotesAction($owner, $voter) {
  103. $fe_user = $GLOBALS['TSFE']->fe_user->user;
  104. /** @var Participant $fe_user */
  105. $fe_user = $this->participantRepository->findByUid($fe_user['uid']);
  106. $games = $this->gameRepository->findByLanParty(intval($this->settings['activeLanParty']));
  107. /** @var Game $game */
  108. foreach ($games as $game){
  109. if($game->getOwner()->contains($fe_user)){
  110. $game->removeOwner($fe_user);
  111. }
  112. if($game->getVoter()->contains($fe_user)){
  113. $game->removeVoter($fe_user);
  114. }
  115. $this->gameRepository->update($game);
  116. }
  117. foreach ($owner as $own){
  118. $game = $this->gameRepository->findByUid($own);
  119. if($game instanceof Game){
  120. $game->addOwner($fe_user);
  121. $this->gameRepository->update($game);
  122. }
  123. }
  124. foreach ($voter as $vote){
  125. $game = $this->gameRepository->findByUid($vote);
  126. if($game instanceof Game){
  127. $game->addVoter($fe_user);
  128. $this->gameRepository->update($game);
  129. }
  130. }
  131. $this->addFlashMessage("Du hast Deine Stimme erfolgreich abgegeben. Du kannst Sie innerhalb der Abstimmungsphase jederzeit ändern.", "Erfolg");
  132. $this->redirect('list');
  133. }
  134. }
  135. ?>