People.php 57.3 KB
Newer Older
1
2
3
4
5
6
<?php

namespace UnicaenLdap\Entity\Base;

use DateTime;
use UnicaenLdap\Entity\Entity;
7
8
use UnicaenLdap\Entity\People as PeopleEntity;
use UnicaenLdap\Entity\Structure as StructureEntity;
9
use UnicaenLdap\Exception;
10
use Zend\Ldap\Attribute;
11
use Zend\Ldap\Dn;
12
13
14
15
16
use Zend\Ldap\Exception\LdapException;

/**
 * Classe mère des entités de la branche "people" de l'annuaire LDAP.
 *
17
 * @author David Surville <david.surville@unicaen.fr>
18
19
20
 */
class People extends Entity
{
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    /**
     * Constantes pour les champs eduPersonAffiliation et eduPersonPrimaryAffiliation
     */
    const STATUS_AFFILIATE = 'affiliate';
    const STATUS_ALUM = 'alum';
    const STATUS_EMERITUS = 'emeritus';
    const STATUS_EMPLOYEE = 'employee';
    const STATUS_FACULTY = 'faculty';
    const STATUS_MEMBER = 'member';
    const STATUS_REGISTERED_READER = 'registered-reader';
    const STATUS_RESEARCHER = 'researcher';
    const STATUS_RETIRED = 'retired';
    const STATUS_STAFF = 'staff';
    const STATUS_STUDENT = 'student';
    const STATUS_TEACHER = 'teacher';

    /**
     * @var string
     */
40
41
42
    protected $type = 'People';

    /**
43
     * Liste des classes d'objet nécessaires à la création d'une entité "People"
44
45
46
47
48
49
50
51
52
53
54
55
     * Il est nécessaire d'ajouter la classe 'ucbnEtu' ou 'ucbnEmp' selon le
     * statut de la personne.
     *
     * @var array
     */
    protected $objectClass = [
        'top',
        'inetOrgPerson',
        'organizationalPerson',
        'person',
        'eduPerson',
        'supannPerson',
56
57
58
59
        'schacPersonalCharacteristics',
        'schacEntryMetadata',
        'ucbnEmp',
        'ucbnEtu',
60
        'posixAccount',
61
        'sambaAccount',
62
        'sambaSamAccount',
63
64
    ];

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    /**
     * Liste des attributs autorisés pour une entité "People"
     *
     * @var array
     */
    protected $authorizedAttributes = [
        // Attributes classes
        'objectClass',
        // Attributes
        'cn',
        'displayName',
        'dateDeNaissance',
        'eduPersonPrincipalName',
        'eduPersonNickname', // no getter and setter
        'eduPersonAffiliation',
        'eduPersonPrimaryAffiliation',
        'eduPersonOrgDN',
        'eduPersonOrgUnitDN',
        'eduPersonPrimaryOrgUnitDN',
        'dateFinInscription',
        'facsimileTelephoneNumber', // no getter and setter
        'gidNumber',
        'givenName',
        'homeDirectory',
        'labeledURI', // no getter and setter
        'leoCode',
        'loginShell',
        'mail',
        'mobile',
94
        'ntPassword',
95
96
97
98
        'pager',
        'postalAddress',
        'preferredLanguage',
        'rid',
99
        'sambaNTPassword',
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
        'sambaSID',
        'schacDateOfBirth',
        'schacExpiryDate',
        'sexe',
        'sn',
        'supannActivite',
        'supannAffectation',
        'supannAliasLogin',
        'supannAutreTelephone',
        'supannCivilite',
        'supannCodeINE',
        'supannEmpCorps',
        'supannEmpId',
        'supannEntiteAffectation',
        'supannEntiteAffectationPrincipale',
        'supannEtablissement',
        'supannEtuAnneeInscription',
        'supannEtuCursusAnnee',
        'supannEtuDiplome',
        'supannEtuElementPedagogique',
        'supannEtuEtape',
        'supannEtuId',
        'supannEtuInscription',
        'supannEtuRegimeInscription',
        'supannEtuSecteurDisciplinaire',
        'supannEtuTypeDiplome',
        'supannListeRouge',
        'supannMailPerso',
        'supannParrainDN',
        'supannRoleGenerique',
        'supannRoleEntite',
        'supannRefId',
        'supannTypeEntiteAffectation',
        'telephoneNumber',
        'title', // no getter and setter
        'ucbnAnneePostBac',
        'ucbnCodeEtape',
        'ucbnEtuComplementInscription',
        'ucbnFonctionStructurelle',
        'ucbnOrganisme',
        'ucbnPrivateAddress',
        'ucbnPrivateAddressBis',
        'ucbnSecteurDisciplinaire',
        'ucbnServiceADE',
        'ucbnServicePapercut',
        'ucbnSiteLocalisation',
        'ucbnSousStructure',
147
        'ucbnSquidHash',
148
149
        'ucbnStatus',
        'ucbnStructureRecherche',
150
        'uidNumber',
151
152
153
        'unicaenMonEtupass',
        'unicaenTermsOfUse',
        'userCertificate',
154
        'userPassword',
155
156
    ];

157
158
159
160
161
    /**
     * Liste des attributs contenant des dates
     *
     * @var array
     */
162
163
164
    protected $dateTimeAttributes = [
        'schacExpiryDate',
    ];
165

166
167
168
169
170
171
172
173
    /**
     * Liste des attributs monovalués
     *
     * @var array
     */
    protected $monoValuedAttributes = [
        'cn',
        'dateDeNaissance',
174
        'dateFinInscription',
175
176
        'displayName',
        'eduPersonOrgDN',
177
        'eduPersonPrimaryAffiliation',
178
179
        'eduPersonPrimaryOrgUnitDN',
        'eduPersonPrincipalName',
180
        'gidNumber',
181
        'givenName',
182
        'homeDirectory',
183
        'leoCode',
184
185
        'loginShell',
        'ntPassword',
186
        'preferredLanguage',
187
188
189
        'rid',
        'sambaNTPassword',
        'sambaSID',
190
        'schacDateOfBirth',
191
        'schacExpiryDate',
192
193
194
195
196
197
198
199
200
        'sexe',
        'supannAliasLogin',
        'supannCivilite',
        'supannCodeINE',
        'supannEmpId',
        'supannEntiteAffectationPrincipale',
        'supannEtuId',
        'supannListeRouge',
        'telephoneNumber',
201
        'ucbnSquidHash',
202
        'uidNumber',
203
        'userPassword',
204
205
    ];

206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
    /**
     * Liste des valeurs autorisées pour les attributs "eduPersonAffiliation" et "eduPersonPrimaryAffiliation"
     *
     * - affiliate : personne qui ne dépend pas de l'établissement (exemple : un partenaire extérieur). La valeur
     * "member" est exclue pour ces personnes.
     * - alum : ancien étudiant conservant des relations avec l'établissement.
     * - emeritus :  professeur ayant obtenu l'éméritat dans l'établissement.
     * - employee : tout personnel rémunéré par l'établissement, quelque soit son activité.
     * - faculty : personnel dont l'activité principale (dans l'établissement) est pédagogique, d'enseignement ou/et de
     * recherche. La valeur “member” est positionnée si ce personnel est géré par l'établissement.
     * - member : personne inscrite dans la (les) base(s) de gestion des étudiants ou celle(s) des personnels.
     * - registered-reader : lecteur de bibliothèque autorisé.
     * - researcher : personne assurant une activité de recherche. La valeur “member” est positionnée si ce personnel
     * est géré par l'établissement.
     * - retired :  personne à la retraite conservant des relations avec l'établissement.
     * - staff : personnel dont l'activité principale (dans l'établissement) est autre qu'enseignant ou chercheur
     * (typiquement BIATOS).
     * - student : personne suivant une formation quelconque dans l'établissement. Si la valeur “member” est positionnée,
     * la personne est enregistrée dans la base des étudiants.
     * - teacher : personnel assurant une activité d'enseignement.
     *
     * @var array
     */
    protected $eduPersonAffiliationAuthorizedValues = [
230
231
232
233
234
235
236
237
238
239
240
241
        self::STATUS_AFFILIATE,
        self::STATUS_ALUM,
        self::STATUS_EMERITUS,
        self::STATUS_EMPLOYEE,
        self::STATUS_FACULTY,
        self::STATUS_MEMBER,
        self::STATUS_REGISTERED_READER,
        self::STATUS_RESEARCHER,
        self::STATUS_RETIRED,
        self::STATUS_STAFF,
        self::STATUS_STUDENT,
        self::STATUS_TEACHER,
242
243
244
245
246
247
248
249
250
251
252
253
254
    ];

    /**
     * Liste des valeurs autorisées pour l'attribut "ucbnStatus"
     *
     * @var array
     */
    protected $ucbnStatusAuthorizedValues = [
        'ALUMNI',
        'APPRENANT',
        'AUDITEUR_LIBRE',
        'CONTRACTUEL',
        'ETUDIANT',
255
        'HEBERGE',
256
257
258
259
260
        'INVITE',
        'LECTEUR_SCD',
        'TITULAIRE',
    ];

261
262
    /**
     * Liste des patterns spécifiques utilisés pour différents attributs
263
     */
264
    static protected $structure_pattern = '/^(?<code>[\w\-]+);(?<libelle>.+)$/';
265
266
267
268
269
    static protected $localisation_pattern = '/^(?<code>[\w\-]+);(?<libelle>.+)$/';
    static protected $etape_pattern = '/^(?<code>.+);(?<libelle>.+)$/';
    static protected $secteur_disciplinaire_pattern = '/^(?<code>\d+);(?<libelle>.+)$/';
    static protected $inscription_pattern =
        '/^\[etab=(?<etab>\{[\w\-:]+\}.+)\]' .
270
271
272
273
274
275
276
277
        '\[anneeinsc=(?<anneeinsc>\d{4})\]' .
        '\[regimeinsc=(?<regimeinsc>\{[\w\-:]+\}\w*)\]' . // {SISE}.* ou {INCONNU}
        '\[sectdisc=(?<sectdisc>\{[\w\-:]+\}\w*)\]' . // {SISE}.* ou {INCONNU}
        '\[typedip=(?<typedip>\{[\w\-:]+\}\w*)\]' . // {SISE}.* ou {INCONNU}
        '\[cursusann=(?<cursusann>\{SUPANN\}\w+)\]' .
        '\[affect=(?<affect>[\w\-]+)\]' .
        '\[diplome=(?<diplome>\{[\w\-:]+\}\w+)\]' .
        '\[etape=(?<etape>\{[\w\-:]+\}.+)\]$/';
278
279
280
    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>.+)$/';
281

282
283
284
285
286
287
288
289
290

    /**
     * Attribut Ldap "sn"
     *
     * Nom d'un individu
     * Doit contenir le nom d'usage. Il est possible d'ajouter le nom de famille en seconde valeur.
     *
     * Multivalué
     *
291
     * @param array|string|null $value
292
293
     * @param bool $append
     * @return self
294
     * @throws Exception
295
296
     * @throws LdapException
     */
297
    public function setSn($value = null, $append = false)
298
    {
299
300
301
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('sn', $value, $append);
302
303
304
305
306
307
308

        return $this;
    }

    /**
     * Attribut Ldap "givenName"
     *
309
     * @param array|string|null $value
310
311
     * @param bool $append
     * @return self
312
     * @throws Exception
313
314
     * @throws LdapException
     */
315
    public function setGivenName($value = null, $append = false)
316
    {
317
318
319
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('givenName', $value, $append);
320
321
322
323
324
325
326

        return $this;
    }

    /**
     * Attribut Ldap "displayName"
     *
327
     * @param array|string|null $value
328
329
     * @param bool $append
     * @return self
330
     * @throws Exception
331
332
     * @throws LdapException
     */
333
    public function setDisplayName($value = null, $append = false)
334
    {
335
336
337
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('displayName', $value, $append);
338
339
340
341
342
343
344

        return $this;
    }

    /**
     * Attribut Ldap "cn"
     *
345
     * @param array|string|null $value
346
347
     * @param bool $append
     * @return self
348
     * @throws Exception
349
350
     * @throws LdapException
     */
351
    public function setCn($value = null, $append = false)
352
    {
353
354
355
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value, [true]);
        $this->appendOrNot('cn', $value, $append);
356
357
358
359
360
361
362

        return $this;
    }

    /**
     * Attribut Ldap "dateDeNaissance"
     *
363
     * @param array|string|DateTime|null $value
364
365
     * @param bool $append
     * @return self
366
     * @throws Exception
367
     * @throws LdapException
368
369
     * @deprecated Deprecated, use {@link self::setSchacDateOfBirth}
     *
370
     */
371
    public function setDateDeNaissance($value = null, $append = false)
372
    {
373
374
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
375
376
377
378
            if (is_string($val)) {
                $val = new DateTime($val);
            }
            return $val->format('Ymd');
379
        }, $value);
380

381
        $this->appendOrNot('dateDeNaissance', $value, $append);
382
383
384
385
386
387
388

        return $this;
    }

    /**
     * Attribut Ldap "schacDateOfBirth"
     *
389
     * @param array|string|DateTime|null $value
390
391
     * @param bool $append
     * @return self
392
     * @throws Exception
393
394
     * @throws LdapException
     */
395
    public function setSchacDateOfBirth($value = null, $append = false)
396
    {
397
398
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
399
400
401
402
            if (is_string($val)) {
                $val = new DateTime($val);
            }
            return $val->format('Ymd');
403
        }, $value);
404

405
        $this->appendOrNot('schacDateOfBirth', $value, $append);
406
407
408
409

        return $this;
    }

410
411
412
413
414
415
416
417
    /**
     * Attribut Ldap "dateFinInscription"
     *
     * @param array|string|DateTime|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
418
419
     * @deprecated Deprecated, use {@link self::setSchacExpiryDate}
     *
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
     */
    public function setDateFinInscription($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                $val = new DateTime($val);
            }
            return $val->format('Ymd');
        }, $value);

        $this->appendOrNot('dateFinInscription', $value, $append);

        return $this;
    }

    /**
     * Attribut Ldap "schacDateOfBirth"
     *
     * @param array|string|DateTime|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSchacExpiryDate($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                $val = new DateTime($val, new \DateTimeZone('+0000')); // définition du timezone à +0h
            }
            return (int)$val->format('U');
        }, $value);

        $this->appendOrNot('schacExpiryDate', $value, $append);

        return $this;
    }

460
461
462
    /**
     * Attribut Ldap "sexe"
     *
463
     * @param array|string|null $value
464
465
     * @param bool $append
     * @return self
466
     * @throws Exception
467
468
     * @throws LdapException
     */
469
    public function setSexe($value = null, $append = false)
470
    {
471
472
473
474
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['F', 'M']);
        });
475

476
        $this->appendOrNot('sexe', $value, $append);
477

478
        return $this;
479
480
    }

481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
    /**
     * Attribut Ldap "eduPersonAffiliation"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setEduPersonAffiliation($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, $this->eduPersonAffiliationAuthorizedValues);
        });

        $this->appendOrNot('eduPersonAffiliation', $value, $append);

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonPrimaryAffiliation"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setEduPersonPrimaryAffiliation($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, $this->eduPersonAffiliationAuthorizedValues);
        });

        $this->appendOrNot('eduPersonPrimaryAffiliation', $value, $append);

        return $this;
    }

523
524
525
    /**
     * Attribut Ldap "postalAddress"
     *
526
     * @param array|string|null $value
527
528
     * @param bool $append
     * @return self
529
     * @throws Exception
530
531
     * @throws LdapException
     */
532
    public function setPostalAddress($value = null, $append = false)
533
    {
534
535
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
536
            return preg_match(self::$postal_address_pattern, $v);
537
538
        });

539
        $this->appendOrNot('postalAddress', $value, $append);
540
541
542
543
544
545
546

        return $this;
    }

    /**
     * Attribut Ldap "telephoneNumber"
     *
547
     * @param array|string|null $value
548
549
     * @param bool $append
     * @return self
550
     * @throws Exception
551
552
     * @throws LdapException
     */
553
    public function setTelephoneNumber($value = null, $append = false)
554
    {
555
556
557
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatTel'], $value);
        $this->appendOrNot('telephoneNumber', $value, $append);
558
559
560
561
562
563
564

        return $this;
    }

    /**
     * Attribut Ldap "supannAutreTelephone"
     *
565
     * @param array|string|null $value
566
567
     * @param bool $append
     * @return self
568
     * @throws Exception
569
570
     * @throws LdapException
     */
571
    public function setSupannAutreTelephone($value = null, $append = false)
572
    {
573
574
575
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatTel'], $value);
        $this->appendOrNot('supannAutreTelephone', $value, $append);
576
577
578
579
580
581
582

        return $this;
    }

    /**
     * Attribut Ldap "mobile"
     *
583
     * @param array|string|null $value
584
585
     * @param bool $append
     * @return self
586
     * @throws Exception
587
588
     * @throws LdapException
     */
589
    public function setMobile($value = null, $append = false)
590
    {
591
592
593
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatTel'], $value);
        $this->appendOrNot('mobile', $value, $append);
594
595
596
597
598
599
600

        return $this;
    }

    /**
     * Attribut Ldap "preferredLanguage"
     *
601
     * @param array|string|null $value
602
603
     * @param bool $append
     * @return self
604
     * @throws Exception
605
606
     * @throws LdapException
     */
607
    public function setPreferredLanguage($value = null, $append = false)
608
    {
609
610
611
        $value = $this->preFormat($value);
        $value = array_map('strtolower', $value);
        $this->appendOrNot('preferredLanguage', $value, $append);
612
613
614
615
616
617
618

        return $this;
    }

    /**
     * Attribut Ldap "leoCode"
     *
619
     * @param array|string|null $value
620
621
     * @param bool $append
     * @return self
622
     * @throws Exception
623
624
     * @throws LdapException
     */
625
    public function setLeoCode($value = null, $append = false)
626
    {
627
628
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
629
            return preg_match('/^\d{13}$/', $v);
630
631
        });

632
        $this->appendOrNot('leoCode', $value, $append);
633
634
635
636
637
638
639

        return $this;
    }

    /**
     * Attribut Ldap "supannALiasLogin"
     *
640
     * @param array|string|null $value
641
642
     * @param bool $append
     * @return self
643
     * @throws Exception
644
645
     * @throws LdapException
     */
646
    public function setSupannAliasLogin($value = null, $append = false)
647
    {
648
649
650
        $value = $this->preFormat($value);
        $value = array_map('strtolower', $value);
        $value = array_filter($value, function ($v) {
651
652
653
            return preg_match('/^[0-9a-z\-]+$/', $v);
        });

654
        $this->appendOrNot('supannAliasLogin', $value, $append);
655
656
657
658
659
660
661

        return $this;
    }

    /**
     * Attribut Ldap "supannEmpId"
     *
662
     * @param array|string|null $value
663
664
     * @param bool $append
     * @return self
665
     * @throws Exception
666
667
     * @throws LdapException
     */
668
    public function setSupannEmpId($value = null, $append = false)
669
    {
670
671
672
673
        $value = $this->preFormat($value);
        $this->appendOrNot('supannEmpId', $value, $append);

        return $this;
674
675
676
677
678
    }

    /**
     * Attribut Ldap "supannEtuId"
     *
679
     * @param array|string|null $value
680
681
     * @param bool $append
     * @return self
682
     * @throws Exception
683
684
     * @throws LdapException
     */
685
    public function setSupannEtuId($value = null, $append = false)
686
    {
687
688
689
690
        $value = $this->preFormat($value);
        $this->appendOrNot('supannEtuId', $value, $append);

        return $this;
691
692
    }

693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
    /**
     * Attribut Ldap "supannEtuInscription"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEtuInscription($value = null, $append = false)
    {
        $value = $this->preFormat($value);

        $supannLabel = $this->getLabel('SUPANN');
        $siseLabel = $this->getLabel('SISE');
        $inconnuLabel = $this->getLabel('INCONNU');
        $value = array_map(function ($v) use ($supannLabel, $siseLabel, $inconnuLabel) {
            if (preg_match(self::$inscription_pattern, $v, $matches)) {
                /**
                 * @var string $etab
                 * @var string $anneeinsc
                 * @var string $regimeinsc
                 * @var string $sectdisc
                 * @var string $typedip
                 * @var string $cursusann
                 * @var string $affect
                 * @var string $diplome
                 * @var string $etape
                 */
                foreach (['regimeinsc', 'sectdisc', 'typedip'] as $part) {
                    $$part = preg_match("/^($siseLabel|$inconnuLabel)\w*$/", $matches[$part])
                        ? $matches[$part]
                        : sprintf('%s%s', $siseLabel, $matches[$part]);
                }
                foreach (['cursusann'] as $part) {
                    $$part = preg_match("/^$supannLabel\w+$/", $matches[$part])
                        ? $matches[$part]
                        : sprintf('%s%s', $supannLabel, $matches[$part]);
                }

                $prefixe = $this->getService()->getCodeStructurePrefixe();
                $affect = (0 !== strpos($matches['affect'], $prefixe))
                    ? sprintf('%s%s', $structure_prefixe, $matches['affect'])
                    : $matches['affect'];

                $prefixe = $this->getService()->getCodeModuleEnseignementPrefixe();
                preg_match('/^(?<etiquette>\{[\w\-:]+\})(?<identifiant>.+)$/', $matches['etape'], $parts);
                $val = (0 !== strpos($parts['identifiant'], $prefixe))
                    ? $prefixe . $parts['identifiant']
                    : $parts['identifiant'];
                $etape = sprintf('%s%s', $parts['etiquette'], $val);

                return preg_replace(
                    self::$inscription_pattern,
                    "[etab=\\1][anneeinsc=\\2][regimeinsc=$regimeinsc][sectdisc=$sectdisc][typedip=$typedip][cursusann=$cursusann][affect=$affect][diplome=\\8][etape=$etape]",
                    $v, 1);
            } else {
                return null;
            }

        }, $value);

        $this->appendOrNot('supannEtuInscription', array_filter($value), $append);

        return $this;
    }

760
761
762
    /**
     * Attribut Ldap "supannCodeINE"
     *
763
     * @param array|string|null $value
764
765
     * @param bool $append
     * @return self
766
     * @throws Exception
767
768
     * @throws LdapException
     */
769
    public function setSupannCodeINE($value = null, $append = false)
770
    {
771
772
773
        $value = $this->preFormat($value);
        $value = array_map('strtoupper', $value);
        $value = array_filter($value, function ($v) {
774
            return preg_match('/^[\w]{11}$/', $v);
775
776
        });

777
        $this->appendOrNot('supannCodeINE', $value, $append);
778
779
780
781
782
783
784

        return $this;
    }

    /**
     * Attribut Ldap "supannCivilite"
     *
785
     * @param array|string|null $value
786
787
     * @param bool $append
     * @return self
788
     * @throws Exception
789
790
     * @throws LdapException
     */
791
    public function setSupannCivilite($value = null, $append = false)
792
    {
793
794
795
796
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['Mme', 'M.']);
        });
797

798
        $this->appendOrNot('supannCivilite', $value, $append);
799

800
        return $this;
801
802
803
804
805
    }

    /**
     * Attribut Ldap "supannListeRouge"
     *
806
     * @param array|string|null $value
807
808
     * @param bool $append
     * @return self
809
     * @throws Exception
810
811
     * @throws LdapException
     */
812
    public function setSupannListeRouge($value = null, $append = false)
813
    {
814
815
816
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatBoolean'], $value);
        $this->appendOrNot('supannListeRouge', $value, $append);
817
818
819
820
821
822
823

        return $this;
    }

    /**
     * Attribut Ldap "supannMailPerso"
     *
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannMailPerso($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter(filter_var_array($value, FILTER_VALIDATE_EMAIL));
        $this->appendOrNot('supannMailPerso', $value, $append);

        return $this;
    }

    /**
     * Attribut Ldap "supannAffectation"
     *
842
     * @param array|string|StructureEntity|null $value
843
844
845
846
847
848
849
850
851
852
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannAffectation($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
853
854
855
856
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->getService()->getCodeStructurePrefixe(), ''), $val->get('description'));
                return preg_match(self::$structure_pattern, $val) ? $val : null;
857
858
859
860
861
            } else {
                return null;
            }
        }, $value);

862
        $this->appendOrNot('supannAffectation', array_filter($value), $append);
863
864
865
866
867
868
869

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectation"
     *
870
     * @param array|string|StructureEntity|null $value
871
872
     * @param bool $append
     * @return self
873
     * @throws Exception
874
875
     * @throws LdapException
     */
876
    public function setSupannEntiteAffectation($value = null, $append = false)
877
    {
878
879
880
881
882
883
884
        $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;
                }
                return $val;
885
            } elseif ($val instanceof StructureEntity) {
886
887
888
889
890
891
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

892
        $this->appendOrNot('supannEntiteAffectation', array_filter($value), $append);
893
894
895
896
897
898
899

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectationPrincipale"
     *
900
     * @param array|string|StructureEntity|null $value
901
902
903
904
905
906
907
908
909
910
911
912
913
914
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEntiteAffectationPrincipale($value = null, $append = false)
    {
        $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;
                }
                return $val;
915
            } elseif ($val instanceof StructureEntity) {
916
917
918
919
920
921
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

922
        $this->appendOrNot('supannEntiteAffectationPrincipale', array_filter($value), $append);
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938

        return $this;
    }

    /**
     * Attribut Ldap "supannTypeEntiteAffectation"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannTypeEntiteAffectation($value = null, $append = false)
    {
        $value = $this->preFormat($value);
939
940
        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($val) use ($supannLabel) {
941
            if (is_string($val)) {
942
                if (preg_match("/^" . $supannLabel . "[\w\-]+$/", $val)) {
943
                    return $val;
944
                } elseif (preg_match("/^[\w\-]+$/", $val)) {
945
946
                    return sprintf('%s%s', $supannLabel, $val);
                }
947
            }
948
            return null;
949
950
        }, $value);

951
        $this->appendOrNot('supannTypeEntiteAffectation', array_filter($value), $append);
952
953
954
955

        return $this;
    }

956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
    /**
     * Attribut Ldap "ucbnSiteLocalisation"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnSiteLocalisation($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$localisation_pattern, $v);
        });

        $this->appendOrNot('ucbnSiteLocalisation', $value, $append);

        return $this;
    }

977
978
979
    /**
     * Attribut Ldap "ucbnSousStructure"
     *
980
     * @param array|string|StructureEntity|null $value
981
982
983
984
985
986
987
988
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnSousStructure($value = null, $append = false)
    {
        $value = $this->preFormat($value);
989
990
991
992
993
994
995
996
997
998
        $value = array_map(function ($val) {
            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()->getCodeStructurePrefixe(), ''), $val->get('description'));
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);
999

1000
        $this->appendOrNot('ucbnSousStructure', array_filter($value), $append);
1001
1002
1003
1004
1005
1006
1007

        return $this;
    }

    /**
     * Attribut Ldap "ucbnStructureRecherche"
     *
1008
     * @param array|string|StructureEntity|null $value
1009
1010
1011
1012
1013
1014
1015
1016
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnStructureRecherche($value = null, $append = false)
    {
        $value = $this->preFormat($value);
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
        $value = array_map(function ($val) {
            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()->getCodeStructurePrefixe(), ''), $val->get('description'));
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);
1027

1028
        $this->appendOrNot('ucbnStructureRecherche', array_filter($value), $append);
1029
1030
1031
1032

        return $this;
    }

1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
    /**
     * Attribut Ldap "eduPersonPrincipalName"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setEduPersonPrincipalName($value = null, $append = false)
    {
        $value = $this->preFormat($value);
1045
1046
1047
        $value = array_map(function ($v) {
            list($identifiant, $domaine) = array_pad(explode('@', strtolower($v)), 2, null);
            if ($domaine != self::$etablissement_domaine) {
1048
1049
1050
1051
1052
                $v = sprintf('%s@%s', $v, self::$etablissement_domaine);
            }
            return $v;
        }, $value);
        $value = array_filter($value, function ($v) {
1053
            return preg_match('/^[0-9a-z\-]+@' . self::$etablissement_domaine . '$/', $v);
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
        });

        $this->appendOrNot('eduPersonPrincipalName', $value, $append);

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgDN"
     *
1064
     * @param array|string|Dn|StructureEntity|null $value
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setEduPersonOrgDN($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return Dn::checkDn($val) ? $val : null;
            } elseif ($val instanceof Dn) {
                return $val->toString();
1078
            } elseif ($val instanceof StructureEntity) {
1079
1080
1081
1082
1083
1084
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1085
        $this->appendOrNot('eduPersonOrgDN', array_filter($value), $append);
1086
1087
1088
1089
1090
1091
1092

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgUnitDN"
     *
1093
     * @param array|string|Dn|StructureEntity|null $value
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setEduPersonOrgUnitDN($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return Dn::checkDn($val) ? $val : null;
            } elseif ($val instanceof Dn) {
                return $val->toString();
1107
            } elseif ($val instanceof StructureEntity) {
1108
1109
1110
1111
1112
1113
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1114
        $this->appendOrNot('eduPersonOrgUnitDN', array_filter($value), $append);
1115
1116
1117
1118
1119
1120
1121

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonPrimaryOrgUnitDN"
     *
1122
     * @param array|string|Dn|StructureEntity|null $value
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setEduPersonPrimaryOrgUnitDN($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return Dn::checkDn($val) ? $val : null;
            } elseif ($val instanceof Dn) {
                return $val->toString();
1136
            } elseif ($val instanceof StructureEntity) {
1137
1138
1139
1140
1141
1142
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1143
        $this->appendOrNot('eduPersonPrimaryOrgUnitDN', array_filter($value), $append);
1144
1145
1146
1147

        return $this;
    }

1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
    /**
     * Attribut Ldap "supannRoleGenerique"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannRoleGenerique($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($val) use ($supannLabel) {
            if (is_string($val)) {
1163
                if (preg_match("/^" . $supannLabel . "[\w\-]+$/", $val)) {
1164
                    return $val;
1165
                } elseif (preg_match("/^[\w\-]+$/", $val)) {
1166
1167
                    return sprintf('%s%s', $supannLabel, $val);
                }
1168
            }
1169
            return null;
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
        }, $value);

        $this->appendOrNot('supannRoleGenerique', array_filter($value), $append);

        return $this;
    }

    /**
     * Attribut Ldap "supannRoleEntite"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannRoleEntite($value = null, $append = false)
    {
        $value = $this->preFormat($value);

        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($v) use ($supannLabel) {
1192
            if (preg_match(self::$role_pattern, $v, $matches)) {
1193
1194
1195
1196
1197
                /**
                 * @var string $role
                 * @var string $type
                 * @var string $code
                 */
1198
                foreach (['role', 'type'] as $part) {
1199
                    $$part = preg_match("/^" . $supannLabel . "[\w\-]+$/", $matches[$part])
1200
1201
1202
1203
1204
1205
1206
1207
                        ? $matches[$part]
                        : sprintf('%s%s', $supannLabel, $matches[$part]);
                }

                $prefixe = $this->getService()->getCodeStructurePrefixe();
                $code = (0 !== strpos($matches['code'], $prefixe))
                    ? sprintf('%s%s', $prefixe, $matches['code'])
                    : $matches['code'];
1208

1209
                return preg_replace(self::$role_pattern, "[role=$role][type=$type][code=$code][libelle=\\4]", $v, 1);
1210
            } else {
1211
                return null;
1212
1213
1214
1215
1216
1217
1218
1219
1220
            }

        }, $value);

        $this->appendOrNot('supannRoleEntite', array_filter($value), $append);

        return $this;
    }

1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
    /**
     * Attribut Ldap "ucbnAnneePostBac"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnAnneePostBac($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match('/^\d{1}$/', $v);
        });

        $this->appendOrNot('ucbnAnneePostBac', $value, $append);

        return $this;
    }

    /**
     * Attribut Ldap "ucbnCodeEtape"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnCodeEtape($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$etape_pattern, $v);
        });

        $this->appendOrNot('ucbnCodeEtape', $value, $append);

        return $this;
    }

    /**
     * Attribut Ldap "ucbnEtuComplementInscription"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnEtuComplementInscription($value = null, $append = false)
    {
        $value = $this->preFormat($value);

        $value = array_map(function ($v) {
            if (preg_match(self::$inscription_complement_pattern, $v, $matches)) {
                /**
                 * @var string $anneeinsc
                 * @var string $etape
                 * @var string $adistance
                 */
                $prefixe = $this->getService()->getCodeModuleEnseignementPrefixe();
                preg_match('/^(?<etiquette>\{[\w\-:]+\})(?<identifiant>.+)$/', $matches['etape'], $parts);
                $val = (0 !== strpos($parts['identifiant'], $prefixe))
                    ? $prefixe . $parts['identifiant']
                    : $parts['identifiant'];
                $etape = sprintf('%s%s', $parts['etiquette'], $val);

                return preg_replace(
                    self::$inscription_pattern,
                    "[anneeinsc=\\1][etape=$etape][adistance=\\3]",
                    $v, 1);
            } else {
                return null;
            }

        }, $value);

        $this->appendOrNot('ucbnEtuComplementInscription', array_filter($value), $append);

        return $this;
    }

1305
    /**
1306
     * Attribut Ldap "ucbnFonctionStructurelle"
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnFonctionStructurelle($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$role_src_pattern, $v);

        });

        $this->appendOrNot('ucbnFonctionStructurelle', $value, $append);

        return $this;
    }

1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
    /**
     * Attribut Ldap "ucbnPrivateAddress"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnPrivateAddress($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$postal_address_pattern, $v);
        });

        $this->appendOrNot('ucbnPrivateAddress', $value, $append);

        return $this;
    }

    /**
     * Attribut Ldap "ucbnPrivateAddressBis"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnPrivateAddressBis($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$postal_address_pattern, $v);
        });

        $this->appendOrNot('ucbnPrivateAddressBis', $value, $append);

        return $this;
    }

1369
1370
1371
    /**
     * Attribut Ldap "supannParrainDN"
     *
1372
     * @param array|string|Dn|PeopleEntity|null $value
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannParrainDN($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return Dn::checkDn($val) ? $val : null;
            } elseif ($val instanceof Dn) {
                return $val->toString();
1386
            } elseif ($val instanceof PeopleEntity) {
1387
1388
1389
1390
1391
1392
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1393
        $this->appendOrNot('supannParrainDN', array_filter($value), $append);
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410

        return $this;
    }

    /**
     * Attribut Ldap "supannRefId"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannRefId($value = null, $append = false)
    {
        $value = $this->preFormat($value);