From 2e56de5d099e84ec371a5589489b22eef14a4148 Mon Sep 17 00:00:00 2001 From: afornerot Date: Mon, 5 Oct 2020 14:40:13 +0200 Subject: [PATCH] =?UTF-8?q?mise=20=C3=A0=20jour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Command/SynchroUsersCommand.php | 68 +++++++++++++++++-- .../src/Controller/AnswerController.php | 4 +- .../src/Controller/SecurityController.php | 2 +- src/nineschool-1.0/src/Form/ActivityType.php | 2 +- src/nineschool-1.0/src/Migrations/.gitignore | 2 +- .../templates/Activity/edit.html.twig | 1 + .../templates/Document/upload.html.twig | 5 +- 7 files changed, 71 insertions(+), 13 deletions(-) diff --git a/src/nineschool-1.0/src/Command/SynchroUsersCommand.php b/src/nineschool-1.0/src/Command/SynchroUsersCommand.php index ae2efce..42b71d7 100644 --- a/src/nineschool-1.0/src/Command/SynchroUsersCommand.php +++ b/src/nineschool-1.0/src/Command/SynchroUsersCommand.php @@ -7,16 +7,21 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Security\Core\Encoder\EncoderFactory; -use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -use App\Entity\Group; -use App\Entity\User; +use App\Entity\Group as Group; +use App\Entity\User as User; +use App\Entity\Answer as Answer; +use App\Entity\Message as Message; + +use App\Service\mailService; class SynchroUsersCommand extends Command { private $container; + private $router; private $em; private $output; private $filesystem; @@ -24,12 +29,15 @@ class SynchroUsersCommand extends Command private $ldap; private $ldap_basedn; private $ldapgroups=[]; + private $mail; - public function __construct(ContainerInterface $container,EntityManagerInterface $em) + public function __construct(ContainerInterface $container,EntityManagerInterface $em,RouterInterface $router, mailService $mail) { parent::__construct(); $this->container = $container; $this->em = $em; + $this->router = $router; + $this->mail = $mail; } protected function configure() @@ -587,6 +595,12 @@ class SynchroUsersCommand extends Command $this->em->persist($group); $this->em->flush(); + // On s'assure que l'ensemble des activité active soit bien distribué en fonction + $activitys=$this->em->getRepository("App:Activity")->findAllGroupActivityActive($group,true); + foreach($activitys as $activity) { + $this->initAnswer($activity); + } + } $this->writeln(''); @@ -728,4 +742,48 @@ class SynchroUsersCommand extends Command $this->em->flush(); } + protected function initAnswer($activity) { + $em = $this->em; + + // Pour chaque élève + $group=$activity->getGroup(); + foreach($group->getUsers() as $user) { + // Existe-t-il une réponse pour l'élève + if($user->hasRole("ROLE_USER")) { + $answer=$em->getRepository("App:Answer")->findOneBy(["user"=>$user,"activity"=>$activity]); + if(!$answer) { + $answer=new Answer; + $answer->setActivity($activity); + $answer->setUser($user); + $answer->setStatus(-1); + + $em->persist($answer); + $em->flush(); + + // Message + $message=new Message; + $message->setMessage("Distribution de l'Activité"); + $message->setDeletable(false); + $message->setUser($activity->getUser()); + $message->setAnswer($answer); + $message->addReader($activity->getUser()); + + $em->persist($message); + $em->flush(); + + // Notification par mail de la distribution de l'activité + $to = $user->getEmail(); + $from = $activity->getUser()->getEmail(); + $subject="Nineschool : Nouvelle Activité à réaliser"; + $body ="Activité = ".$activity->getName()."
"; + $body.="Professeur = ".$activity->getUser()->getDisplayname()."
"; + $body.="Matière = ".$activity->getSubject()."
"; + $body.="Url = ".$this->router->generate('app_answer_update', ["id"=>$answer->getId()], UrlGeneratorInterface::ABSOLUTE_URL); + + $this->mail->sendEmail($subject, $body, $to, $from); + } + } + } + } + } diff --git a/src/nineschool-1.0/src/Controller/AnswerController.php b/src/nineschool-1.0/src/Controller/AnswerController.php index 62e2d97..f221f55 100755 --- a/src/nineschool-1.0/src/Controller/AnswerController.php +++ b/src/nineschool-1.0/src/Controller/AnswerController.php @@ -117,7 +117,7 @@ class AnswerController extends AbstractController // Affichage du formulaire return $this->render($this->render.'edit.html.twig', [ 'useheader' => true, - 'usesidebar' => ($this->getUser()->hasRole("ROLE_ADMIN")), + 'usesidebar' => false, $this->data => $data, 'mode' => 'update', 'form' => $form->createView() @@ -227,7 +227,7 @@ class AnswerController extends AbstractController // Affichage du formulaire return $this->render($this->render.'view.html.twig', [ 'useheader' => true, - 'usesidebar' => ($this->getUser()->hasRole("ROLE_ADMIN")), + 'usesidebar' => false, $this->data => $data, 'mode' => 'update', 'form' => $form->createView() diff --git a/src/nineschool-1.0/src/Controller/SecurityController.php b/src/nineschool-1.0/src/Controller/SecurityController.php index 4349747..43eef84 100755 --- a/src/nineschool-1.0/src/Controller/SecurityController.php +++ b/src/nineschool-1.0/src/Controller/SecurityController.php @@ -239,7 +239,7 @@ class SecurityController extends AbstractController // Récupération des informations du user try{ - $response = \Unirest\Request::post($url.'/rest/user/'.$user->getUsername(),$headers,["key"=>$appmasterkey]); + $response = \Unirest\Request::post($url.'/rest/user/'.$user->getUsername(),$headers,["key"=>$appmasterkey,"only"=>"user,groups"]); } catch (\Exception $e) { die("Erreur de communication API = ".$e->getMessage()."\n"); diff --git a/src/nineschool-1.0/src/Form/ActivityType.php b/src/nineschool-1.0/src/Form/ActivityType.php index 462b1f0..ce083b0 100644 --- a/src/nineschool-1.0/src/Form/ActivityType.php +++ b/src/nineschool-1.0/src/Form/ActivityType.php @@ -33,7 +33,7 @@ class ActivityType extends AbstractType ] ); - if($options["status"]==0) { + if($options["mode"]=="update"&&$options["status"]==0) { $builder->add('distribution', SubmitType::class, [ "label" => "Distribuer", diff --git a/src/nineschool-1.0/src/Migrations/.gitignore b/src/nineschool-1.0/src/Migrations/.gitignore index cde8069..66ca35b 100644 --- a/src/nineschool-1.0/src/Migrations/.gitignore +++ b/src/nineschool-1.0/src/Migrations/.gitignore @@ -1 +1 @@ -*.php +*.php \ No newline at end of file diff --git a/src/nineschool-1.0/templates/Activity/edit.html.twig b/src/nineschool-1.0/templates/Activity/edit.html.twig index 8c092f2..1031e8f 100755 --- a/src/nineschool-1.0/templates/Activity/edit.html.twig +++ b/src/nineschool-1.0/templates/Activity/edit.html.twig @@ -159,6 +159,7 @@ +


{{ form_end(form) }} diff --git a/src/nineschool-1.0/templates/Document/upload.html.twig b/src/nineschool-1.0/templates/Document/upload.html.twig index a250bef..ebc84ce 100644 --- a/src/nineschool-1.0/templates/Document/upload.html.twig +++ b/src/nineschool-1.0/templates/Document/upload.html.twig @@ -1,9 +1,8 @@ {% extends 'base.html.twig' %} -{% block head_style %} - {{ encore_entry_link_tags('app') }} +{% block encorelinktags %} {{ encore_entry_link_tags('dropzone') }} -{% endblock head_style %} +{% endblock encorelinktags %} {% block body %}