Commit 1ac5109e by Damien Moulard

Merge branch '5804-display-questionnaire-to-all-logged-in-users' into 'ssa-gironde'

vitrine prestataire : display questionnaire as form in readonly mode using third…

See merge request cooperatic/kohinos-tav!54
parents 20d36a21 4a099ca7
......@@ -689,7 +689,7 @@ class PrestataireAdmin extends AbstractAdmin
];
if (($this->security->isGranted('ROLE_GESTION_GROUPE') || $this->security->isGranted('ROLE_SUPER_ADMIN')) && $this->getConfigurationPool()->getContainer()->getParameter('presta_self_init_and_eval')) {
$actions['reviewPrestaQuiz'] = [
'template' => '@kohinos/tav/reviewprestaquiz.html.twig'
'template' => '@kohinos/tav/prestaquiz/review.html.twig'
];
}
if (null != $this->security->getUser() && ($this->security->isGranted('ROLE_SUPER_ADMIN') || $this->security->isGranted('ROLE_ADMIN_PRESTATAIRE_COTISATIONS_ALL') || $this->security->isGranted('ROLE_ADMIN_PRESTATAIRE_COTISATIONS_CREATE'))) {
......
......@@ -214,7 +214,7 @@ class IndexController extends AbstractController
return $this->redirectToRoute($redirRoute);
}
return $this->render('@kohinos/tav/prestaquiz_sent.html.twig');
return $this->render('@kohinos/tav/prestaquiz/sent.html.twig');
}
/**
......@@ -262,7 +262,7 @@ class IndexController extends AbstractController
}
}
return $this->render('@kohinos/tav/infos_prestaquiz.html.twig', [
return $this->render('@kohinos/tav/prestaquiz/infos.html.twig', [
'form' => $form->createView(),
]);
}
......@@ -302,8 +302,8 @@ class IndexController extends AbstractController
}
$tmpl = Prestataire::DISTRIBUTOR === $presta->getMarketChannelFunction() ?
'@kohinos/tav/distributor_selfeval_prestaquiz.html.twig'
: '@kohinos/tav/producer_selfeval_prestaquiz.html.twig';
'@kohinos/tav/prestaquiz/distributor.html.twig'
: '@kohinos/tav/prestaquiz/producer.html.twig';
return $this->render($tmpl, [
'form' => $form->createView(),
......
......@@ -8,6 +8,7 @@ use App\Entity\Prestataire;
use App\Enum\MoyenEnum;
use App\Form\Type\DistributorSelfEvalPrestaQuizType;
use App\Form\Type\ProducerSelfEvalPrestaQuizType;
use App\Form\Type\SelfEvalPrestaQuizType;
use App\Utils\CustomEntityManager;
use DateTime;
use Sonata\AdminBundle\Controller\CRUDController;
......@@ -138,7 +139,7 @@ class PrestataireAdminController extends CRUDController
$quiz = $prestataire->getSelfEvalPrestaQuiz();
$formClass = Prestataire::DISTRIBUTOR === $prestataire->getMarketChannelFunction() ?
DistributorSelfEvalPrestaQuizType::class : ProducerSelfEvalPrestaQuizType::class;
$form = $this->createForm($formClass, $quiz, ["review" => true]);
$form = $this->createForm($formClass, $quiz, ["mode" => SelfEvalPrestaQuizType::ADMIN_EDIT]);
$form->handleRequest($request);
......@@ -150,8 +151,8 @@ class PrestataireAdminController extends CRUDController
}
$tmpl = Prestataire::DISTRIBUTOR === $prestataire->getMarketChannelFunction() ?
'@kohinos/tav/distributor_selfeval_prestaquiz.html.twig'
: '@kohinos/tav/producer_selfeval_prestaquiz.html.twig';
'@kohinos/tav/prestaquiz/distributor.html.twig'
: '@kohinos/tav/prestaquiz/producer.html.twig';
return $this->render($tmpl, [
'form' => $form->createView(),
......
......@@ -6,6 +6,10 @@ use App\Entity\Groupe;
use App\Entity\Prestataire;
use App\Entity\Rubrique;
use App\Entity\Flux;
use App\Entity\SelfEvalPrestaQuiz;
use App\Form\Type\DistributorSelfEvalPrestaQuizType;
use App\Form\Type\ProducerSelfEvalPrestaQuizType;
use App\Form\Type\SelfEvalPrestaQuizType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;
......@@ -39,8 +43,14 @@ class PrestatairesController extends FrontController
return new RedirectResponse($this->router->generate('index'));
}
$quiz = $prestataire->getSelfEvalPrestaQuiz();
$formClass = Prestataire::DISTRIBUTOR === $prestataire->getMarketChannelFunction() ?
DistributorSelfEvalPrestaQuizType::class : ProducerSelfEvalPrestaQuizType::class;
$form = $this->createForm($formClass, $quiz, ["mode" => SelfEvalPrestaQuizType::READONLY]);
return $this->render('@kohinos/presta/show.html.twig', [
'presta' => $prestataire,
'form' => $form->createView()
]);
}
......
......@@ -100,7 +100,7 @@ class DistributorSelfEvalPrestaQuizType extends SelfEvalPrestaQuizType
$builder->add('localite_global_comment', TextareaType::class, $this->cmtOpts);
//Review
if($options['review']) {
if($options['mode'] !== self::PRESTA_EDIT) {
$this->reviewOpts['label'] = "Transparence et juste rémunération : " . $this->reviewLabel;
$this->reviewOpts['choices'] = $this->stdGlobalChoices;
$builder->add('review_transpar_global', ChoiceType::class, $this->reviewOpts);
......
......@@ -59,7 +59,7 @@ class ProducerSelfEvalPrestaQuizType extends SelfEvalPrestaQuizType
$builder->add('proagdur_global_comment', TextareaType::class, $this->cmtOpts);
//Review
if($options['review']) {
if($options['mode'] !== self::PRESTA_EDIT) {
$this->reviewOpts['label'] = "Pratiques agricoles durables : " . $this->reviewLabel;
$this->reviewOpts['choices'] = $this->stdGlobalChoices;
$builder->add('review_proagdur_global', ChoiceType::class, $this->reviewOpts);
......
......@@ -20,6 +20,10 @@ use Symfony\Component\Validator\Constraints\NotNull;
*/
class SelfEvalPrestaQuizType extends AbstractType
{
const PRESTA_EDIT = 'presta_edit';
const ADMIN_EDIT = 'admin_edit';
const READONLY = 'readonly';
protected $security;
protected array $stdChoices;
......@@ -57,26 +61,28 @@ class SelfEvalPrestaQuizType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
//options are moved to buildForm as 'review' option is required to set them up
//options are moved to buildForm as 'mode' option is required to set them up
$this->reviewOpts = [
'label' => '',
'choices' => $this->stdChoices,
'expanded' => true,
"multiple" => false,
'constraints' => [new NotNull()]
'constraints' => [new NotNull()],
'disabled' => $options['mode'] === self::READONLY
];
$this->opts = $this->reviewOpts;
$this->opts['disabled'] = $options['review'];
$this->opts['disabled'] = $options['mode'] !== self::PRESTA_EDIT;
$this->reviewCmtOpts = [
'attr' => [
'placeholder' => 'Commentaires'
'placeholder' => $options['mode'] === self::READONLY ? '' : 'Commentaires'
],
'label' => false,
'required' => false
'required' => false,
'disabled' => $options['mode'] === self::READONLY
];
$this->cmtOpts = $this->reviewCmtOpts;
$this->cmtOpts['disabled'] = $options['review'];
$this->cmtOpts['attr']['placeholder'] = $options['review'] ? '' : 'Commentaires';
$this->cmtOpts['disabled'] = $options['mode'] !== self::PRESTA_EDIT;
$this->cmtOpts['attr']['placeholder'] = $options['mode'] !== self::PRESTA_EDIT ? '' : 'Commentaires';
/* PARTIE 1 : ACCESSIBILITE ET INCLUSIVITE */
$this->opts['label'] = "Géographique et physique : le lieu est-il accessible par différents modes de transport ?";
......@@ -136,7 +142,7 @@ class SelfEvalPrestaQuizType extends AbstractType
$builder->add('bienetre_global_comment', TextareaType::class, $this->cmtOpts);
//Review
if($options['review']) {
if($options['mode'] !== self::PRESTA_EDIT) {
$this->reviewOpts['label'] = "Accessibilité et inclusivité : " . $this->reviewLabel;
$this->reviewOpts['choices'] = $this->stdGlobalChoices;
$builder->add('review_accessib_global', ChoiceType::class, $this->reviewOpts);
......@@ -148,7 +154,9 @@ class SelfEvalPrestaQuizType extends AbstractType
$builder->add('review_bienetre_global_comment', TextareaType::class, $this->reviewCmtOpts);
}
$builder->add('save', SubmitType::class, ['label' => $options['review'] ? 'Enregistrer' : 'Envoyer']);
if($options['mode'] !== self::READONLY) {
$builder->add('save', SubmitType::class, ['label' => $options['mode'] === self::PRESTA_EDIT ? 'Envoyer' : 'Enregistrer']);
}
}
/**
......@@ -158,7 +166,7 @@ class SelfEvalPrestaQuizType extends AbstractType
{
$resolver->setDefaults([
'data_class' => SelfEvalPrestaQuiz::class,
'review' => false //decide if prestataire is filling the form or if an admin is reviewing
'mode' => self::PRESTA_EDIT
]);
}
......
......@@ -77,12 +77,23 @@
{% endfor %}
</ul>
{% endif %}
{% if app.user and presta_self_init_and_eval and presta.selfEvalPrestaQuiz %}
{% set prestataire = presta %}
<div class="card-header"><h2>Questionnaire</h2></div>
<div class="card-body">
{% if presta.marketChannelFunction == 'distributor' %}
{% include '@kohinos/tav/prestaquiz/distributor_core.html.twig' %}
{% else %}
{% include '@kohinos/tav/prestaquiz/producer_core.html.twig' %}
{% endif %}
</div>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
{% block contenat %}
<div class='container newslist mt-5'>
......
{# View for prestataire questionnaire sections that are common to distributors and producers #}
<br/>
<br/>
<h2><i class="fas fa-universal-access"></i> Accessibilité et Inclusivité</h2>
<div class="container">
......
{% extends '@kohinos/common/layout.html.twig' %}
{% block content %}
{# Check if review mode to adapt title #}
{% if form.review_transpar_global is defined %}
<h1>Revue auto-évaluation distributeur {{ prestataire.raison }}</h1>
{% else %}
<h1>Inscription point de vente (2/2) : auto-évaluation</h1>
{% endif %}
<br/>
<br/>
{% include '@kohinos/tav/prestaquiz/distributor_core.html.twig' %}
{% endblock %}
\ No newline at end of file
{% extends '@kohinos/common/layout.html.twig' %}
{% block content %}
{# Form theme use is mandatory to insert non-text stuff (such as html, icons...) in the choice type choices label. #}
{% form_theme form '@kohinos/tav/prestaquiz_form_theme.html.twig' %}
{# Check if review mode to adapt title #}
{% if form.review_transpar_global is defined %}
<h1>Revue auto-évaluation distributeur {{ prestataire.raison }}</h1>
{% else %}
<h1>Inscription point de vente (2/2) : auto-évaluation</h1>
{% endif %}
{% form_theme form '@kohinos/tav/prestaquiz/form_theme.html.twig' %}
{{ form_start(form) }}
{# includes twig common to distributors and producers #}
{% include '@kohinos/tav/selfeval_prestaquiz.html.twig' %}
{% include '@kohinos/tav/prestaquiz/base.html.twig' %}
<br/>
......@@ -138,5 +128,3 @@
<br/>
{{ form_end(form) }}
\ No newline at end of file
{% endblock %}
\ No newline at end of file
{% extends '@kohinos/common/layout.html.twig' %}
{% block content %}
{# Check if review mode to adapt title #}
{% if form.review_proagdur_global is defined %}
<h1>Revue auto-évaluation producteur {{ prestataire.raison }}</h1>
{% else %}
<h1>Inscription point de vente (2/2) : auto-évaluation</h1>
{% endif %}
<br/>
<br/>
{% include '@kohinos/tav/prestaquiz/producer_core.html.twig' %}
{% endblock %}
\ No newline at end of file
{% extends '@kohinos/common/layout.html.twig' %}
{% block content %}
{# Form theme use is mandatory to insert non-text stuff (such as html, icons...) in the choice type choices label. #}
{% form_theme form '@kohinos/tav/prestaquiz_form_theme.html.twig' %}
{# Check if review mode to adapt title #}
{% if form.review_proagdur_global is defined %}
<h1>Revue auto-évaluation producteur {{ prestataire.raison }}</h1>
{% else %}
<h1>Inscription point de vente (2/2) : auto-évaluation</h1>
{% endif %}
{% form_theme form '@kohinos/tav/prestaquiz/form_theme.html.twig' %}
{{ form_start(form) }}
{# includes twig common to distributors and producers #}
{% include '@kohinos/tav/selfeval_prestaquiz.html.twig' %}
{% include '@kohinos/tav/prestaquiz/base.html.twig' %}
<br/>
<br/>
......@@ -91,5 +81,3 @@
<br/>
{{ form_end(form) }}
\ No newline at end of file
{% endblock %}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment