Project 'cooperatic/kohinos-tav' was moved to 'agplv3/kohinos-tav'. Please update any links and bookmarks that may still have the old path.
Commit ac735522 by Damien Moulard

Merge branch '5767-late-autoevaluation-presta-edit' into 'ssa-gironde'

allow presta to edit questionnaire from vitrine

See merge request cooperatic/kohinos-tav!60
parents f0cedfab 230ce048
......@@ -18,6 +18,7 @@ use App\Entity\User;
use App\Entity\Usergroup;
use App\Enum\CurrencyEnum;
use App\Form\Type\DistributorSelfEvalPrestaQuizType;
use App\Form\Type\SelfEvalPrestaQuizType;
use App\Form\Type\InfosPrestaQuizType;
use App\Form\Type\InstallFormType;
use App\Form\Type\ProducerSelfEvalPrestaQuizType;
......@@ -41,8 +42,8 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\Security as Secur;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;
......@@ -71,7 +72,7 @@ class IndexController extends AbstractController
LoginAuthenticator $authenticator,
TokenStorageInterface $tokenStorage,
RouterInterface $router,
Security $security,
Secur $security,
\Swift_Mailer $mailer
) {
$this->eventDispatcher = $eventDispatcher;
......@@ -321,6 +322,54 @@ class IndexController extends AbstractController
]);
}
/**
* @Route("/quiz-presta-edit", name="quiz-presta-edit")
* @Security("is_granted('ROLE_PRESTATAIRE')")
*/
/* Late presta edit (after definitive submission) :
* As we are not in the somehow complex subscription tunnel context anymore,
* I found easier to create a new controller
* instead of reusing prestaQuizSelfEvalAction
*/
public function quizPrestaEditAction(Request $request): Response
{
//Look for enabled prestataire with current user (fail if no enabled prestataire has been found)
$prestas = $this->em->getRepository(Prestataire::class)->findByData(['user' => $this->security->getUser()]);
if(!$prestas) {
throw new \Exception('Vous n\'êtes pas autorisé à accèder à cette page.');
} else {
$presta = $prestas[0];
}
/* @var Prestataire $presta */
$formClass = Prestataire::DISTRIBUTOR === $presta->getMarketChannelFunction() ?
DistributorSelfEvalPrestaQuizType::class : ProducerSelfEvalPrestaQuizType::class;
// Block if no quiz (e.g. user access this controleur in non presta_self_init_and_eval env) or
// if presta has been enabled while questionnaire has not been submitted yet (should not occur)
$quiz = $presta->getSelfEvalPrestaQuiz();
if (null == $quiz || !$quiz->isSubmitted) {
throw new \Exception('Aucun questionnaire soumis trouvé.');
}
$form = $this->createForm($formClass, $quiz, ["mode" => SelfEvalPrestaQuizType::PRESTA_EDIT_AFTER_DEFINITIVE_SUBMISSION]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->flush();
return $this->redirectToRoute('show_prestataire',['slug' => $presta->getRaison()]);
}
$tmpl = Prestataire::DISTRIBUTOR === $presta->getMarketChannelFunction() ?
'@kohinos/tav/prestaquiz/distributor.html.twig'
: '@kohinos/tav/prestaquiz/producer.html.twig';
return $this->render($tmpl, [
'form' => $form->createView(),
]);
}
private function notifyGestionnaireAfterPrestaquizSent(Prestataire $presta)
{
$user = $this->security->getUser();
......
......@@ -23,6 +23,7 @@ class SelfEvalPrestaQuizType extends AbstractType
const PRESTA_EDIT = 'presta_edit';
const ADMIN_EDIT = 'admin_edit';
const READONLY = 'readonly';
const PRESTA_EDIT_AFTER_DEFINITIVE_SUBMISSION = 'presta_edit_after_definitive_submission';
protected $security;
......@@ -68,26 +69,28 @@ class SelfEvalPrestaQuizType extends AbstractType
'choices' => $this->stdChoices,
'expanded' => true,
"multiple" => false,
'disabled' => $options['mode'] === self::READONLY
'disabled' => $options['mode'] !== self::ADMIN_EDIT
];
$this->opts = $this->reviewOpts;
$this->opts['disabled'] = $options['mode'] !== self::PRESTA_EDIT;
$this->opts['disabled'] = $options['mode'] !== self::PRESTA_EDIT && $options['mode'] !== self::PRESTA_EDIT_AFTER_DEFINITIVE_SUBMISSION;
$this->reviewCmtOpts = [
'attr' => [
'placeholder' => $options['mode'] === self::READONLY ? '' : 'Commentaires'
'placeholder' => $options['mode'] !== self::ADMIN_EDIT ? '' : 'Commentaires'
],
'label' => false,
'required' => false,
'disabled' => $options['mode'] === self::READONLY
'disabled' => $options['mode'] !== self::ADMIN_EDIT
];
$this->cmtOpts = $this->reviewCmtOpts;
$this->cmtOpts['disabled'] = $options['mode'] !== self::PRESTA_EDIT;
$this->cmtOpts['disabled'] = $options['mode'] !== self::PRESTA_EDIT && $options['mode'] !== self::PRESTA_EDIT_AFTER_DEFINITIVE_SUBMISSION;
$this->cmtOpts['attr']['placeholder'] = $options['mode'] !== self::PRESTA_EDIT ? '' : 'Commentaires';
$this->globalCmtOpts = $this->cmtOpts;
$this->globalCmtOpts['required'] = true;
$this->globalCmtOpts['attr']['placeholder'] = $options['mode'] !== self::PRESTA_EDIT ? '' : 'Commentaires (obligatoire)';
$this->globalCmtOpts['attr']['placeholder'] = $options['mode'] !== self::PRESTA_EDIT && $options['mode'] !== self::PRESTA_EDIT_AFTER_DEFINITIVE_SUBMISSION ? '' : 'Commentaires (obligatoire)';
$builder->add($options["mode"],HiddenType::class,['mapped' => false]); //ease conditionnal display in twig
/* PARTIE 1 : ACCESSIBILITE ET INCLUSIVITE */
$this->opts['label'] = "Géographique et physique : le point de vente est-il accessible par différents modes de transport ?";
......
......@@ -94,7 +94,12 @@
{% endif %}
{% if app.user and presta_self_init_and_eval and presta.selfEvalPrestaQuiz %}
{% set prestataire = presta %}
<div class="card-header"><h2>{{ 'Questionnaire'|trans }}</h2></div>
<div class="card-header">
<h2>{{ 'Questionnaire'|trans }}</h2>
{% if app.user in prestataire.users and is_granted("ROLE_PRESTATAIRE") %}
<a class='btn btn-primary float-right' href="{{ path('quiz-presta-edit') }}">Corriger</a>
{% endif %}
</div>
<div class="card-body">
{% if presta.marketChannelFunction == 'distributor' %}
{% include '@kohinos/tav/prestaquiz/distributor_core.html.twig' %}
......
......@@ -2,8 +2,10 @@
{% block content %}
{# Check if review mode to adapt title #}
{% if form.review_transpar_global is defined %}
{% if form.admin_edit is defined %}
<h1>Revue auto-évaluation distributeur {{ prestataire.raison }}</h1>
{% elseif form.presta_edit_after_definitive_submission is defined %}
<h1>Correction du questionnaire d'auto-évaluation</h1>
{% else %}
<h1>Inscription point de vente (2/2) : auto-évaluation</h1>
{% endif %}
......
......@@ -2,8 +2,10 @@
{% block content %}
{# Check if review mode to adapt title #}
{% if form.review_proagdur_global is defined %}
{% if form.admin_edit is defined %}
<h1>Revue auto-évaluation producteur {{ prestataire.raison }}</h1>
{% elseif form.presta_edit_after_definitive_submission is defined %}
<h1>Correction du questionnaire d'auto-évaluation</h1>
{% else %}
<h1>Inscription point de vente (2/2) : auto-évaluation</h1>
{% endif %}
......
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