mise à jour
This commit is contained in:
parent
dc41ce62c4
commit
2e56de5d09
@ -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()."<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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");
|
||||
|
@ -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",
|
||||
|
2
src/nineschool-1.0/src/Migrations/.gitignore
vendored
2
src/nineschool-1.0/src/Migrations/.gitignore
vendored
@ -1 +1 @@
|
||||
*.php
|
||||
*.php
|
@ -159,6 +159,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br><br><br>
|
||||
|
||||
{{ form_end(form) }}
|
||||
|
||||
|
@ -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 %}
|
||||
|
Loading…
Reference in New Issue
Block a user