Commit 679e9cf0 authored by surville's avatar surville
Browse files

[Evolution] Développement UnicaenLdap WIP

parent 08b0d71f
<?php
namespace UnicaenLdap\Entity\Base;
use UnicaenLdap\Entity\Entity;
use UnicaenLdap\Exception;
use Zend\Ldap\Attribute;
use Zend\Ldap\Exception\LdapException;
/**
* Classe mère des entités de la branche "generic" de l'annuaire LDAP.
*
* @author David Surville <david.surville@unicaen.fr>
*/
class Generic extends Entity
{
/**
* @var string
*/
protected $type = 'Generic';
/**
* Liste des classes d'objet nécessaires à la création d'une adresse générique
*
* @var array
*/
protected $objectClass = [
'top',
'inetOrgPerson',
'organizationalPerson',
'person',
];
/**
* Liste des attributs autorisés pour une entité "Generic"
*
* @var array
*/
protected $authorizedAttributes = [
// Attributes classes
'objectClass',
// Attributes
'cn',
'description',
'mail',
'sn',
'supannAliasLogin',
'ucbnServiceIMAP',
'userPassword',
];
/**
* Liste des attributs contenant des dates
*
* @var string[]
*/
protected $dateTimeAttributes = [
];
/**
* Liste des attributs monovalués
*
* @var array
*/
protected $monoValuedAttributes = [
'supannALiasLogin',
'ucbnServiceIMAP',
'userPassword',
];
/**
* Attribut Ldap "cn"
*
* @param array|string|null $value
* @param bool $append
* @return self
*/
public function setCn($value = null, $append = false)
{
$value = $this->preFormat($value);
$this->appendOrNot('cn', $value, $append);
return $this;
}
/**
* Attribut Ldap "description"
*
* @param array|string|null $value
* @param bool $append
* @return self
*/
public function setDescription($value = null, $append = false)
{
$value = $this->preFormat($value);
$this->appendOrNot('description', $value, $append);
return $this;
}
/**
* Attribut Ldap "mail"
*
* @param array|string|null $value
* @param bool $append
* @return self
* @throws Exception
* @throws LdapException
*/
public function setMail($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_filter(filter_var_array($value, FILTER_VALIDATE_EMAIL));
$this->appendOrNot('mail', $value, $append);
return $this;
}
/**
* Attribut Ldap "sn"
*
* @param array|string|null $value
* @param bool $append
* @return self
*/
public function setSn($value = null, $append = false)
{
$value = $this->preFormat($value);
$this->appendOrNot('sn', $value, $append);
return $this;
}
/**
* Attribut Ldap "supannALiasLogin"
*
* @param array|string|null $value
* @param bool $append
* @return self
* @throws Exception
* @throws LdapException
*/
public function setSupannAliasLogin($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_map('strtolower', $value);
$value = array_filter($value, function ($v) {
return preg_match('/^[0-9a-z\-]+$/', $v);
});
$this->appendOrNot('supannAliasLogin', $value, $append);
return $this;
}
/**
* Attribut Ldap "ucbnServiceIMAP"
*
* @param array|string|null $value
* @param bool $append
* @return self
* @throws Exception
* @throws LdapException
*/
public function setUcbnServiceIMAP($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_map([$this, 'formatBoolean'], $value);
$this->appendOrNot('ucbnServiceIMAP', $value, $append);
return $this;
}
/**
* Attribut Ldap "userPassword"
*
* @param string $value
* @return self
* @throws LdapException
*/
public function setUserPassword(string $value)
{
$this->getNode()->setPasswordAttribute($value, Attribute::PASSWORD_HASH_SHA, 'userPassword');
return $this;
}
}
\ No newline at end of file
......@@ -94,8 +94,6 @@ class Group extends Entity
* @param array|string|null $value
* @param bool $append
* @return self
* @throws Exception
* @throws LdapException
*/
public function setDescription($value = null, $append = false)
{
......
......@@ -72,21 +72,21 @@ class People extends Entity
'objectClass',
// Attributes
'cn',
'displayName',
'dateDeNaissance',
'eduPersonPrincipalName',
'eduPersonNickname', // no getter and setter
'dateFinInscription',
'displayName',
'eduPersonAffiliation',
'eduPersonPrimaryAffiliation',
'eduPersonNickname',
'eduPersonOrgDN',
'eduPersonOrgUnitDN',
'eduPersonPrimaryAffiliation',
'eduPersonPrimaryOrgUnitDN',
'dateFinInscription',
'facsimileTelephoneNumber', // no getter and setter
'eduPersonPrincipalName',
'facsimileTelephoneNumber',
'gidNumber',
'givenName',
'homeDirectory',
'labeledURI', // no getter and setter
'labeledURI',
'leoCode',
'loginShell',
'mail',
......@@ -131,7 +131,7 @@ class People extends Entity
'supannRefId',
'supannTypeEntiteAffectation',
'telephoneNumber',
'title', // no getter and setter
'title',
'ucbnAnneePostBac',
'ucbnCodeEtape',
'ucbnEtuComplementInscription',
......@@ -198,6 +198,8 @@ class People extends Entity
'supannEtuId',
'supannListeRouge',
'telephoneNumber',
'ucbnServiceADE',
'ucbnServicePapercut',
'ucbnSquidHash',
'uidNumber',
'userPassword',
......@@ -275,8 +277,15 @@ class People extends Entity
'\[affect=(?<affect>[\w\-]+)\]' .
'\[diplome=(?<diplome>\{[\w\-:]+\}\w+)\]' .
'\[etape=(?<etape>\{[\w\-:]+\}.+)\]$/';
static protected $inscription_complement_pattern = '/^\[anneeinsc=(?<anneeinsc>\d{4})\]\[etape=(?<etape>\{[\w\-:]+\}.+)\]\[adistance=(?<adistance>\{[\w\-:]+\}\w{1})\]$/';
static protected $role_pattern = '/^\[role=(?<role>\{SUPANN\}[\w\-]+)\]\[type=(?<type>\{SUPANN\}[\w\-]+)\]\[code=(?<code>[\w\-]+)\]\[libelle=(?<libelle>.+)\]$/';
static protected $inscription_complement_pattern =
'/^\[anneeinsc=(?<anneeinsc>\d{4})\]' .
'\[etape=(?<etape>\{[\w\-:]+\}.+)\]' .
'\[adistance=(?<adistance>\{[\w\-:]+\}\w{1})\]$/';
static protected $role_pattern =
'/^\[role=(?<role>\{SUPANN\}[\w\-]+)\]' .
'\[type=(?<type>\{SUPANN\}[\w\-]+)\]' .
'\[code=(?<code>[\w\-]+)\]' .
'\[libelle=(?<libelle>.+)\]$/';
static protected $role_src_pattern = '/^(?<code>\d{4});(?<libelle>.+)$/';
......@@ -577,6 +586,24 @@ class People extends Entity
return $this;
}
/**
* Attribut Ldap "mail"
*
* @param array|string|null $value
* @param bool $append
* @return self
* @throws Exception
* @throws LdapException
*/
public function setMail($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_filter(filter_var_array($value, FILTER_VALIDATE_EMAIL));
$this->appendOrNot('mail', $value, $append);
return $this;
}
/**
* Attribut Ldap "mobile"
*
......@@ -595,6 +622,24 @@ class People extends Entity
return $this;
}
/**
* Attribut Ldap "pager"
*
* @param array|string|null $value
* @param bool $append
* @return self
* @throws Exception
* @throws LdapException
*/
public function setPager($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_map([$this, 'formatTel'], $value);
$this->appendOrNot('pager', $value, $append);
return $this;
}
/**
* Attribut Ldap "preferredLanguage"
*
......
......@@ -97,7 +97,7 @@ class Root extends Entity
public function setEduOrgHomePageURI($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = filter_var_array($value, FILTER_VALIDATE_URL);
$value = array_filter(filter_var_array($value, FILTER_VALIDATE_URL));
$this->appendOrNot('eduOrgHomePageURI', $value, $append);
return $this;
......@@ -132,7 +132,7 @@ class Root extends Entity
public function setEduOrgSuperiorURI($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = filter_var_array($value, FILTER_VALIDATE_URL);
$value = array_filter(filter_var_array($value, FILTER_VALIDATE_URL));
$this->appendOrNot('eduOrgSuperiorURI', $value, $append);
return $this;
......@@ -150,7 +150,7 @@ class Root extends Entity
public function setEduOrgWhitePagesURI($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = filter_var_array($value, FILTER_VALIDATE_URL);
$value = array_filter(filter_var_array($value, FILTER_VALIDATE_URL));
$this->appendOrNot('eduOrgWhitePagesURI', $value, $append);
return $this;
......
<?php
namespace UnicaenLdap\Entity\Base;
use UnicaenLdap\Entity\Entity;
use Zend\Ldap\Attribute;
use Zend\Ldap\Exception\LdapException;
/**
* Classe mère des entités de la branche "system" de l'annuaire LDAP.
*
* @author David Surville <david.surville@unicaen.fr>
*/
class System extends Entity
{
protected $type = 'System';
/**
* Liste des classes d'objet nécessaires à la création d'un compte système
*
* @var string[]
*/
protected $objectClass = [
'top',
'inetOrgPerson',
'organizationalPerson',
'person',
'supannPerson',
'ucbnEmp',
];
/**
* Liste des attributs autorisés pour une entité "Generic"
*
* @var array
*/
protected $authorizedAttributes = [
// Attributes classes
'objectClass',
// Attributes
'cn',
'sn',
'userPassword',
];
/**
* Liste des attributs contenant des dates
*
* @var string[]
*/
protected $dateTimeAttributes = [
];
/**
* Attribut Ldap "cn"
*
* @param array|string|null $value
* @param bool $append
* @return self
*/
public function setCn($value = null, $append = false)
{
$value = $this->preFormat($value);
$this->appendOrNot('cn', $value, $append);
return $this;
}
/**
* Attribut Ldap "sn"
*
* @param array|string|null $value
* @param bool $append
* @return self
*/
public function setSn($value = null, $append = false)
{
$value = $this->preFormat($value);
$this->appendOrNot('sn', $value, $append);
return $this;
}
/**
* Attribut Ldap "userPassword"
*
* @param string $value
* @return self
* @throws LdapException
*/
public function setUserPassword(string $value)
{
$this->getNode()->setPasswordAttribute($value, Attribute::PASSWORD_HASH_SHA, 'userPassword');
return $this;
}
}
\ No newline at end of file
......@@ -2,34 +2,12 @@
namespace UnicaenLdap\Entity;
use UnicaenLdap\Entity\Base\Generic as BaseGeneric;
/**
* Classe mère des adresses génériques de l'annuaire LDAP.
* Classe de gestion des entités de la branche "generic" de l'annuaire LDAP.
*
* @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
*/
class Generic extends Entity
{
protected $type = 'Generic';
/**
* Liste des classes d'objet nécessaires à la création d'une adresse générique
*
* @var string[]
*/
protected $objectClass = [
'top',
'inetOrgPerson',
'organizationalPerson',
'person',
'supannPerson',
'ucbnEmp',
];
/**
* Liste des attributs contenant des dates
*
* @var string[]
*/
protected $dateTimeAttributes = [
];
}
\ No newline at end of file
class Generic extends BaseGeneric
{}
\ No newline at end of file
......@@ -162,11 +162,19 @@ class People extends BasePeople
/**
* Retourne l'adresse postale professionnelle
*
* @return array
* @param string $type type de l'adresse : 'professionnelle' ou 'personnelle'
* @return array|null
*/
public function getAdressePostale()
public function getAdressePostale($type = 'professionnelle')
{
$value = $this->preFormat($this->postalAddress);
if(!in_array($type, ['professionnelle', 'personnelle'])) {
return null;
}
$attributes = ($type == 'professionnelle')
? $this->postalAddress
: [$this->ucbnPrivateAddress, $this->ucbnPrivateAddressBis];
$value = $this->preFormat($attributes);
$value = array_map(function ($val) {
return explode('$', $val);
}, $value);
......@@ -440,7 +448,29 @@ class People extends BasePeople
}
/**
* Vérifie l'appartenance d'une personne à une structure
* Retourne les structures recherche auxquelles appartient la personne
*
* @return StructureEntity[]|null
*/
public function getStructureRecherche()
{
$structureService = $this->service->getLdapStructureService();
$structurePrefixe = $structureService->getCodeStructurePrefixe();
$value = $this->preFormat($this->ucbnStructureRecherche);
if (empty($value)) return null;
$value = array_map(function ($v) use ($structurePrefixe) {
preg_match(self::$structure_pattern, $v, $matches);
return $structurePrefixe . $matches['code'];
}, $value);
$value = $structureService->getAllBy($value, 'supannCodeEntite');
return 1 == count($value) ? array_shift($value) : $value;
}
/**
* Vérifie l'appartenance d'une personne à une structure (structures recherche incluses)
*
* @param string|Dn|StructureEntity $value
* @return bool
......@@ -471,13 +501,21 @@ class People extends BasePeople
}
$structures = $this->preFormat($this->supannEntiteAffectation);
return in_array($value->getId(), $structures);
$structuresRecherche = $this->preFormat($this->ucbnStructureRecherche);
$structuresRecherche = array_map(function ($v) use ($structurePrefixe) {
preg_match(self::$structure_pattern, $v, $matches);
return $structurePrefixe . $matches['code'];
}, $structuresRecherche);
return in_array($value->getId(), array_merge($structures, $structuresRecherche));
}
/**
* Retourne les étapes auxquelles appartient la personne
* Retourne les étapes auxquelles appartient l'étudiant
*
* @return StructureEntity[]|null
* @return mixed|StructureEntity[]|null
* @throws Exception
*/
public function getInscriptionEtape()
{
......@@ -501,9 +539,10 @@ class People extends BasePeople
}
/**
* Retourne les étapes auxquelles appartient la personne
* Retourne les éléments pédagogiques auxquels appartient l'étudiant
*
* @return StructureEntity[]|null
* @return mixed|StructureEntity[]|null
* @throws Exception
*/
public function getInscriptionElementPedagogique()
{
......@@ -540,15 +579,16 @@ class People extends BasePeople
preg_match(self::$inscription_pattern, $v, $matches);
$affect = $matches['affect'];
$etape = str_replace($this->getLabel('UAI', $this->service->getLdapRootService()->getEtablissementUAI()), '', $matches['etape']);
$replace = [$this->getLabel('SISE'), $this->getLabel('SUPANN'), $this->getLabel('INCONNU')];
return [
'etab' => str_replace($this->getLabel('UAI'), '', $matches['etab']),
'anneeinsc' => $matches['anneeinsc'],
'regimeinsc' => str_replace($this->getLabel('SISE'), '', $matches['regimeinsc']),
'sectdisc' => str_replace($this->getLabel('SISE'), '', $matches['sectdisc']),
'typedip' => str_replace($this->getLabel('SISE'), '', $matches['typedip']),
'cursusann' => str_replace($this->getLabel('SUPANN'), '', $matches['cursusann']),
'regimeinsc' => str_replace($replace, '', $matches['regimeinsc']),
'sectdisc' => str_replace($replace, '', $matches['sectdisc']),
'typedip' => str_replace($replace, '', $matches['typedip']),
'cursusann' => str_replace($replace, '', $matches['cursusann']),
'affect' => $this->service->getLdapStructureService()->get($affect) ?: $affect,
'diplome' => str_replace($this->getLabel('SISE'), '', $matches['diplome']),
'diplome' => str_replace($replace, '', $matches['diplome']),
'etape' => $this->service->getLdapStructureService()->get($etape) ?: $etape,
];
}, $value);
......@@ -557,24 +597,122 @@ class People extends BasePeople
}
/**
* Retourne true si l'argument est au format "supannRoleEntite".
* Retourne le complément des inscriptions d'un étudiant
*
* @return array
*/
public function getInscriptionComplement()
{
$value = $this->preFormat($this->ucbnEtuComplementInscription);
if (empty($value)) return null;
$value = array_map(function ($v) {
preg_match(self::$inscription_complement_pattern, $v, $matches);
$uaiLabel = $this->getLabel('UAI', $this->service->getLdapRootService()->getEtablissementUAI());
$etape = str_replace($uaiLabel, '', $matches['etape']);
return [
'anneeinsc' => $matches['anneeinsc'],
'etape' => $this->service->getLdapStructureService()->get($etape) ?: $etape,
'adistance' => str_replace($uaiLabel, '', $matches['adistance'])
];
}, $value);
return 1 == count($value) ? array_shift($value) : $value;
}