diff --git a/src/Controller/ProjectController.php b/src/Controller/ProjectController.php index f0aa9cb..759f4ab 100644 --- a/src/Controller/ProjectController.php +++ b/src/Controller/ProjectController.php @@ -4,6 +4,7 @@ namespace App\Controller; use App\Entity\Project; use App\Form\ProjectType; +use App\Form\ProjectVotedType; use App\Repository\ProjectRepository; use App\Security\ProjectVoter; use Bnine\FilesBundle\Service\FileService; @@ -121,7 +122,20 @@ class ProjectController extends AbstractController $attribute = constant(ProjectVoter::class.'::MOVE'.$status); $this->denyAccessUnlessGranted($attribute, $project); - if (Project::VOTED == $status) { + if ('VOTED' == $status && Project::ARCHIVED != $project->getStatus()) { + $form = $this->createForm(ProjectVotedType::class, $project); + $form->handleRequest($request); + + if (!$form->isSubmitted() || !$form->isValid()) { + return $this->render('project/vote.html.twig', [ + 'usemenu' => true, + 'usesidebar' => false, + 'title' => 'Vote Projet = '.$project->getTitle(), + 'routecancel' => 'app_user_project_view', + 'form' => $form, + 'project' => $project, + ]); + } } $project->setStatus(constant(Project::class.'::'.$status)); diff --git a/src/Form/ProjectVotedType.php b/src/Form/ProjectVotedType.php index 51443a1..a0c1f5f 100644 --- a/src/Form/ProjectVotedType.php +++ b/src/Form/ProjectVotedType.php @@ -6,7 +6,9 @@ use App\Entity\Project; use App\Form\Type\ProjectOptionType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CollectionType; +use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -20,6 +22,24 @@ class ProjectVotedType extends AbstractType 'attr' => ['class' => 'btn btn-success no-print me-1'], ]) + ->add('resultVote', TextareaType::class, [ + 'label' => 'Résultats', + 'required' => true, + 'attr' => [ + 'rows' => 7, + ], + ]) + + ->add('nbVoteWhite', IntegerType::class, [ + 'label' => 'Votes blancs', + 'required' => false, + ]) + + ->add('nbVoteNull', IntegerType::class, [ + 'label' => 'Votes nuls', + 'required' => false, + ]) + ->add('options', CollectionType::class, [ 'entry_type' => ProjectOptionType::class, 'entry_options' => ['label' => false], diff --git a/templates/home/home.html.twig b/templates/home/home.html.twig index 3d9256d..148f839 100644 --- a/templates/home/home.html.twig +++ b/templates/home/home.html.twig @@ -51,7 +51,29 @@
{{project.summary|nl2br}} + + {% if project.status=="Voté" or project.status=="Archivé" %} + +
+
+
+ {% for option in project.options %} + {{ option.title|title }} = {{ option.nbVote }}
+ {% endfor %} +
+
+ Votes Blancs = {{ project.nbVoteWhite }}
+ Votes Nuls = {{ project.nbVoteNull }} +
+
+ +
+ Résultat =
+ {{ project.resultVote|nl2br }} +
+ {% endif %}
+
+ {% if project.status=="Voté" or project.status=="Archivé" %} +
+
Vote
+
+
+
+ {% for option in project.options %} + {{ option.title|title }} = {{ option.nbVote }}
+ {% endfor %} +
+
+ Votes Blancs = {{ project.nbVoteWhite }}
+ Votes Nuls = {{ project.nbVoteNull }} +
+
+ +
+ Résultat =
+ {{ project.resultVote|nl2br }} +
+
+ {% endif %} +
{% for option in project.options %}
diff --git a/templates/project/vote.html.twig b/templates/project/vote.html.twig new file mode 100644 index 0000000..2a32a06 --- /dev/null +++ b/templates/project/vote.html.twig @@ -0,0 +1,63 @@ +{% extends 'base.html.twig' %} + +{% block title %} = {{title}}{% endblock %} + +{% block body %} +

{{title}}

+ + {% include('include/error.html.twig') %} + + {{ form_start(form) }} + {{ form_widget(form.submit) }} + Annuler + +
+ +
+
+
Vote
+
+
+ {% for optionForm in form.options %} +
+ {{ optionForm.title.vars.value }} +
+ {{ form_widget(optionForm.nbVote, {'attr': {'class': 'form-control form-control-sm'}}) }} +
+
+ {% endfor %} + +
+ {{ form.nbVoteWhite.vars.label }} +
+ {{ form_widget(form.nbVoteWhite, {'attr': {'class': 'form-control form-control-sm'}}) }} +
+
+ +
+ {{ form.nbVoteNull.vars.label }} +
+ {{ form_widget(form.nbVoteNull, {'attr': {'class': 'form-control form-control-sm'}}) }} +
+
+
+
+
+
+ + +
+
+
Résultat
+
+ {{ form_widget(form.resultVote, { 'attr': { 'class': 'flex-fill w-100' } }) }} +
+
+
+
+ +
+ {{ form_rest(form) }} +
+ {{ form_end(form, { render_rest: false }) }} +{% endblock %}