Commit 681b09bb authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Mise en place de la structure de base et début d'implémentation de la couche fonctionnelle

parent 92d5387d
Loading
Loading
Loading
Loading
+3
Changes for src/UnicaenLdap/Entity/Entity.php: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -46,8 +46,11 @@ abstract class Entity
    public static function getNodeParams($type)
    {
        $params = array(
            'Generic' => array( 'uid', 'UnicaenLdap\\Entity\\Generic' ),
            'Group' => array( 'cn', 'UnicaenLdap\\Entity\\Group' ),
            'People' => array( 'uid', 'UnicaenLdap\\Entity\\People' ),
            'Structure' => array( 'supannCodeEntite', 'UnicaenLdap\\Entity\\Structure' ),
            'System' => array( 'uid', 'UnicaenLdap\\Entity\\System' ),
        );
        if (! isset($params[$type])) throw new Exception('Paramètres de "'.$type.'" non trouvés');
        return $params[$type];
+77
Changes for src/UnicaenLdap/Entity/People.php: 77 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
namespace UnicaenLdap\Entity;

use UnicaenLdap\Entity\Group;
use UnicaenLdap\Entity\Structure;
use DateTime;


@@ -122,6 +123,82 @@ class People extends Entity
        return 0 === strpos($this->uid, 'i');
    }

    /**
     * Retourne les structures auxquelles appartiennent la personne
     *
     * @return Structure[]
     */
    public function getEduPersonOrgUnit()
    {
        $structure = $this->getService()->getServiceManager()->get('ldapServiceStructure');
        $dn = $this->eduPersonOrgUnitDN;
        if (empty($dn)) return null;
        return $structure->getAllBy( $dn, 'dn' );
    }

    /**
     * Retourne la structure principale à laquelle appartient la personne
     *
     * @return Structure
     */
    public function getEduPersonPrimaryOrgUnit()
    {
        $structure = $this->getService()->getServiceManager()->get('ldapServiceStructure');
        $dn = $this->eduPersonPrimaryOrgUnitDN;
        if (empty($dn)) return null;
        return $structure->getBy( $dn, 'dn' );
    }

    /**
     * Retourne la structure d'affectation de la personne
     * @todo à terminer
     * @return Structure[]
     */
    public function getEntiteAffectation()
    {
        throw new \Exception('Méthode pas finie');
        $structure = $this->getService()->getServiceManager()->get('ldapServiceStructure');
        $codes = $this->getNode()->getAttribute('supannEntiteAffectation');
        var_dump($codes);
        return $structure->getBy( $dn, 'dn' );
    }

    /**
     * Retourne la structure d'affectation de la personne
     * @todo à terminer
     * @return Structure
     */
    public function getEntiteAffectationPrincipale()
    {
        throw new \Exception('Méthode pas finie');
        $structure = $this->getService()->getServiceManager()->get('ldapServiceStructure');

        $codes = array();
        $affectations = $this->getNode()->getAttribute('supannAffectation');


        list($code, $description) = explode( ';', $this->supannAffectation );
        $code = $this->supannAffectation;
        if (empty($dn)) return null;
        return $structure->getBy( $dn, 'dn' );
    }

    /**
     * Retourne la structure d'affectation de la personne
     * @todo à terminer
     * @return Structure
     */
    public function getAffectationDescription()
    {
        throw new \Exception('Méthode pas finie');
        $structure = $this->getService()->getServiceManager()->get('ldapServiceStructure');
        
        list($code, $description) = explode( ';', $this->supannAffectation );
        $code = $this->supannAffectation;
        if (empty($dn)) return null;
        return $structure->getBy( $dn, 'dn' );
    }

   /**
     * Retourne true si l'argument est au format "supannRoleEntite".
     *
+50
Changes for src/UnicaenLdap/Entity/Structure.php: 50 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php
namespace UnicaenLdap\Entity;

use UnicaenLdap\Filter\Filter;

/**
 * Classe mère des structures de l'annuaire LDAP.
 *
@@ -18,4 +20,52 @@ class Structure extends Entity
     */
    protected $dateTimeAttributes = array(
    );

    /**
     * Retourne la structure parente, si elle existe
     *
     * @return Structure[]
     */
    public function getParents()
    {
        if (null !== $parentIds = $this->get('supannCodeEntiteParent')){
            return $this->service->getAll($parentIds);
        }
        return null;
    }

    /**
     * Retourne la liste des structures filles
     *
     * @param string|Filter $filter  Filtre éventuel
     * @param string $orderBy        Champ de tri
     * @return Structure[]
     */
    public function getChildren( $filter=null, $orderBy=null )
    {
        $childrenFilter = Filter::equals('supannCodeEntiteParent', $this->getId());

        if (empty($filter)){
            $filter = $childrenFilter;
        }else{
            if (is_string($filter)) $filter = Filter::string ($filter);
            $filter = Filter::andFilter($childrenFilter, $filter);
        }
        return $this->service->search($filter, $orderBy, -1, 0);
    }

    /**
     * Retourne le code Harpège
     *
     * @return string
     */
    public function getCodeHarpege()
    {
        $code = $this->get('supannCodeEntite');
        if (0 === strpos($code, 'HS_')){
            return substr( $code, 3 );
        }else{
            return null; // Ne retourne rien si le code ne correspond pas à la nomenclature Harpège
        }
    }
}
 No newline at end of file
+39
Changes for src/UnicaenLdap/Filter/Structure.php: 39 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php
namespace UnicaenLdap\Filter;

/**
 * Filtres pour les structures
 *
 * @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
 */
class Structure extends Filter
{

    public static function pedagogique()
    {
        return self::orFilter(
            self::equals('supannTypeEntite', '{SUPANN}F100'), // Diplômes
            self::equals('supannTypeEntite', '{SUPANN}F200'), // ? ?
            self::equals('supannTypeEntite', '{SUPANN}F300')  // Unités
        );
    }

    /**
     * Code ou liste de codes Harpège
     *
     * @param string|array $codes
     */
    public static function codeHarpege( $codes )
    {
        if (is_string($codes)){
            return self::equals('supannCodeEntite', 'HS_'.$codes);
        }else{
            $filters = array();
            foreach( $codes as $code ){
                $filters[] = self::codeHarpege($code);
            }
            return call_user_func_array(__CLASS__.'::orFilter', $filters);
        }
    }

}
 No newline at end of file
+18 −1
Changes for src/UnicaenLdap/Service/Service.php: 18 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -186,8 +186,11 @@ abstract class Service implements ServiceManagerAwareInterface
            $i = 0;
            ErrorHandler::start(E_WARNING);
            for ($entry=ldap_first_entry($resource,$search); $entry; $entry=ldap_next_entry($resource,$entry)) {
                $result[] = ldap_get_values_len($resource,$entry,$key)[0];
                $value = ldap_get_values_len($resource,$entry,$key)[0];
                if (null !== $value){
                    $result[] = $value;
                    $i++;
                }
                if ($i > $limit + $offset - 1) break; // Pas besoin d'aller plus loin...
            }
            ErrorHandler::stop();
@@ -195,6 +198,7 @@ abstract class Service implements ServiceManagerAwareInterface
            $result = array();
        }
        $this->__searchEnd( $search );
        $this->count = count($result);
        return new Collection( $this, array_slice( $result, $offset, $limit ) );
    }

@@ -415,6 +419,19 @@ abstract class Service implements ServiceManagerAwareInterface
        }
    }

    /**
     * Retourne un tableau d'entités de format array[ID] = Entite
     * 
     * @param string[] $ids   Tableau d'identifiants
     * @param string $orderBy Nom d'attribut à trier
     * @return Entity[]
     */
    public function getAll( $ids, $orderBy=null )
    {
        $key = Entity::getNodeParams($this->type)[0];
        return $this->getAllBy($ids, $key, $orderBy);
    }

    /**
     * Retourne un tableau d'entités de format array[ID] = Entite
     *
Loading