nineskeletor/src/Repository/Niveau01Repository.php

86 lines
2.6 KiB
PHP

<?php
namespace App\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\Niveau01;
use App\Service\LdapService;
class Niveau01Repository extends ServiceEntityRepository
{
private $ldapservice;
public function __construct(ManagerRegistry $registry, LdapService $ldapservice)
{
parent::__construct($registry, Niveau01::class);
$this->ldapservice=$ldapservice;
}
public function add(Niveau01 $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Niveau01 $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
/* Déterminer le niveau01 d'un user SSO en fonction de ses attributs */
public function calculateSSONiveau01($attruser)
{
$niveau01s = $this->_em->getRepository('App\Entity\Niveau01')->findAll();
foreach($niveau01s as $niveau01) {
if($niveau01->getAttributes()) {
$attniveau=json_decode($niveau01->getAttributes(),true);
foreach($attniveau as $key => $value) {
if(array_key_exists($key,$attruser)) {
if(is_array($attruser[$key])) {
foreach($attruser[$key] as $val) {
if($value=="*")
return $niveau01;
elseif($val==$value)
return $niveau01;
}
}
else {
if($value=="*")
return $niveau01;
elseif($value==$attruser[$key])
return $niveau01;
}
}
}
}
}
return false;
}
/* Déterminer le niveau01 d'un user LDAP */
public function calculateLDAPNiveau01($username)
{
$niveau01s = $this->_em->getRepository('App\Entity\Niveau01')->findAll();
foreach($niveau01s as $niveau01) {
if($niveau01->getLdapfilter()) {
$ismember=$this->ldapservice->findNiveau01ismember($niveau01->getLdapfilter(),$username);
if($ismember) return $niveau01;
}
}
return false;
}
}