From 43f9299aaa44311cff21125ac80322de95d52610 Mon Sep 17 00:00:00 2001 From: Kayn Ty Date: Wed, 18 Apr 2018 15:42:30 +0200 Subject: [PATCH] choix de festival actuel ok --- app/Resources/views/base.html.twig | 5 +- app/Resources/views/festival/index.html.twig | 30 +++++++-- .../logged/angular/loaded-caisse.html.twig | 12 ++-- .../views/logged/dashboard.html.twig | 1 - .../Controller/DefaultController.php | 65 ++++++++++++------- 5 files changed, 77 insertions(+), 36 deletions(-) diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index c1c8cef1..faab7362 100755 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -19,9 +19,10 @@
{% include 'default/header.html.twig' %} + {% block body %} + {% endblock %}
- {% block body %} - {% endblock %} +
{% block javascripts %} diff --git a/app/Resources/views/festival/index.html.twig b/app/Resources/views/festival/index.html.twig index 530fbab6..89f7a88e 100755 --- a/app/Resources/views/festival/index.html.twig +++ b/app/Resources/views/festival/index.html.twig @@ -1,7 +1,14 @@ {% extends 'base.html.twig' %} {% block body %} -

Festivals list

+
+
+

Festivals

+ +
+ @@ -9,6 +16,10 @@ + + + + @@ -21,8 +32,18 @@ + + + + +
Id Name DatecreationClientsfond caisse avantfond caisse apreschiffre affaire Actions
{{ festival.name }} {% if festival.dateCreation %}{{ festival.dateCreation|date('Y-m-d H:i:s') }}{% endif %}{{ festival.sellRecords|length }}{{ festival.fondDeCaisseAvant }}{{ festival.fondDeCaisseApres }}{{ festival.chiffreAffaire }} @@ -39,9 +61,5 @@
- + Nouveau festival {% endblock %} diff --git a/app/Resources/views/logged/angular/loaded-caisse.html.twig b/app/Resources/views/logged/angular/loaded-caisse.html.twig index a4e4afe9..7a841baf 100755 --- a/app/Resources/views/logged/angular/loaded-caisse.html.twig +++ b/app/Resources/views/logged/angular/loaded-caisse.html.twig @@ -10,16 +10,18 @@
-
+
- {% include 'logged/angular/validate-button.html.twig' %} - {% include 'logged/angular/current.html.twig' %} - {#{% include 'logged/angular/paused.html.twig' %}#} -
+ {% include 'logged/angular/validate-button.html.twig' %} + {% include 'logged/angular/current.html.twig' %} + {#{% include 'logged/angular/paused.html.twig' %}#} +
+ Festival choisi par l'utilsateur: + {{ app.user.activeFestival.name }} {% include 'logged/angular/recent.html.twig' %}
diff --git a/app/Resources/views/logged/dashboard.html.twig b/app/Resources/views/logged/dashboard.html.twig index 1d3cae42..04b97f26 100755 --- a/app/Resources/views/logged/dashboard.html.twig +++ b/app/Resources/views/logged/dashboard.html.twig @@ -6,7 +6,6 @@
- {% include 'default/header.html.twig' %} {% include 'logged/caisse-main.html.twig' %}
diff --git a/src/AppBundle/Controller/DefaultController.php b/src/AppBundle/Controller/DefaultController.php index cca86721..88f5a2cb 100755 --- a/src/AppBundle/Controller/DefaultController.php +++ b/src/AppBundle/Controller/DefaultController.php @@ -43,11 +43,15 @@ class DefaultController extends Controller { $m = $this->getDoctrine()->getManager(); $currentUser = $this->getUser(); - $lastFestival = $m->getRepository( 'AppBundle:Festival' ) - ->findOneBy( [ 'user' => $this->getUser()->getId() ], - [ 'id' => 'desc' ], - 0, - 1 ); + + $lastFestival = $currentUser->getActiveFestival(); + if(!$lastFestival){ + $lastFestival = $m->getRepository( 'AppBundle:Festival' ) + ->findOneBy( [ 'user' => $this->getUser()->getId() ], + [ 'id' => 'desc' ], + 0, + 1 ); + } $categRepo = $m->getRepository( 'AppBundle:ProductCategory' ); $sellingRepo = $m->getRepository( 'AppBundle:SellRecord' ); $categories = $categRepo->findAll(); @@ -80,23 +84,23 @@ class DefaultController extends Controller { } $activeFestival = $currentUser->getActiveFestival(); - if ( ! $activeFestival ) { - $activeFestival = $m->getRepository( 'AppBundle:Festival' ) - ->findOneBy( [ 'user' => $this->getUser()->getId() ], - [ 'id' => 'desc' ], - 0, - 1 ); - if ( ! $activeFestival ) { - $activeFestival = new Festival(); - $activeFestival->setDateCreation( new \DateTime() ); - $activeFestival->setName( 'default festival' ); - $activeFestival->setUser( $currentUser ); - } - $currentUser->setActiveFestival( $activeFestival ); - $m->persist( $activeFestival ); - $m->persist( $currentUser ); - $m->flush(); - } +// if ( ! $activeFestival ) { +// $activeFestival = $m->getRepository( 'AppBundle:Festival' ) +// ->findOneBy( [ 'user' => $this->getUser()->getId() ], +// [ 'id' => 'desc' ], +// 0, +// 1 ); +// if ( ! $activeFestival ) { +// $activeFestival = new Festival(); +// $activeFestival->setDateCreation( new \DateTime() ); +// $activeFestival->setName( 'default festival' ); +// $activeFestival->setUser( $currentUser ); +// } +// $currentUser->setActiveFestival( $activeFestival ); +// $m->persist( $activeFestival ); +// $m->persist( $currentUser ); +// $m->flush(); +// } $categRepo = $m->getRepository( 'AppBundle:ProductCategory' ); @@ -342,4 +346,21 @@ class DefaultController extends Controller { ] ); } + + + /** + * @Route("/set-active-festival/{id}", name="set_active_festival") + */ + public function setActiveFestivalAction( $id ) { + $currentUser = $this->getUser(); + $m = $this->getDoctrine()->getManager(); + $repo = $m->getRepository( 'AppBundle:Festival' ); + + $currentUser->setActiveFestival( $repo->find( $id ) ); + $m->persist( $currentUser ); + $m->flush(); + + // replace this example code with whatever you need + return $this->redirectToRoute( 'dashboard' ); + } }