Commit d865fa53 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Corrections pour passer à ZF3.

parent e8fe4a66
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ class Group extends Entity
    public function getPeople($orderBy = null)
    {
        /* @var $people \UnicaenLdap\Service\People */
        $people = $this->getService()->getServiceLocator()->get('ldapServicePeople');
        $people = $this->getService()->getLdapServiceForEntityClass(\UnicaenLdap\Service\People::class);

        /** @var People[] $result */
        $result = $people->getAllBy($this->get('member'), 'dn', $orderBy);
+24 −6
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ class People extends Entity
     */
    public function getGroups(DateTime $dateObservation = null, $orderBy = null)
    {
        $group = $this->getService()->getServiceLocator()->get('ldapServiceGroup');
        $group = $this->getService()->getLdapServiceForEntityClass(\UnicaenLdap\Service\Group::class);

        return $group->filterValids($group->getAllBy($this->get('memberOf'), 'dn', $orderBy), $dateObservation);
    }
@@ -168,6 +168,24 @@ class People extends Entity
        return 0 === strpos($this->uid, 'i');
    }

    /**
     * @var \UnicaenLdap\Service\Structure
     */
    protected $ldapStructureService;

    /**
     * @return \UnicaenLdap\Service\Structure
     */
    protected function getLdapStructureService()
    {
        if (null === $this->ldapStructureService) {
            $this->ldapStructureService =
                $this->getService()->getLdapServiceForEntityClass(\UnicaenLdap\Service\Structure::class);
        }

        return $this->ldapStructureService;
    }

    /**
     * Retourne les structures auxquelles appartiennent la personne
     *
@@ -175,7 +193,7 @@ class People extends Entity
     */
    public function getEduPersonOrgUnit()
    {
        $structure = $this->getService()->getServiceLocator()->get('ldapServiceStructure');
        $structure = $this->getLdapStructureService();
        $dn = $this->eduPersonOrgUnitDN;
        if (empty($dn)) return null;

@@ -189,7 +207,7 @@ class People extends Entity
     */
    public function getEduPersonPrimaryOrgUnit()
    {
        $structure = $this->getService()->getServiceLocator()->get('ldapServiceStructure');
        $structure = $this->getLdapStructureService();
        $dn = $this->eduPersonPrimaryOrgUnitDN;
        if (empty($dn)) return null;

@@ -206,7 +224,7 @@ class People extends Entity
    public function getEntiteAffectation()
    {
        throw new \Exception('Méthode pas finie');
        $structure = $this->getService()->getServiceLocator()->get('ldapServiceStructure');
        $structure = $this->getLdapStructureService();
        $codes = $this->getNode()->getAttribute('supannEntiteAffectation');
        var_dump($codes);

@@ -223,7 +241,7 @@ class People extends Entity
    public function getEntiteAffectationPrincipale()
    {
        throw new \Exception('Méthode pas finie');
        $structure = $this->getService()->getServiceLocator()->get('ldapServiceStructure');
        $structure = $this->getLdapStructureService();

        $codes = [];
        $affectations = $this->getNode()->getAttribute('supannAffectation');
@@ -246,7 +264,7 @@ class People extends Entity
    public function getAffectationDescription()
    {
        throw new \Exception('Méthode pas finie');
        $structure = $this->getService()->getServiceLocator()->get('ldapServiceStructure');
        $structure = $this->getLdapStructureService();

        list($code, $description) = explode(';', $this->supannAffectation);
        $code = $this->supannAffectation;
+36 −11
Original line number Diff line number Diff line
@@ -2,16 +2,14 @@

namespace UnicaenLdap\Service;

use UnicaenLdap\Ldap;
use UnicaenApp\Exception\RuntimeException;
use UnicaenLdap\Collection;
use UnicaenLdap\Entity\Entity;
use UnicaenLdap\Exception;
use UnicaenLdap\Collection;
use UnicaenLdap\Filter\Filter;
use Zend\ServiceManager\ServiceLocatorAwareTrait;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\Ldap\Filter\AbstractFilter;
use UnicaenLdap\Ldap;
use Zend\Ldap\Dn;
use Zend\Ldap\Filter\AbstractFilter;
use Zend\Stdlib\ErrorHandler;

/**
@@ -21,8 +19,6 @@ use Zend\Stdlib\ErrorHandler;
 */
abstract class AbstractService
{
    use ServiceLocatorAwareTrait;

    /**
     * Limite de recherche par défaut
     */
@@ -57,6 +53,38 @@ abstract class AbstractService
     */
    protected $count;

    /**
     * @var array
     */
    protected $ldapServicesByEntityClass = [
        \UnicaenLdap\Entity\People::class    => null,
        \UnicaenLdap\Entity\Structure::class => null,
        \UnicaenLdap\Entity\System::class    => null,
        \UnicaenLdap\Entity\Group::class     => null,
        \UnicaenLdap\Entity\Generic::class   => null,
    ];

    /**
     * @param array
     */
    public function setLdapServicesByEntityClass(array $ldapServicesByEntityClass)
    {
        $this->ldapServicesByEntityClass = $ldapServicesByEntityClass;
    }

    /**
     * @param string $entityClass
     * @return mixed
     */
    public function getLdapServiceForEntityClass($entityClass)
    {
        if (! isset($this->ldapServicesByEntityClass[$entityClass])) {
            throw new RuntimeException("Le service de recherche LDAP pour la classe d'entité $entityClass n'a pas été injecté.");
        }

        return $this->ldapServicesByEntityClass[$entityClass];
    }

    /**
     * Retourne le type du service
     * 
@@ -74,9 +102,6 @@ abstract class AbstractService
     */
    public function getLdap()
    {
        if (empty($this->ldap)){
            $this->ldap = $this->getServiceLocator()->get('ldap');
        }
        return $this->ldap;
    }

+12 −1
Original line number Diff line number Diff line
@@ -22,7 +22,18 @@ class GenericFactory implements FactoryInterface
    {
        $service = new Generic();

        $service->setServiceLocator($container);
        /** @var \UnicaenLdap\Ldap $ldap */
        $ldap = $container->get('ldap');

        $service->setLdap($ldap);

        $service->setLdapServicesByEntityClass([
            \UnicaenLdap\Entity\People::class    => $container->get('ldapServiceGeneric'),
            \UnicaenLdap\Entity\Structure::class => $container->get('ldapServiceStructure'),
            \UnicaenLdap\Entity\System::class    => $container->get('ldapServiceSystem'),
            \UnicaenLdap\Entity\Group::class     => $container->get('ldapServiceGroup'),
            \UnicaenLdap\Entity\Generic::class   => $container->get('ldapServiceGeneric'),
        ]);

        return $service;
    }
+12 −1
Original line number Diff line number Diff line
@@ -22,7 +22,18 @@ class GroupFactory implements FactoryInterface
    {
        $service = new Group();

        $service->setServiceLocator($container);
        /** @var \UnicaenLdap\Ldap $ldap */
        $ldap = $container->get('ldap');

        $service->setLdap($ldap);

        $service->setLdapServicesByEntityClass([
            \UnicaenLdap\Entity\People::class    => $container->get('ldapServiceGeneric'),
            \UnicaenLdap\Entity\Structure::class => $container->get('ldapServiceStructure'),
            \UnicaenLdap\Entity\System::class    => $container->get('ldapServiceSystem'),
            \UnicaenLdap\Entity\Group::class     => $container->get('ldapServiceGroup'),
            \UnicaenLdap\Entity\Generic::class   => $container->get('ldapServiceGeneric'),
        ]);

        return $service;
    }
Loading