Commit 72b11547 authored by David Surville's avatar David Surville
Browse files

[Evolution] Développement UnicaenLdap WIP

parent bce4412f
......@@ -84,7 +84,7 @@ class Group extends Entity
{
return sprintf('uid=%s,%s',
self::MEMBER_NOBODY,
$this->getService()->getLdapSystemService()->getBranches()[0]
$this->service->getLdapSystemService()->getBranches()[0]
);
}
......
......@@ -730,12 +730,12 @@ class People extends Entity
: sprintf('%s%s', $supannLabel, $matches[$part]);
}
$prefixe = $this->getService()->getLdapStructureService()->getCodeStructurePrefixe();
$prefixe = $this->service->getLdapStructureService()->getCodeStructurePrefixe();
$affect = (0 !== strpos($matches['affect'], $prefixe))
? sprintf('%s%s', $structure_prefixe, $matches['affect'])
: $matches['affect'];
$prefixe = $this->getService()->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
$prefixe = $this->service->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
preg_match('/^(?<etiquette>\{[\w\-:]+\})(?<identifiant>.+)$/', $matches['etape'], $parts);
$val = (0 !== strpos($parts['identifiant'], $prefixe))
? $prefixe . $parts['identifiant']
......@@ -852,7 +852,7 @@ class People extends Entity
if (is_string($val)) {
return preg_match(self::$structure_pattern, $val) ? $val : null;
} elseif ($val instanceof StructureEntity) {
$val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->getService()->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
$val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->service->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
return preg_match(self::$structure_pattern, $val) ? $val : null;
} else {
return null;
......@@ -878,8 +878,8 @@ class People extends Entity
$value = $this->preFormat($value);
$value = array_map(function ($val) {
if (is_string($val)) {
if (0 !== strpos($val, $this->getService()->getLdapStructureService()->getCodeStructurePrefixe())) {
$val = $this->getService()->getLdapStructureService()->getCodeStructurePrefixe() . $val;
if (0 !== strpos($val, $this->service->getLdapStructureService()->getCodeStructurePrefixe())) {
$val = $this->service->getLdapStructureService()->getCodeStructurePrefixe() . $val;
}
return $val;
} elseif ($val instanceof StructureEntity) {
......@@ -908,8 +908,8 @@ class People extends Entity
$value = $this->preFormat($value);
$value = array_map(function ($val) {
if (is_string($val)) {
if (0 !== strpos($val, $this->getService()->getLdapStructureService()->getCodeStructurePrefixe())) {
$val = $this->getService()->getLdapStructureService()->getCodeStructurePrefixe() . $val;
if (0 !== strpos($val, $this->service->getLdapStructureService()->getCodeStructurePrefixe())) {
$val = $this->service->getLdapStructureService()->getCodeStructurePrefixe() . $val;
}
return $val;
} elseif ($val instanceof StructureEntity) {
......@@ -990,7 +990,7 @@ class People extends Entity
if (is_string($val)) {
return preg_match(self::$structure_pattern, $val) ? $val : null;
} elseif ($val instanceof StructureEntity) {
$val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->getService()->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
$val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->service->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
return preg_match(self::$structure_pattern, $val) ? $val : null;
} else {
return null;
......@@ -1018,7 +1018,7 @@ class People extends Entity
if (is_string($val)) {
return preg_match(self::$structure_pattern, $val) ? $val : null;
} elseif ($val instanceof StructureEntity) {
$val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->getService()->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
$val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->service->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
return preg_match(self::$structure_pattern, $val) ? $val : null;
} else {
return null;
......@@ -1041,7 +1041,7 @@ class People extends Entity
*/
public function setEduPersonPrincipalName($value = null, $append = false)
{
$universiteDomaine = $this->getService()->getLdapRootService()->getEtablissementDomain();
$universiteDomaine = $this->service->getLdapRootService()->getEtablissementDomain();
$value = $this->preFormat($value);
$value = array_map(function ($v) use ($universiteDomaine) {
list($identifiant, $domaine) = array_pad(explode('@', strtolower($v)), 2, null);
......@@ -1202,7 +1202,7 @@ class People extends Entity
: sprintf('%s%s', $supannLabel, $matches[$part]);
}
$prefixe = $this->getService()->getLdapStructureService()->getCodeStructurePrefixe();
$prefixe = $this->service->getLdapStructureService()->getCodeStructurePrefixe();
$code = (0 !== strpos($matches['code'], $prefixe))
? sprintf('%s%s', $prefixe, $matches['code'])
: $matches['code'];
......@@ -1281,7 +1281,7 @@ class People extends Entity
* @var string $etape
* @var string $adistance
*/
$prefixe = $this->getService()->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
$prefixe = $this->service->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
preg_match('/^(?<etiquette>\{[\w\-:]+\})(?<identifiant>.+)$/', $matches['etape'], $parts);
$val = (0 !== strpos($parts['identifiant'], $prefixe))
? $prefixe . $parts['identifiant']
......@@ -1653,7 +1653,7 @@ class People extends Entity
$value = array_map(function ($val) {
if (is_string($val)) {
if (preg_match(self::$attribute_with_label_pattern, $val, $matches)) {
$prefixe = $this->getService()->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
$prefixe = $this->service->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
$val = (0 !== strpos($matches['identifiant'], $prefixe))
? $prefixe . $matches['identifiant']
: $matches['identifiant'];
......@@ -1684,7 +1684,7 @@ class People extends Entity
$value = array_map(function ($val) {
if (is_string($val)) {
if (preg_match(self::$attribute_with_label_pattern, $val, $matches)) {
$prefixe = $this->getService()->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
$prefixe = $this->service->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
$val = (0 !== strpos($matches['identifiant'], $prefixe))
? $prefixe . $matches['identifiant']
: $matches['identifiant'];
......
......@@ -110,8 +110,8 @@ class Structure extends Entity
$value = $this->preFormat($value);
$value = array_map(function ($val) {
if (is_string($val)) {
if (0 !== strpos($val, $this->getService()->getCodeStructurePrefixe())) {
$val = $this->getService()->getCodeStructurePrefixe() . $val;
if (0 !== strpos($val, $this->service->getCodeStructurePrefixe())) {
$val = $this->service->getCodeStructurePrefixe() . $val;
}
return $val;
} elseif ($val instanceof StructureEntity) {
......
......@@ -48,7 +48,7 @@ class Group extends BaseGroup
*/
public function getMembres($orderBy = null)
{
$peopleService = $this->getService()->getLdapPeopleService();
$peopleService = $this->service->getLdapPeopleService();
$result = $peopleService->getAllBy($this->member, 'dn', $orderBy);
return $result;
......
......@@ -5,7 +5,9 @@ namespace UnicaenLdap\Entity;
use DateTime;
use UnicaenLdap\Entity\Base\People as BasePeople;
use UnicaenLdap\Entity\Structure as StructureEntity;
use UnicaenLdap\Entity\System as SystemEntity;
use UnicaenLdap\Exception;
use Zend\Ldap\Dn;
/**
* Classe de gestion des entités de la branche "people" de l'annuaire LDAP.
......@@ -135,6 +137,28 @@ class People extends BasePeople
return DateTime::createFromFormat('Ymd h:i:s', $this->schacExpiryDate . ' 00:00:00');
}
/**
* Retourne le responsable de l'entrée Ldap
*
* @return People|SystemEntity|string|null
* @throws Exception
* @throws \Zend\Ldap\Exception\LdapException
*/
public function getParrain()
{
$systemService = $this->service->getLdapSystemService();
$node = $this->service->getLdap()->getNode($this->supannParrainDN);
$branch = $node->getDn()->get(1);
switch($branch['ou']) {
case strtolower($this->service->getType()):
return $this->service->getBy($node->getDnString(), 'dn');
case strtolower($systemService->getType()):
return $systemService->getBy($node->getDnString(), 'dn');
default:
return $this->supannParrainDN;
}
}
/**
* Retourne l'adresse postale professionnelle
*
......@@ -281,30 +305,6 @@ class People extends BasePeople
return $this->whichStatus(parent::STATUS_TEACHER);
}
/**
* Établissement auquel appartient la personne
*
* @return StructureEntity|null
*/
public function getEtablissement()
{
$rootService = $this->getService()->getLdapRootService();
$structureService = $this->getService()->getLdapStructureService();
$dn = $this->eduPersonOrgDN;
if (empty($dn)) return null;
switch($dn) {
case $rootService->getEtablissementDN():
return $rootService->getStructureEntity();
default:
try {
return $structureService->getBy($dn, 'dn');
} catch (Exception $e) {
return null;
}
}
}
/**
* Retourne le léocode associé à l'individu
*
......@@ -383,21 +383,27 @@ class People extends BasePeople
}
/**
* Modifie l'ensemble des attributs liés au mot de passe
* Établissement auquel appartient la personne
*
* @param string $value
* @return $this
* @throws \UnicaenLdap\Exception
* @throws \Zend\Ldap\Exception\LdapException
* @return StructureEntity|null
*/
public function setPassword(string $value)
public function getEtablissement()
{
parent::setUserPassword($value);
parent::setNtPassword($value);
parent::setSambaNTPassword($value);
parent::setUcbnSquidHash($value);
$rootService = $this->service->getLdapRootService();
$structureService = $this->service->getLdapStructureService();
$dn = $this->eduPersonOrgDN;
return $this;
if (empty($dn)) return null;
switch($dn) {
case $rootService->getEtablissementDN():
return $rootService->getStructureEntity();
default:
try {
return $structureService->getBy($dn, 'dn');
} catch (Exception $e) {
return null;
}
}
}
/**
......@@ -407,7 +413,7 @@ class People extends BasePeople
*/
public function getStructure()
{
$structureService = $this->getService()->getLdapStructureService();
$structureService = $this->service->getLdapStructureService();
$value = $this->eduPersonOrgUnitDN;
if (empty($value)) return null;
......@@ -422,7 +428,7 @@ class People extends BasePeople
*/
public function getStructurePrincipale()
{
$structureService = $this->getService()->getLdapStructureService();
$structureService = $this->service->getLdapStructureService();
$value = $this->eduPersonPrimaryOrgUnitDN;
if (empty($value)) return null;
......@@ -433,6 +439,41 @@ class People extends BasePeople
}
}
/**
* Vérifie l'appartenance d'une personne à une structure
*
* @param string|Dn|StructureEntity $value
* @return bool
* @throws Exception
* @throws \Zend\Ldap\Exception\LdapException
*/
public function isInStructure($value)
{
$structureService = $this->service->getLdapStructureService();
$structurePrefixe = $structureService->getCodeStructurePrefixe();
if (is_string($value)) {
if(Dn::checkDn($value)) {
$value = $structureService->getBy($value, 'dn');
}
else {
if (0 !== strpos($value, $structurePrefixe)) {
$value = $structurePrefixe . $value;
}
$value = $structureService->get($value);
}
} elseif ($value instanceof Dn) {
$value = $structureService->getBy($value->toString(), 'dn');
}
if(!$value instanceof StructureEntity) {
return false;
}
$structures = $this->preFormat($this->supannEntiteAffectation);
return in_array($value->getId(), $structures);
}
/**
* Retourne les étapes auxquelles appartient la personne
*
......@@ -443,8 +484,8 @@ class People extends BasePeople
$value = $this->preFormat($this->supannEtuEtape);
if (empty($value)) return null;
$label = $this->getLabel('UAI', $this->getService()->getLdapRootService()->getEtablissementUAI());
$structureService = $this->getService()->getLdapStructureService();
$label = $this->getLabel('UAI', $this->service->getLdapRootService()->getEtablissementUAI());
$structureService = $this->service->getLdapStructureService();
list($structureKey) = Entity::getNodeParams($structureService->getType());
$structureBranch = $structureService->getBranches()[0];
$value = array_map(function ($v) use ($label, $structureKey, $structureBranch) {
......@@ -469,8 +510,8 @@ class People extends BasePeople
$value = $this->preFormat($this->supannEtuElementPedagogique);
if (empty($value)) return null;
$label = $this->getLabel('UAI', $this->getService()->getLdapRootService()->getEtablissementUAI());
$structureService = $this->getService()->getLdapStructureService();
$label = $this->getLabel('UAI', $this->service->getLdapRootService()->getEtablissementUAI());
$structureService = $this->service->getLdapStructureService();
list($structureKey) = Entity::getNodeParams($structureService->getType());
$structureBranch = $structureService->getBranches()[0];
$value = array_map(function ($v) use ($label, $structureKey, $structureBranch) {
......@@ -485,6 +526,36 @@ class People extends BasePeople
return 1 == count($value) ? array_shift($value) : $value;
}
/**
* Retourne les inscriptions complètes d'un étudiant
*
* @return array
*/
public function getInscription()
{
$value = $this->preFormat($this->supannEtuInscription);
if (empty($value)) return null;
$value = array_map(function ($v) {
preg_match(self::$inscription_pattern, $v, $matches);
$affect = $matches['affect'];
$etape = str_replace($this->getLabel('UAI', $this->service->getLdapRootService()->getEtablissementUAI()), '', $matches['etape']);
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']),
'affect' => $this->service->getLdapStructureService()->get($affect) ?: $affect,
'diplome' => str_replace($this->getLabel('SISE'), '', $matches['diplome']),
'etape' => $this->service->getLdapStructureService()->get($etape) ?: $etape,
];
}, $value);
return 1 == count($value) ? array_shift($value) : $value;
}
/**
* Retourne true si l'argument est au format "supannRoleEntite".
*
......@@ -504,4 +575,22 @@ class People extends BasePeople
return false;
}
/**
* Modifie l'ensemble des attributs liés au mot de passe
*
* @param string $value
* @return $this
* @throws \UnicaenLdap\Exception
* @throws \Zend\Ldap\Exception\LdapException
*/
public function setPassword(string $value)
{
parent::setUserPassword($value);
parent::setNtPassword($value);
parent::setSambaNTPassword($value);
parent::setUcbnSquidHash($value);
return $this;
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ class Structure extends BaseStructure
public function getParents()
{
if (null !== ($parentIds = $this->get('supannCodeEntiteParent'))) {
return $this->getService()->getAll($parentIds);
return $this->service->getAll($parentIds);
}
return null;
......@@ -46,7 +46,7 @@ class Structure extends BaseStructure
$filter = Filter::andFilter($childrenFilter, $filter);
}
return $this->getService()->search($filter, $orderBy, -1, 0);
return $this->service->search($filter, $orderBy, -1, 0);
}
/**
......@@ -60,8 +60,8 @@ class Structure extends BaseStructure
{
$code = $this->getId();
return (
0 === strpos($code, $this->getService()->getCodeStructurePrefixe()) ||
0 === strpos($code, $this->getService()->getCodeModuleEnseignementPrefixe()))
0 === strpos($code, $this->service->getCodeStructurePrefixe()) ||
0 === strpos($code, $this->service->getCodeModuleEnseignementPrefixe()))
? substr($code, 3)
: $code;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment