diff --git a/app/DoctrineMigrations/Version20160120180223.php b/app/DoctrineMigrations/Version20160120180223.php new file mode 100644 index 00000000..04ed8301 --- /dev/null +++ b/app/DoctrineMigrations/Version20160120180223.php @@ -0,0 +1,34 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE intra_Tournament ADD maxManager INT DEFAULT NULL'); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE intra_Tournament DROP maxManager'); + } +} diff --git a/src/InsaLan/TournamentBundle/Admin/ManagerAdmin.php b/src/InsaLan/TournamentBundle/Admin/ManagerAdmin.php new file mode 100644 index 00000000..6da5f877 --- /dev/null +++ b/src/InsaLan/TournamentBundle/Admin/ManagerAdmin.php @@ -0,0 +1,50 @@ +add('user') + ->add('gameName') + ->add('tournament') + ->add('participant') + ->add('paymentDone', null, array('required'=>false)) + ->add('arrived', null, array('required'=>false)) + ; + } + + // Fields to be shown on filter forms + protected function configureDatagridFilters(DatagridMapper $datagridMapper) + { + $datagridMapper + ->add('gameName') + ->add('user.username') + ->add('user.email') + ->add('tournament') + ->add('arrived') + ; + } + + // Fields to be shown on lists + protected function configureListFields(ListMapper $listMapper) + { + $listMapper + ->addIdentifier('user.username') + ->addIdentifier('gameName') + ->add('tournament') + ->add('user.email') + ->add('paymentDone') + ->add('arrived') + ; + } + +} diff --git a/src/InsaLan/TournamentBundle/Admin/PlayerAdmin.php b/src/InsaLan/TournamentBundle/Admin/PlayerAdmin.php index 76f6e22f..2b5d0ee0 100644 --- a/src/InsaLan/TournamentBundle/Admin/PlayerAdmin.php +++ b/src/InsaLan/TournamentBundle/Admin/PlayerAdmin.php @@ -15,6 +15,7 @@ protected function configureFormFields(FormMapper $formMapper) $formMapper ->add('user') ->add('team') + ->add('manager') ->add('gameName') ->add('gameValidated', null, array('required'=>false)) ->add('gameAvatar') diff --git a/src/InsaLan/TournamentBundle/Admin/TeamAdmin.php b/src/InsaLan/TournamentBundle/Admin/TeamAdmin.php index 4b92aaf0..c904d75d 100644 --- a/src/InsaLan/TournamentBundle/Admin/TeamAdmin.php +++ b/src/InsaLan/TournamentBundle/Admin/TeamAdmin.php @@ -19,6 +19,7 @@ protected function configureFormFields(FormMapper $formMapper) ->add('name') ->add('tournament') ->add('captain') + ->add('manager') ->add('validated', 'choice', array( 'required' => true, 'choices' => array( diff --git a/src/InsaLan/TournamentBundle/Controller/ManagerController.php b/src/InsaLan/TournamentBundle/Controller/ManagerController.php index 7284b9db..9b0ba8e1 100644 --- a/src/InsaLan/TournamentBundle/Controller/ManagerController.php +++ b/src/InsaLan/TournamentBundle/Controller/ManagerController.php @@ -22,11 +22,13 @@ use Payum\Paypal\ExpressCheckout\Nvp\Api; use InsaLan\TournamentBundle\Form\SetManagerName; +use InsaLan\TournamentBundle\Form\SetPlayerName; use InsaLan\TournamentBundle\Form\TeamLoginType; use InsaLan\TournamentBundle\Exception\ControllerException; use InsaLan\TournamentBundle\Entity\Manager; use InsaLan\TournamentBundle\Entity\Participant; +use InsaLan\TournamentBundle\Entity\Player; use InsaLan\TournamentBundle\Entity\Tournament; use InsaLan\TournamentBundle\Entity\Team; use InsaLan\TournamentBundle\Entity; @@ -87,17 +89,78 @@ public function setNameAction(Request $request, Entity\Tournament $tournament) $em->persist($manager); $em->flush(); - return $this->redirect( - $this->generateUrl('insalan_tournament_manager_jointeamwithpassword', array('tournament' => $tournament->getId())) - ); + if($tournament->getParticipantType() === "team") + return $this->redirect( + $this->generateUrl('insalan_tournament_manager_jointeamwithpassword', array('tournament' => $tournament->getId())) + ); + else // solo tournaments + return $this->redirect( + $this->generateUrl('insalan_tournament_manager_joinsoloplayer', array('tournament' => $tournament->getId())) + ); } return array('form' => $form->createView(), 'selectedGame' => $tournament->getType(), 'tournamentId' => $tournament->getId()); } + /** + * Allow a manager to join a player in a solo tournament + * @Route("/{tournament}/user/joinplayer") + * @Template() + */ + public function joinSoloPlayerAction(Request $request, Entity\Tournament $tournament) + { + $em = $this->getDoctrine()->getManager(); + $usr = $this->get('security.context')->getToken()->getUser(); + + // handle only solo tournaments + if($tournament->getParticipantType() !== "player") + throw new ControllerException("Joueurs solo non acceptées dans ce tournois"); + + // check if there is already a pending manager for this user and tournament + $manager = $em->getRepository('InsaLanTournamentBundle:Manager') + ->findOneByUserAndPendingTournament($usr, $tournament); + + if($manager === null) + return $this->redirect($this->generateUrl('insalan_tournament_manager_setname', array('tournament' => $tournament->getId()))); + + $form_player = new Player(); + $form = $this->createForm(new SetPlayerName(), $form_player); // fill player gamename + $form->handleRequest($request); + + $error_details = null; + if ($form->isValid()) { + try { + // find the targeted player related to the manager + $player = $em + ->getRepository('InsaLanTournamentBundle:Player') + ->findOneBy(array( + 'gameName' => $form_player->getGameName(), + 'tournament' => $tournament)); + + if ($player === null) + throw new ControllerException("Joueur introuvable !"); + if ($player->getManager() != null) + throw new ControllerException("Le joueur possède déjà un manager !"); + + $manager->setParticipant($player); + $player->setManager($manager); + $em->persist($manager); + $em->persist($player); + $em->flush(); + + return $this->redirect($this->generateUrl('insalan_tournament_manager_pay', array('tournament' => $tournament->getId()))); + + } catch (ControllerException $e) { + $error_details = $e->getMessage(); + } + + } + return array('tournament' => $tournament, 'user' => $usr, 'manager' => $manager, 'error' => $error_details, 'form' => $form->createView()); + } + /** * Allow a new manager to join a team with name and password - * @Route("/{tournament}/user/setname") + * @Route("/{tournament}/user/jointeam") * @Template() */ public function joinTeamWithPasswordAction(Request $request, Entity\Tournament $tournament) @@ -300,9 +363,10 @@ public function payOfflineAction(Request $request, Entity\Tournament $tournament return array('tournament' => $tournament, 'user' => $usr, 'manager' => $manager); } - + /** * Allow a manager to drop a pending tournament registration if not managed by team + * TODO add flashbag confirmation * @Route("/{tournament}/user/leave") */ public function leaveAction(Entity\Tournament $tournament) { @@ -316,6 +380,17 @@ public function leaveAction(Entity\Tournament $tournament) { if($manager->getTournament()->getParticipantType() !== "player") throw new ControllerException("Not Allowed"); // must be a player only tournament + // not allowed if he paid something + if(!$tournament->isFree() && $manager->getPaymentDone()){ + $this->get('session')->getFlashBag()->add('error', "Vous avez payé votre place, merci de contacter l'InsaLan si vous souhaitez vous désister."); + return $this->redirect($this->generateUrl('insalan_tournament_user_index')); + } + // not allowed either if registration are closed + if(!$tournament->isOpenedNow()) + return $this->redirect($this->generateUrl('insalan_tournament_user_index')); + + $manager->getParticipant()->setManager(null); + $manager->setParticipant(null); $em->remove($manager); $em->flush(); @@ -324,8 +399,8 @@ public function leaveAction(Entity\Tournament $tournament) { /** * Allow a manager to drop a pending tournament registration managed by teams + * TODO add flashbag confirmation * @Route("/user/leave/team/{teamId}") - * @Template() */ public function leaveTeamAction($teamId) { $em = $this->getDoctrine()->getManager(); @@ -353,7 +428,7 @@ public function leaveTeamAction($teamId) { } // not allowed either if registration are closed if(!$team->getTournament()->isOpenedNow()) - return $this->redirect($this->generateUrl('insalan_tournament_user_index')); + return $this->redirect($this->generateUrl('insalan_tournament_user_index')); $manager->setParticipant(null); $team->setManager(null); @@ -361,6 +436,7 @@ public function leaveTeamAction($teamId) { $em->persist($team); $em->remove($manager); $em->flush(); + return $this->redirect($this->generateUrl('insalan_tournament_user_index')); } diff --git a/src/InsaLan/TournamentBundle/Entity/ManagerRepository.php b/src/InsaLan/TournamentBundle/Entity/ManagerRepository.php index d7f054f4..abdcd6c2 100644 --- a/src/InsaLan/TournamentBundle/Entity/ManagerRepository.php +++ b/src/InsaLan/TournamentBundle/Entity/ManagerRepository.php @@ -4,12 +4,6 @@ use Doctrine\ORM\EntityRepository; -/** - * ManagerRepository - * - * This class was generated by the Doctrine ORM. Add your own custom - * repository methods below. - */ class ManagerRepository extends EntityRepository { public function findOneByUserAndPendingTournament(\InsaLan\UserBundle\Entity\User $u, Tournament $t) { diff --git a/src/InsaLan/TournamentBundle/Entity/Tournament.php b/src/InsaLan/TournamentBundle/Entity/Tournament.php index ea642292..5719ad1a 100644 --- a/src/InsaLan/TournamentBundle/Entity/Tournament.php +++ b/src/InsaLan/TournamentBundle/Entity/Tournament.php @@ -104,6 +104,14 @@ class Tournament */ protected $teamMaxPlayer; + /** + * Maximum number of manager allowed on the tournament. + * Only for solo tournaments at the moment. + * + * @ORM\Column(type="integer", nullable=true) + */ + protected $maxManager; + /** * @ORM\Column(type="string", nullable=true) */ @@ -451,6 +459,27 @@ public function getTeamMaxPlayer() return $this->teamMaxPlayer; } + /** + * Get the maximum allowed number of manager + * + * @return integer + */ + public function getMaxManager() + { + return $this->maxManager; + } + + /** + * Set the maximum allowed number of manager + */ + public function setMaxManager($maxManager) + { + $this->maxManager = $maxManager; + + return $this; + } + + /** * Set participantType * diff --git a/src/InsaLan/TournamentBundle/Form/SetPlayerName.php b/src/InsaLan/TournamentBundle/Form/SetPlayerName.php index 9f3c463b..8ed7f97d 100644 --- a/src/InsaLan/TournamentBundle/Form/SetPlayerName.php +++ b/src/InsaLan/TournamentBundle/Form/SetPlayerName.php @@ -8,7 +8,7 @@ class SetPlayerName extends AbstractType { - /** + /** * @param FormBuilderInterface $builder * @param array $options */ @@ -18,7 +18,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('gameName') ; } - + /** * @param OptionsResolverInterface $resolver */ diff --git a/src/InsaLan/TournamentBundle/Form/TeamType.php b/src/InsaLan/TournamentBundle/Form/TeamType.php index 3a3d60ad..f1c612bb 100644 --- a/src/InsaLan/TournamentBundle/Form/TeamType.php +++ b/src/InsaLan/TournamentBundle/Form/TeamType.php @@ -8,7 +8,7 @@ class TeamType extends AbstractType { - /** + /** * @param FormBuilderInterface $builder * @param array $options */ @@ -24,7 +24,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) )) ; } - + /** * @param OptionsResolverInterface $resolver */ diff --git a/src/InsaLan/TournamentBundle/Resources/config/services.yml b/src/InsaLan/TournamentBundle/Resources/config/services.yml index 504ef260..b1924b1a 100644 --- a/src/InsaLan/TournamentBundle/Resources/config/services.yml +++ b/src/InsaLan/TournamentBundle/Resources/config/services.yml @@ -43,6 +43,17 @@ services: calls: - [ setTranslationDomain, [InsaLanTournamentBundle]] + sonata.admin.tournament.manager: + class: InsaLan\TournamentBundle\Admin\ManagerAdmin + tags: + - { name: sonata.admin, manager_type: orm, group: "Tournois", label: "Manager" } + arguments: + - ~ + - InsaLan\TournamentBundle\Entity\Manager + - ~ + calls: + - [ setTranslationDomain, [InsaLanTournamentBundle]] + sonata.admin.tournament.team: class: InsaLan\TournamentBundle\Admin\TeamAdmin tags: diff --git a/src/InsaLan/TournamentBundle/Resources/views/Manager/JoinSoloPlayerActive.html.twig b/src/InsaLan/TournamentBundle/Resources/views/Manager/JoinSoloPlayerActive.html.twig new file mode 100644 index 00000000..5454b7df --- /dev/null +++ b/src/InsaLan/TournamentBundle/Resources/views/Manager/JoinSoloPlayerActive.html.twig @@ -0,0 +1,31 @@ +{% if error %} +
+
+
+ {{ counter }} +
+
Coacher un joueur inscrit
+
+
+
+

{{ error }}

+
+{% else %} +
+
+
+ {{ counter }} +
+
Coacher un joueur inscrit
+
+
+{% endif %} + +
+ +
+ +
+ Ok +
+
diff --git a/src/InsaLan/TournamentBundle/Resources/views/Manager/JoinSoloPlayerValidated.html.twig b/src/InsaLan/TournamentBundle/Resources/views/Manager/JoinSoloPlayerValidated.html.twig new file mode 100644 index 00000000..34091b5d --- /dev/null +++ b/src/InsaLan/TournamentBundle/Resources/views/Manager/JoinSoloPlayerValidated.html.twig @@ -0,0 +1,9 @@ +
+
+
+ {{ counter }} +
+
Joueur sélectionnée : {{ manager.participant }}
+
+
+
\ No newline at end of file diff --git a/src/InsaLan/TournamentBundle/Resources/views/Manager/joinSoloPlayer.html.twig b/src/InsaLan/TournamentBundle/Resources/views/Manager/joinSoloPlayer.html.twig new file mode 100644 index 00000000..28154906 --- /dev/null +++ b/src/InsaLan/TournamentBundle/Resources/views/Manager/joinSoloPlayer.html.twig @@ -0,0 +1,25 @@ +{% extends 'InsaLanTournamentBundle::layout.html.twig' %} + +{% block body %} +{{ parent() }} + +
+ + +
+

Rejoindre le tournoi « {{ tournament.name }} » en tant que manager

+ {{ tournament.description }} +
+ +
+ + {% include 'InsaLanTournamentBundle:Manager:ChooseManagerNameValidated.html.twig' with {'counter': 1}%} + {% include 'InsaLanTournamentBundle:Manager:JoinSoloPlayerActive.html.twig' with {'counter': 2}%} + +
+
+{% endblock %} diff --git a/src/InsaLan/TournamentBundle/Resources/views/Manager/pay.html.twig b/src/InsaLan/TournamentBundle/Resources/views/Manager/pay.html.twig index d25a94d7..44f4cc0a 100644 --- a/src/InsaLan/TournamentBundle/Resources/views/Manager/pay.html.twig +++ b/src/InsaLan/TournamentBundle/Resources/views/Manager/pay.html.twig @@ -22,9 +22,9 @@ {% include 'InsaLanTournamentBundle:Manager:CreateJoinTeamValidated.html.twig' with {'counter': 2}%} {% include 'InsaLanTournamentBundle:Manager:BeforePaymentActive.html.twig' with {'counter': 3}%} {% else %} - {% include 'InsaLanTournamentBundle:Manager:ChooseGameNameValidated.html.twig' with {'counter': 1}%} - {# player choice must be here if not given by URL #} - {% include 'InsaLanTournamentBundle:Manager:BeforePaymentActive.html.twig' with {'counter': 2} %} + {% include 'InsaLanTournamentBundle:Manager:ChooseManagerNameValidated.html.twig' with {'counter': 1}%} + {% include 'InsaLanTournamentBundle:Manager:JoinSoloPlayerValidated.html.twig' with {'counter': 2} %} + {% include 'InsaLanTournamentBundle:Manager:BeforePaymentActive.html.twig' with {'counter': 3} %} {% endif %} diff --git a/src/InsaLan/TournamentBundle/Resources/views/Manager/payDone.html.twig b/src/InsaLan/TournamentBundle/Resources/views/Manager/payDone.html.twig index 19c72923..4b415064 100644 --- a/src/InsaLan/TournamentBundle/Resources/views/Manager/payDone.html.twig +++ b/src/InsaLan/TournamentBundle/Resources/views/Manager/payDone.html.twig @@ -23,9 +23,10 @@ {% include 'InsaLanTournamentBundle:Manager:BeforePaymentValidated.html.twig' with {'counter': 3}%} {% include 'InsaLanTournamentBundle:Manager:AfterPaymentActive.html.twig' with {'counter': 4} %} {% else %} - {% include 'InsaLanTournamentBundle:Manager:ChooseGameNameValidated.html.twig' with {'counter': 1} %} - {% include 'InsaLanTournamentBundle:Manager:BeforePaymentValidated.html.twig' with {'counter': 2} %} - {% include 'InsaLanTournamentBundle:Manager:AfterPaymentActive.html.twig' with {'counter': 3} %} + {% include 'InsaLanTournamentBundle:Manager:ChooseManagerNameValidated.html.twig' with {'counter': 1} %} + {% include 'InsaLanTournamentBundle:Manager:JoinSoloPlayerValidated.html.twig' with {'counter': 2} %} + {% include 'InsaLanTournamentBundle:Manager:BeforePaymentValidated.html.twig' with {'counter': 3} %} + {% include 'InsaLanTournamentBundle:Manager:AfterPaymentActive.html.twig' with {'counter': 4} %} {% endif %} diff --git a/src/InsaLan/TournamentBundle/Resources/views/User/index.html.twig b/src/InsaLan/TournamentBundle/Resources/views/User/index.html.twig index ce76cd49..db0cc1da 100644 --- a/src/InsaLan/TournamentBundle/Resources/views/User/index.html.twig +++ b/src/InsaLan/TournamentBundle/Resources/views/User/index.html.twig @@ -67,6 +67,19 @@
{% endif %} + {% endif %}{# paticipantType == 'team' #} + {% if participant.participantType == 'player' and participant.manager is not null %} + {% endif %}
@@ -95,11 +108,14 @@ {% endif %} - {% if participant.participantType == 'team' and participant.manager is not null and participant.manager.user == app.user %} + {% if participant.manager is not null and participant.manager.user == app.user %} {# 2-button layout #}{% if participant.tournament.isOpenedNow %} - Annuler - Mon inscription - + {% if participant.participantType == 'team' %} + Annuler + {% elseif participant.participantType == 'player' %} + Annuler + {% endif %} + Mon inscription {# tournament is closed #}{% else %} Inscription archivée {% endif %} @@ -161,13 +177,13 @@

{{ t.name }}{% if t.isFull %} - COMPLET {% endif %}

- {% if t.participantType == 'team' %} -
Inscription manager - {% endif %} + + Inscription manager {% if t.isFull and t.participantType == 'team' %} Rejoindre une équipe {% endif %} {% if not t.isFull %}Inscription joueur{% endif %} +

{{ t.teamMinPlayer }} joueur(s) -