Compare commits
No commits in common. "89feb2c3580cc35b88bc28eb84b9ce4eebcb0e01" and "203b658726ee726a6aaa955c9a7f1695b581eaad" have entirely different histories.
89feb2c358
...
203b658726
|
@ -7,17 +7,22 @@ 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 Ramsey\Uuid\Uuid;
|
||||
|
||||
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;
|
||||
|
@ -25,12 +30,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()
|
||||
|
@ -102,17 +110,6 @@ class SynchroUsersCommand extends Command
|
|||
$ldapusers = array();
|
||||
$ldapmails = array();
|
||||
|
||||
// Suppression des groupe ninegate
|
||||
$groups=$this->em->getRepository("App:Group")->findAll();
|
||||
foreach($groups as $group) {
|
||||
if($group->getIdexternal()) {
|
||||
$this->writeln(" - Suppression dans Bundle >> ".$group->getName());
|
||||
if(!$simulate) {
|
||||
$this->em->remove($group);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($ldap_model=="scribe") {
|
||||
$this->writeln('');
|
||||
|
@ -158,32 +155,6 @@ class SynchroUsersCommand extends Command
|
|||
if(!$simulate) $this->addmodGroup($label,$ldapfilter,true);
|
||||
}
|
||||
|
||||
// Elèves des Classes
|
||||
$this->writeln('');
|
||||
$this->writeln('== ELEVES DES CLASSES ==========================================');
|
||||
$results = $this->ldap->search("type=Classe", ['cn','description','gidNumber'], $this->ldap_basedn);
|
||||
foreach($results as $result) {
|
||||
$cn=$result["cn"];
|
||||
$ldapfilter="(&(type=Classe)(cn=$cn))";
|
||||
|
||||
$label="ELEVES - ".$result["cn"];
|
||||
$this->writeln(" - $label");
|
||||
if(!$simulate) $this->addmodGroup($label,$ldapfilter,false);
|
||||
}
|
||||
|
||||
// Professeurs des Classes
|
||||
$this->writeln('');
|
||||
$this->writeln('== PROFESSEURS DES CLASSES ==========================================');
|
||||
$results = $this->ldap->search("type=Classe", ['cn','description','gidNumber'], $this->ldap_basedn);
|
||||
foreach($results as $result) {
|
||||
$cn=$result["cn"];
|
||||
$ldapfilter="(|(&(type=Equipe)(cn=profs-$cn))(&(ENTPersonProfils=Administratif)(divcod=$cn)))";
|
||||
|
||||
$label="PROFESSEURS - ".$result["cn"];
|
||||
$this->writeln(" - $label");
|
||||
if(!$simulate) $this->addmodGroup($label,$ldapfilter,false);
|
||||
}
|
||||
|
||||
// Options
|
||||
$this->writeln('');
|
||||
$this->writeln('== OPTIONS ==========================================');
|
||||
|
@ -416,6 +387,15 @@ class SynchroUsersCommand extends Command
|
|||
$this->writeln('== GROUPS ============================================');
|
||||
$groups=$this->em->getRepository("App:Group")->findAll();
|
||||
foreach($groups as $group) {
|
||||
if($group->getIdexternal()) {
|
||||
$this->writeln(" - Suppression dans Bundle >> ".$group->getName());
|
||||
if(!$simulate) {
|
||||
$this->em->remove($group);
|
||||
$this->em->flush();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(!$group->getLdapfilter()) continue;
|
||||
|
||||
if(!in_array($group->getId(),$this->ldapgroups)) {
|
||||
|
@ -444,25 +424,12 @@ class SynchroUsersCommand extends Command
|
|||
$this->writeln('== SYNCHONISATION NINEGATE TO BUNDLE ================');
|
||||
$this->writeln('=====================================================');
|
||||
|
||||
|
||||
// Suppression des groupe annuaire
|
||||
$groups=$this->em->getRepository("App:Group")->findAll();
|
||||
foreach($groups as $group) {
|
||||
if($group->getLdapfilter()) {
|
||||
$this->writeln(" - Suppression dans Bundle >> ".$group->getName());
|
||||
if(!$simulate) {
|
||||
$this->em->remove($group);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$appmasterurl = $this->container->getParameter("appMasterurl");
|
||||
$appmasterkey = $this->container->getParameter("appMasterkey");
|
||||
|
||||
// Généraltion de l'urol de communication
|
||||
if(stripos($appmasterurl,"/")===0) {
|
||||
$url="http://".$this->container->getParameter("appWeburl").$appmasterurl;
|
||||
$url="https://".$this->container->getParameter("appWeburl").$appmasterurl;
|
||||
}
|
||||
else
|
||||
$url=$appmasterurl;
|
||||
|
@ -601,7 +568,7 @@ class SynchroUsersCommand extends Command
|
|||
$this->writeln($group->getName());
|
||||
|
||||
$usergroups=[];
|
||||
if($tabgroups[$group->getIdexternal()])
|
||||
if(array_key_exists($group->getIdexternal(),$tabgroups)&&$tabgroups[$group->getIdexternal()])
|
||||
$usergroups = $tabgroups[$group->getIdexternal()]["users"];
|
||||
$tbusers=[];
|
||||
foreach($usergroups as $user) {
|
||||
|
@ -632,6 +599,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('');
|
||||
|
@ -664,6 +637,15 @@ class SynchroUsersCommand extends Command
|
|||
$this->writeln('== GROUPS ============================================');
|
||||
$groups=$this->em->getRepository("App:Group")->findAll();
|
||||
foreach($groups as $group) {
|
||||
if($group->getLdapfilter()) {
|
||||
$this->writeln(" - Suppression dans Bundle >> ".$group->getName());
|
||||
if(!$simulate) {
|
||||
$this->em->remove($group);
|
||||
$this->em->flush();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(!$group->getIdexternal()) continue;
|
||||
|
||||
if(!in_array($group->getIdexternal(),$lstgroups)) {
|
||||
|
@ -714,15 +696,13 @@ class SynchroUsersCommand extends Command
|
|||
|
||||
protected function addUser($username,$firstname,$lastname,$email,$usersadmin) {
|
||||
$user = new User();
|
||||
$key = Uuid::uuid4();
|
||||
|
||||
$user->setUsername($username);
|
||||
$user->setPassword("NOPASSWORD");
|
||||
$user->setLastname($lastname);
|
||||
$user->setFirstname($firstname);
|
||||
$user->setEmail($email);
|
||||
$user->setApiKey($key);
|
||||
|
||||
|
||||
// Definition du role
|
||||
if(in_array($username,$usersadmin))
|
||||
$role="ROLE_ADMIN";
|
||||
|
@ -766,4 +746,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -76,8 +76,8 @@ LDAP_USERNAME=uid
|
|||
LDAP_FIRSTNAME=givenname
|
||||
LDAP_LASTNAME=sn
|
||||
LDAP_EMAIL=mail
|
||||
LDAP_FILTERGROUP='(&(ObjectClass=posixGroup)(cn=*))'
|
||||
LDAP_FILTERUSER='(&(ObjectClass=person)(uid=*))'
|
||||
LDAP_FILTERGROUP=(cn=*)
|
||||
LDAP_FILTERUSER=(uid=*)
|
||||
%else
|
||||
LDAP_USERNAME=%%nineschool_ldapuid
|
||||
LDAP_FIRSTNAME=%%nineschool_ldapfirstname
|
||||
|
|
Loading…
Reference in New Issue