mise à jour

This commit is contained in:
afornerot 2020-10-05 14:40:13 +02:00
parent dc41ce62c4
commit 2e56de5d09
7 changed files with 71 additions and 13 deletions

View File

@ -7,16 +7,21 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Security\Core\Encoder\EncoderFactory; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
use App\Entity\Group; use App\Entity\Group as Group;
use App\Entity\User; 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 class SynchroUsersCommand extends Command
{ {
private $container; private $container;
private $router;
private $em; private $em;
private $output; private $output;
private $filesystem; private $filesystem;
@ -24,12 +29,15 @@ class SynchroUsersCommand extends Command
private $ldap; private $ldap;
private $ldap_basedn; private $ldap_basedn;
private $ldapgroups=[]; private $ldapgroups=[];
private $mail;
public function __construct(ContainerInterface $container,EntityManagerInterface $em) public function __construct(ContainerInterface $container,EntityManagerInterface $em,RouterInterface $router, mailService $mail)
{ {
parent::__construct(); parent::__construct();
$this->container = $container; $this->container = $container;
$this->em = $em; $this->em = $em;
$this->router = $router;
$this->mail = $mail;
} }
protected function configure() protected function configure()
@ -587,6 +595,12 @@ class SynchroUsersCommand extends Command
$this->em->persist($group); $this->em->persist($group);
$this->em->flush(); $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(''); $this->writeln('');
@ -728,4 +742,48 @@ class SynchroUsersCommand extends Command
$this->em->flush(); $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()."<br>";
$body.="Professeur = ".$activity->getUser()->getDisplayname()."<br>";
$body.="Matière = ".$activity->getSubject()."<br>";
$body.="Url = ".$this->router->generate('app_answer_update', ["id"=>$answer->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
$this->mail->sendEmail($subject, $body, $to, $from);
}
}
}
}
} }

View File

@ -117,7 +117,7 @@ class AnswerController extends AbstractController
// Affichage du formulaire // Affichage du formulaire
return $this->render($this->render.'edit.html.twig', [ return $this->render($this->render.'edit.html.twig', [
'useheader' => true, 'useheader' => true,
'usesidebar' => ($this->getUser()->hasRole("ROLE_ADMIN")), 'usesidebar' => false,
$this->data => $data, $this->data => $data,
'mode' => 'update', 'mode' => 'update',
'form' => $form->createView() 'form' => $form->createView()
@ -227,7 +227,7 @@ class AnswerController extends AbstractController
// Affichage du formulaire // Affichage du formulaire
return $this->render($this->render.'view.html.twig', [ return $this->render($this->render.'view.html.twig', [
'useheader' => true, 'useheader' => true,
'usesidebar' => ($this->getUser()->hasRole("ROLE_ADMIN")), 'usesidebar' => false,
$this->data => $data, $this->data => $data,
'mode' => 'update', 'mode' => 'update',
'form' => $form->createView() 'form' => $form->createView()

View File

@ -239,7 +239,7 @@ class SecurityController extends AbstractController
// Récupération des informations du user // Récupération des informations du user
try{ 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) { catch (\Exception $e) {
die("Erreur de communication API = ".$e->getMessage()."\n"); die("Erreur de communication API = ".$e->getMessage()."\n");

View File

@ -33,7 +33,7 @@ class ActivityType extends AbstractType
] ]
); );
if($options["status"]==0) { if($options["mode"]=="update"&&$options["status"]==0) {
$builder->add('distribution', $builder->add('distribution',
SubmitType::class, [ SubmitType::class, [
"label" => "Distribuer", "label" => "Distribuer",

View File

@ -159,6 +159,7 @@
</div> </div>
</div> </div>
</div> </div>
<br><br><br>
{{ form_end(form) }} {{ form_end(form) }}

View File

@ -1,9 +1,8 @@
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block head_style %} {% block encorelinktags %}
{{ encore_entry_link_tags('app') }}
{{ encore_entry_link_tags('dropzone') }} {{ encore_entry_link_tags('dropzone') }}
{% endblock head_style %} {% endblock encorelinktags %}
{% block body %} {% block body %}