Commit 1a015299 by Damien Moulard

send email to group admin when a presatataire edits its self eval quizz

parent 7b23e444
...@@ -358,7 +358,16 @@ class IndexController extends AbstractController ...@@ -358,7 +358,16 @@ class IndexController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$this->em->flush(); $this->em->flush();
return $this->redirectToRoute('show_prestataire',['slug' => $presta->getRaison()]);
// Notify group administrator that the user updated their self evaluation
$this->notifyGestionnaireAfterPrestaquizSent($presta, 'edit');
$this->addFlash(
'success',
'Modifications enregistrées !'
);
return $this->redirectToRoute('show_prestataire', ['slug' => $presta->getSlug()]);
} }
$tmpl = Prestataire::DISTRIBUTOR === $presta->getMarketChannelFunction() ? $tmpl = Prestataire::DISTRIBUTOR === $presta->getMarketChannelFunction() ?
...@@ -370,7 +379,13 @@ class IndexController extends AbstractController ...@@ -370,7 +379,13 @@ class IndexController extends AbstractController
]); ]);
} }
private function notifyGestionnaireAfterPrestaquizSent(Prestataire $presta) /**
* Notify by email the group administrator when a prestataire submits or edits their
* self evaluation quizz.
*
* @param $type submit|edit, action performed by the user. Default: 'submit'.
*/
private function notifyGestionnaireAfterPrestaquizSent(Prestataire $presta, $type="submit")
{ {
$user = $this->security->getUser(); $user = $this->security->getUser();
$gestionnaires = $presta->getGroupe()->getGestionnaires(); $gestionnaires = $presta->getGroupe()->getGestionnaires();
...@@ -380,14 +395,16 @@ class IndexController extends AbstractController ...@@ -380,14 +395,16 @@ class IndexController extends AbstractController
$to = $gestionnaires->first()->getEmail(); $to = $gestionnaires->first()->getEmail();
} }
$subjectKeyWord = $type == "submit" ? "Réception" : "Édition";
$subject = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::MLC_NAME_SMALL) $subject = $this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::MLC_NAME_SMALL)
. ' : Réception questionnaire point de vente'; . ' : ' . $subjectKeyWord . ' d\'un questionnaire de point de vente';
$contentKeyWord = $type == "submit" ? "soumettre" : "modifier";
$mail = (new \Swift_Message($subject)) $mail = (new \Swift_Message($subject))
->setFrom($this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::MLC_NOTIF_EMAIL)) //using $from here sometimes fails with 550 5.7.1 Sender mismatch ->setFrom($this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::MLC_NOTIF_EMAIL)) //using $from here sometimes fails with 550 5.7.1 Sender mismatch
->setTo($to) ->setTo($to)
->setBody("L'utilisateur " . $user->getUsername() ->setBody("L'utilisateur " . $user->getUsername()
. " vient de soumettre un questionnaire pour le point de vente " . $presta->getRaison() . "." . " vient de " . $contentKeyWord . " un questionnaire d'auto-évaluation pour le point de vente " . $presta->getRaison() . "."
); );
$this->mailer->send($mail); $this->mailer->send($mail);
} }
......
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