synchro modif
This commit is contained in:
parent
870b4701d5
commit
1faf9935b9
|
@ -7,22 +7,17 @@ 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\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
|
||||
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
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;
|
||||
use App\Entity\Group;
|
||||
use App\Entity\User;
|
||||
|
||||
class SynchroUsersCommand extends Command
|
||||
{
|
||||
private $container;
|
||||
private $router;
|
||||
private $em;
|
||||
private $output;
|
||||
private $filesystem;
|
||||
|
@ -30,15 +25,12 @@ class SynchroUsersCommand extends Command
|
|||
private $ldap;
|
||||
private $ldap_basedn;
|
||||
private $ldapgroups=[];
|
||||
private $mail;
|
||||
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em,RouterInterface $router, mailService $mail)
|
||||
public function __construct(ContainerInterface $container,EntityManagerInterface $em)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->container = $container;
|
||||
$this->em = $em;
|
||||
$this->router = $router;
|
||||
$this->mail = $mail;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
|
@ -110,6 +102,17 @@ 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('');
|
||||
|
@ -155,6 +158,32 @@ 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 DE LA CLASSE - ".$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 DE LA CLASSE - ".$result["cn"];
|
||||
$this->writeln(" - $label");
|
||||
if(!$simulate) $this->addmodGroup($label,$ldapfilter,false);
|
||||
}
|
||||
|
||||
// Options
|
||||
$this->writeln('');
|
||||
$this->writeln('== OPTIONS ==========================================');
|
||||
|
@ -387,15 +416,6 @@ 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)) {
|
||||
|
@ -424,12 +444,25 @@ 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="https://".$this->container->getParameter("appWeburl").$appmasterurl;
|
||||
$url="http://".$this->container->getParameter("appWeburl").$appmasterurl;
|
||||
}
|
||||
else
|
||||
$url=$appmasterurl;
|
||||
|
@ -568,7 +601,7 @@ class SynchroUsersCommand extends Command
|
|||
$this->writeln($group->getName());
|
||||
|
||||
$usergroups=[];
|
||||
if(array_key_exists($group->getIdexternal(),$tabgroups)&&$tabgroups[$group->getIdexternal()])
|
||||
if($tabgroups[$group->getIdexternal()])
|
||||
$usergroups = $tabgroups[$group->getIdexternal()]["users"];
|
||||
$tbusers=[];
|
||||
foreach($usergroups as $user) {
|
||||
|
@ -599,12 +632,6 @@ 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('');
|
||||
|
@ -637,15 +664,6 @@ 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)) {
|
||||
|
@ -696,13 +714,15 @@ 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";
|
||||
|
@ -746,48 +766,4 @@ 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=(cn=*)
|
||||
LDAP_FILTERUSER=(uid=*)
|
||||
LDAP_FILTERGROUP=(&(ObjectClass=posixGroup)(cn=*))
|
||||
LDAP_FILTERUSER=(&(ObjectClass=person)(uid=*))
|
||||
%else
|
||||
LDAP_USERNAME=%%nineschool_ldapuid
|
||||
LDAP_FIRSTNAME=%%nineschool_ldapfirstname
|
||||
|
|
Loading…
Reference in New Issue