'.$string.'>');
+ $this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
+ }
+ private function writeln($string) {
+ $this->output->writeln($string);
+ $this->filesystem->appendToFile($this->rootlog.'cron.log', $string."\n");
+ }
+
+}
diff --git a/src/schedule-2.0/src/Controller/EventController.php b/src/schedule-2.0/src/Controller/EventController.php
index 1e7e4cd..bc3b5c1 100755
--- a/src/schedule-2.0/src/Controller/EventController.php
+++ b/src/schedule-2.0/src/Controller/EventController.php
@@ -17,6 +17,11 @@ class EventController extends AbstractController
private $route = "app_event";
private $render = "Event/";
private $entity = "App:Event";
+ private $notificator;
+
+ public function __construct(\App\Service\notificationService $notificator) {
+ $this->notificator = $notificator;
+ }
public function list(Request $request)
{
@@ -245,6 +250,12 @@ class EventController extends AbstractController
$em->persist($event);
$em->flush();
+ if($task->getNature()->getIsvacation()){
+ $idevent=$event->getId();
+ $valid_url = $this->generateUrl('app_validationholiday');
+ $this->notificator->sendNotifAttenteValid("Congés en attente de validation", $iduser, $idevent, $valid_url);
+
+ }
$output=$this->formatEvent($event);
}
diff --git a/src/schedule-2.0/src/Controller/ValidationController.php b/src/schedule-2.0/src/Controller/ValidationController.php
index 66bc702..f8cc772 100755
--- a/src/schedule-2.0/src/Controller/ValidationController.php
+++ b/src/schedule-2.0/src/Controller/ValidationController.php
@@ -10,7 +10,11 @@ use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
class ValidationController extends AbstractController
{
private $knpSnappy;
- public function __construct(\Knp\Snappy\Pdf $knpSnappy) { $this->knpSnappy = $knpSnappy; }
+ private $notificator;
+ public function __construct(\Knp\Snappy\Pdf $knpSnappy, \App\Service\notificationService $notificator) {
+ $this->knpSnappy = $knpSnappy;
+ $this->notificator = $notificator;
+ }
public function validation(Request $request)
{
@@ -510,6 +514,9 @@ class ValidationController extends AbstractController
$event->setValidateholiday(true);
$em->persist($event);
$em->flush();
+ $iduser=$this->get("session")->get("iduser");
+ $idevent=$event->getId();
+ $this->notificator->sendNotifValid("Congé validé", $iduser, $event);
}
$output=[];
diff --git a/src/schedule-2.0/src/Service/notificationService.php b/src/schedule-2.0/src/Service/notificationService.php
new file mode 100644
index 0000000..1c754af
--- /dev/null
+++ b/src/schedule-2.0/src/Service/notificationService.php
@@ -0,0 +1,98 @@
+mailer = $mailer;
+ $this->twig = $twig;
+ $this->em = $em;
+ }
+
+ public function sendNotifAttenteValid($subject, $iduser, $idevent, $valid_url)
+ {
+ $template = $this->twig->load('Notif/attentevalidation.html.twig');
+ $user=$this->em->getRepository("App:User")->find($iduser);
+ $event=$this->em->getRepository("App:Event")->find($idevent);
+ $users=$this->em->getRepository("App:User")->findAll();
+ $tbemails=[];
+ foreach($users as $usr) {
+ if(in_array("ROLE_VALIDATOR",$usr->getRoles())) {
+ array_push($tbemails,$usr->getEmail());
+ }
+ // else{
+ // if(in_array("ROLE_MASTER",$usr->getRoles())) {
+ // if ($usr->getService() == $user->getService() ){
+ // $tmp=[
+ // "id"=>$usr->getId(),
+ // "email"=>$usr->getEmail()
+ // ];
+ // }
+ // array_push($tbemails,$tmp);
+ // }
+ // }
+ }
+
+ $parameters=[
+ 'date' => new \DateTime(),
+ 'username' => $user->getUsername(),
+ 'start' => $event->getStart(),
+ 'end' => $event->getEnd(),
+ 'duration' => $event->getDuration(),
+ 'valid_link' => $valid_url,
+ ];
+ $bodyHtml = $template->renderBlock('body', $parameters);
+
+ $message = (new \Swift_Message())
+ ->setFrom('schedule@cadoles.com')
+ ->setSubject($user->getUsername() . " = " . $subject)
+ //TODO envoyer à tt les users master associé au service de l'utilisateur et l'ensemble des user validator
+ ->setTo($tbemails)
+ ->setBody($bodyHtml, 'text/html');
+
+ $response = $this->mailer->send($message);
+
+ return $response;
+ }
+ public function sendNotifValid($subject, $iduser, $idevent)
+ {
+ $template = $this->twig->load('Notif/validation.html.twig');
+ $user=$this->em->getRepository("App:User")->find($iduser);
+ $event=$this->em->getRepository("App:Event")->find($idevent);
+ $users=$this->em->getRepository("App:User")->findAll();
+ $tbemails=[];
+ foreach($users as $usr) {
+ if(in_array("ROLE_VALIDATOR",$usr->getRoles())) {
+ array_push($tbemails,$usr->getEmail());
+ }
+
+ }
+ $parameters=[
+ 'date' => new \DateTime(),
+ 'username' => $user->getUsername(),
+ 'start' => $event->getStart(),
+ 'end' => $event->getEnd(),
+ 'duration' => $event->getDuration(),
+ ];
+ $bodyHtml = $template->renderBlock('body', $parameters);
+
+ $message = (new \Swift_Message())
+ ->setFrom('schedule@cadoles.com')
+ ->setSubject($user->getUsername() . " = " . $subject)
+ ->setTo($this->container->getParameter('appMailnotif'))
+ ->setCc($tbemails)
+ ->setBody($bodyHtml, 'text/html');
+
+ $response = $this->mailer->send($message);
+
+
+ return $response;
+ }
+}
diff --git a/src/schedule-2.0/templates/Notif/attentevalidation.html.twig b/src/schedule-2.0/templates/Notif/attentevalidation.html.twig
new file mode 100644
index 0000000..a224421
--- /dev/null
+++ b/src/schedule-2.0/templates/Notif/attentevalidation.html.twig
@@ -0,0 +1,25 @@
+{% block body %}
+{% autoescape %}
+Date de la demande : {{ date|date("d/m/Y H:i") }}
+
+ Utilisateur = {{ username }}
+
+
+ Début = {{ start|date("d/m/Y H:i") }}
+
+
+ Fin = {{ end|date("d/m/Y H:i") }}
+
+
+ Durée = {{ duration }}
+
+
+ Type = Congé
+
+
+ Lien pour valider = {{ valid_link }}
+
+
+{% endautoescape %}
+{% endblock %}
+
diff --git a/src/schedule-2.0/templates/Notif/validation.html.twig b/src/schedule-2.0/templates/Notif/validation.html.twig
new file mode 100644
index 0000000..4a35676
--- /dev/null
+++ b/src/schedule-2.0/templates/Notif/validation.html.twig
@@ -0,0 +1,23 @@
+{% block body %}
+{% autoescape %}
+VALIDATION
+
+ Utilisateur = {{ username }}
+
+
+ Début = {{ start|date("d/m/Y H:i") }}
+
+
+ Fin = {{ end|date("d/m/Y H:i") }}
+
+
+ Durée = {{ duration }}
+
+
+ Type = Congé
+
+
+
+{% endautoescape %}
+{% endblock %}
+
diff --git a/tmpl/schedule-env.local b/tmpl/schedule-env.local
index 31f3ab6..7815fe1 100644
--- a/tmpl/schedule-env.local
+++ b/tmpl/schedule-env.local
@@ -4,6 +4,12 @@ APP_SECRET=%%pwdreader("","/var/www/html/schedule/.key")
APP_AUTH=CAS
+# MAIL sendmail / smtp
+MAILER_METHOD=sendmail
+MAILER_URL=
+MAILER_NOREPLY=noreply@noreply.fr
+MAILER_DEFAULT_NOTIF=%%getVar('schedule_email_global_notif', '')
+
# Bdd = Redefine local
DATABASE_NAME=schedule
DATABASE_USER=schedule