Commit e3f5d0de by Yvon Kerdoncuff

Merge branch '5984-mail-group-admin-on-quizz-edit' into 'ssa-gironde'

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

See merge request cooperatic/kohinos-tav!65
parents ff2ca60f 1a015299
......@@ -358,7 +358,16 @@ class IndexController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$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() ?
......@@ -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();
$gestionnaires = $presta->getGroupe()->getGestionnaires();
......@@ -380,14 +395,16 @@ class IndexController extends AbstractController
$to = $gestionnaires->first()->getEmail();
}
$subjectKeyWord = $type == "submit" ? "Réception" : "Édition";
$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))
->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)
->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);
}
......
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