People.php 58.6 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
    /**
     * Liste des attributs autorisés pour une entité "People"
     *
     * @var array
     */
    protected $authorizedAttributes = [
        // Attributes classes
        'objectClass',
        // Attributes
        'cn',
        'dateDeNaissance',
76
77
        'dateFinInscription',
        'displayName',
78
        'eduPersonAffiliation',
79
        'eduPersonNickname',
80
81
        'eduPersonOrgDN',
        'eduPersonOrgUnitDN',
82
        'eduPersonPrimaryAffiliation',
83
        'eduPersonPrimaryOrgUnitDN',
84
85
        'eduPersonPrincipalName',
        'facsimileTelephoneNumber',
86
87
88
        'gidNumber',
        'givenName',
        'homeDirectory',
89
        'labeledURI',
90
91
92
93
        '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
        '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',
134
        'title',
135
136
137
138
139
140
141
142
143
144
145
146
        '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
202
        'ucbnServiceADE',
        'ucbnServicePapercut',
203
        'ucbnSquidHash',
204
        'uidNumber',
205
        'userPassword',
206
207
    ];

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
    /**
     * 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 = [
232
233
234
235
236
237
238
239
240
241
242
243
        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,
244
245
246
247
248
249
250
251
252
253
254
255
256
    ];

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

263
264
    /**
     * Liste des patterns spécifiques utilisés pour différents attributs
265
     */
266
    static protected $structure_pattern = '/^(?<code>[\w\-]+);(?<libelle>.+)$/';
267
268
269
270
271
    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\-:]+\}.+)\]' .
272
273
274
275
276
277
278
279
        '\[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\-:]+\}.+)\]$/';
280
281
282
283
284
285
286
287
288
    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>.+)\]$/';
289
    static protected $role_src_pattern = '/^(?<code>\d{4});(?<libelle>.+)$/';
290

291
292
293
294
295
296
297
298
299

    /**
     * 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é
     *
300
     * @param array|string|null $value
301
302
     * @param bool $append
     * @return self
303
     * @throws Exception
304
305
     * @throws LdapException
     */
306
    public function setSn($value = null, $append = false)
307
    {
308
309
310
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('sn', $value, $append);
311
312
313
314
315
316
317

        return $this;
    }

    /**
     * Attribut Ldap "givenName"
     *
318
     * @param array|string|null $value
319
320
     * @param bool $append
     * @return self
321
     * @throws Exception
322
323
     * @throws LdapException
     */
324
    public function setGivenName($value = null, $append = false)
325
    {
326
327
328
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('givenName', $value, $append);
329
330
331
332
333
334
335

        return $this;
    }

    /**
     * Attribut Ldap "displayName"
     *
336
     * @param array|string|null $value
337
338
     * @param bool $append
     * @return self
339
     * @throws Exception
340
341
     * @throws LdapException
     */
342
    public function setDisplayName($value = null, $append = false)
343
    {
344
345
346
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('displayName', $value, $append);
347
348
349
350
351
352
353

        return $this;
    }

    /**
     * Attribut Ldap "cn"
     *
354
     * @param array|string|null $value
355
356
     * @param bool $append
     * @return self
357
     * @throws Exception
358
359
     * @throws LdapException
     */
360
    public function setCn($value = null, $append = false)
361
    {
362
363
364
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value, [true]);
        $this->appendOrNot('cn', $value, $append);
365
366
367
368
369
370
371

        return $this;
    }

    /**
     * Attribut Ldap "dateDeNaissance"
     *
372
     * @param array|string|DateTime|null $value
373
374
     * @param bool $append
     * @return self
375
     * @throws Exception
376
     * @throws LdapException
377
378
     * @deprecated Deprecated, use {@link self::setSchacDateOfBirth}
     *
379
     */
380
    public function setDateDeNaissance($value = null, $append = false)
381
    {
382
383
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
384
385
386
387
            if (is_string($val)) {
                $val = new DateTime($val);
            }
            return $val->format('Ymd');
388
        }, $value);
389

390
        $this->appendOrNot('dateDeNaissance', $value, $append);
391
392
393
394
395
396
397

        return $this;
    }

    /**
     * Attribut Ldap "schacDateOfBirth"
     *
398
     * @param array|string|DateTime|null $value
399
400
     * @param bool $append
     * @return self
401
     * @throws Exception
402
403
     * @throws LdapException
     */
404
    public function setSchacDateOfBirth($value = null, $append = false)
405
    {
406
407
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
408
409
410
411
            if (is_string($val)) {
                $val = new DateTime($val);
            }
            return $val->format('Ymd');
412
        }, $value);
413

414
        $this->appendOrNot('schacDateOfBirth', $value, $append);
415
416
417
418

        return $this;
    }

419
420
421
422
423
424
425
426
    /**
     * Attribut Ldap "dateFinInscription"
     *
     * @param array|string|DateTime|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
427
428
     * @deprecated Deprecated, use {@link self::setSchacExpiryDate}
     *
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
460
461
462
463
464
465
466
467
468
     */
    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;
    }

469
470
471
    /**
     * Attribut Ldap "sexe"
     *
472
     * @param array|string|null $value
473
474
     * @param bool $append
     * @return self
475
     * @throws Exception
476
477
     * @throws LdapException
     */
478
    public function setSexe($value = null, $append = false)
479
    {
480
481
482
483
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['F', 'M']);
        });
484

485
        $this->appendOrNot('sexe', $value, $append);
486

487
        return $this;
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
523
524
525
526
527
528
529
530
531
    /**
     * 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;
    }

532
533
534
    /**
     * Attribut Ldap "postalAddress"
     *
535
     * @param array|string|null $value
536
537
     * @param bool $append
     * @return self
538
     * @throws Exception
539
540
     * @throws LdapException
     */
541
    public function setPostalAddress($value = null, $append = false)
542
    {
543
544
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
545
            return preg_match(self::$postal_address_pattern, $v);
546
547
        });

548
        $this->appendOrNot('postalAddress', $value, $append);
549
550
551
552
553
554
555

        return $this;
    }

    /**
     * Attribut Ldap "telephoneNumber"
     *
556
     * @param array|string|null $value
557
558
     * @param bool $append
     * @return self
559
     * @throws Exception
560
561
     * @throws LdapException
     */
562
    public function setTelephoneNumber($value = null, $append = false)
563
    {
564
565
566
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatTel'], $value);
        $this->appendOrNot('telephoneNumber', $value, $append);
567
568
569
570
571
572
573

        return $this;
    }

    /**
     * Attribut Ldap "supannAutreTelephone"
     *
574
     * @param array|string|null $value
575
576
     * @param bool $append
     * @return self
577
     * @throws Exception
578
579
     * @throws LdapException
     */
580
    public function setSupannAutreTelephone($value = null, $append = false)
581
    {
582
583
584
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatTel'], $value);
        $this->appendOrNot('supannAutreTelephone', $value, $append);
585
586
587
588

        return $this;
    }

589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
    /**
     * 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;
    }

607
608
609
    /**
     * Attribut Ldap "mobile"
     *
610
     * @param array|string|null $value
611
612
     * @param bool $append
     * @return self
613
     * @throws Exception
614
615
     * @throws LdapException
     */
616
    public function setMobile($value = null, $append = false)
617
    {
618
619
620
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatTel'], $value);
        $this->appendOrNot('mobile', $value, $append);
621
622
623
624

        return $this;
    }

625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
    /**
     * 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;
    }

643
644
645
    /**
     * Attribut Ldap "preferredLanguage"
     *
646
     * @param array|string|null $value
647
648
     * @param bool $append
     * @return self
649
     * @throws Exception
650
651
     * @throws LdapException
     */
652
    public function setPreferredLanguage($value = null, $append = false)
653
    {
654
655
656
        $value = $this->preFormat($value);
        $value = array_map('strtolower', $value);
        $this->appendOrNot('preferredLanguage', $value, $append);
657
658
659
660
661
662
663

        return $this;
    }

    /**
     * Attribut Ldap "leoCode"
     *
664
     * @param array|string|null $value
665
666
     * @param bool $append
     * @return self
667
     * @throws Exception
668
669
     * @throws LdapException
     */
670
    public function setLeoCode($value = null, $append = false)
671
    {
672
673
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
674
            return preg_match('/^\d{13}$/', $v);
675
676
        });

677
        $this->appendOrNot('leoCode', $value, $append);
678
679
680
681
682
683
684

        return $this;
    }

    /**
     * Attribut Ldap "supannALiasLogin"
     *
685
     * @param array|string|null $value
686
687
     * @param bool $append
     * @return self
688
     * @throws Exception
689
690
     * @throws LdapException
     */
691
    public function setSupannAliasLogin($value = null, $append = false)
692
    {
693
694
695
        $value = $this->preFormat($value);
        $value = array_map('strtolower', $value);
        $value = array_filter($value, function ($v) {
696
697
698
            return preg_match('/^[0-9a-z\-]+$/', $v);
        });

699
        $this->appendOrNot('supannAliasLogin', $value, $append);
700
701
702
703
704
705
706

        return $this;
    }

    /**
     * Attribut Ldap "supannEmpId"
     *
707
     * @param array|string|null $value
708
709
     * @param bool $append
     * @return self
710
     * @throws Exception
711
712
     * @throws LdapException
     */
713
    public function setSupannEmpId($value = null, $append = false)
714
    {
715
716
717
718
        $value = $this->preFormat($value);
        $this->appendOrNot('supannEmpId', $value, $append);

        return $this;
719
720
721
722
723
    }

    /**
     * Attribut Ldap "supannEtuId"
     *
724
     * @param array|string|null $value
725
726
     * @param bool $append
     * @return self
727
     * @throws Exception
728
729
     * @throws LdapException
     */
730
    public function setSupannEtuId($value = null, $append = false)
731
    {
732
733
734
735
        $value = $this->preFormat($value);
        $this->appendOrNot('supannEtuId', $value, $append);

        return $this;
736
737
    }

738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
    /**
     * 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]);
                }

778
                $prefixe = $this->service->getLdapStructureService()->getCodeStructurePrefixe();
779
780
781
782
                $affect = (0 !== strpos($matches['affect'], $prefixe))
                    ? sprintf('%s%s', $structure_prefixe, $matches['affect'])
                    : $matches['affect'];

783
                $prefixe = $this->service->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
                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;
    }

805
806
807
    /**
     * Attribut Ldap "supannCodeINE"
     *
808
     * @param array|string|null $value
809
810
     * @param bool $append
     * @return self
811
     * @throws Exception
812
813
     * @throws LdapException
     */
814
    public function setSupannCodeINE($value = null, $append = false)
815
    {
816
817
818
        $value = $this->preFormat($value);
        $value = array_map('strtoupper', $value);
        $value = array_filter($value, function ($v) {
819
            return preg_match('/^[\w]{11}$/', $v);
820
821
        });

822
        $this->appendOrNot('supannCodeINE', $value, $append);
823
824
825
826
827
828
829

        return $this;
    }

    /**
     * Attribut Ldap "supannCivilite"
     *
830
     * @param array|string|null $value
831
832
     * @param bool $append
     * @return self
833
     * @throws Exception
834
835
     * @throws LdapException
     */
836
    public function setSupannCivilite($value = null, $append = false)
837
    {
838
839
840
841
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['Mme', 'M.']);
        });
842

843
        $this->appendOrNot('supannCivilite', $value, $append);
844

845
        return $this;
846
847
848
849
850
    }

    /**
     * Attribut Ldap "supannListeRouge"
     *
851
     * @param array|string|null $value
852
853
     * @param bool $append
     * @return self
854
     * @throws Exception
855
856
     * @throws LdapException
     */
857
    public function setSupannListeRouge($value = null, $append = false)
858
    {
859
860
861
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatBoolean'], $value);
        $this->appendOrNot('supannListeRouge', $value, $append);
862
863
864
865
866
867
868

        return $this;
    }

    /**
     * Attribut Ldap "supannMailPerso"
     *
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
     * @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"
     *
887
     * @param array|string|StructureEntity|null $value
888
889
890
891
892
893
894
895
896
897
     * @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)) {
898
899
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
900
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->service->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
901
                return preg_match(self::$structure_pattern, $val) ? $val : null;
902
903
904
905
906
            } else {
                return null;
            }
        }, $value);

907
        $this->appendOrNot('supannAffectation', array_filter($value), $append);
908
909
910
911
912
913
914

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectation"
     *
915
     * @param array|string|StructureEntity|null $value
916
917
     * @param bool $append
     * @return self
918
     * @throws Exception
919
920
     * @throws LdapException
     */
921
    public function setSupannEntiteAffectation($value = null, $append = false)
922
    {
923
924
925
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
926
927
                if (0 !== strpos($val, $this->service->getLdapStructureService()->getCodeStructurePrefixe())) {
                    $val = $this->service->getLdapStructureService()->getCodeStructurePrefixe() . $val;
928
929
                }
                return $val;
930
            } elseif ($val instanceof StructureEntity) {
931
932
933
934
935
936
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

937
        $this->appendOrNot('supannEntiteAffectation', array_filter($value), $append);
938
939
940
941
942
943
944

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectationPrincipale"
     *
945
     * @param array|string|StructureEntity|null $value
946
947
948
949
950
951
952
953
954
955
     * @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)) {
956
957
                if (0 !== strpos($val, $this->service->getLdapStructureService()->getCodeStructurePrefixe())) {
                    $val = $this->service->getLdapStructureService()->getCodeStructurePrefixe() . $val;
958
959
                }
                return $val;
960
            } elseif ($val instanceof StructureEntity) {
961
962
963
964
965
966
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

967
        $this->appendOrNot('supannEntiteAffectationPrincipale', array_filter($value), $append);
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983

        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);
984
985
        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($val) use ($supannLabel) {
986
            if (is_string($val)) {
987
                if (preg_match("/^" . $supannLabel . "[\w\-]+$/", $val)) {
988
                    return $val;
989
                } elseif (preg_match("/^[\w\-]+$/", $val)) {
990
991
                    return sprintf('%s%s', $supannLabel, $val);
                }
992
            }
993
            return null;
994
995
        }, $value);

996
        $this->appendOrNot('supannTypeEntiteAffectation', array_filter($value), $append);
997
998
999
1000

        return $this;
    }

1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
    /**
     * 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;
    }

1022
1023
1024
    /**
     * Attribut Ldap "ucbnSousStructure"
     *
1025
     * @param array|string|StructureEntity|null $value
1026
1027
1028
1029
1030
1031
1032
1033
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnSousStructure($value = null, $append = false)
    {
        $value = $this->preFormat($value);
1034
1035
1036
1037
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
1038
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->service->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
1039
1040
1041
1042
1043
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);
1044

1045
        $this->appendOrNot('ucbnSousStructure', array_filter($value), $append);
1046
1047
1048
1049
1050
1051
1052

        return $this;
    }

    /**
     * Attribut Ldap "ucbnStructureRecherche"
     *
1053
     * @param array|string|StructureEntity|null $value
1054
1055
1056
1057
1058
1059
1060
1061
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnStructureRecherche($value = null, $append = false)
    {
        $value = $this->preFormat($value);
1062
1063
1064
1065
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
1066
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->service->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
1067
1068
1069
1070
1071
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);
1072

1073
        $this->appendOrNot('ucbnStructureRecherche', array_filter($value), $append);
1074
1075
1076
1077

        return $this;
    }

1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
    /**
     * Attribut Ldap "eduPersonPrincipalName"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setEduPersonPrincipalName($value = null, $append = false)
    {
1089
        $universiteDomaine = $this->service->getLdapRootService()->getEtablissementDomain();
1090
        $value = $this->preFormat($value);
1091
        $value = array_map(function ($v) use ($universiteDomaine) {
1092
            list($identifiant, $domaine) = array_pad(explode('@', strtolower($v)), 2, null);
1093
1094
            if ($domaine != $universiteDomaine) {
                $v = sprintf('%s@%s', $v, $universiteDomaine);
1095
1096
1097
            }
            return $v;
        }, $value);
1098
        $value = array_filter($value, function ($v) use ($universiteDomaine) {
1099
            return preg_match('/^[0-9a-z\-]+@' . $universiteDomaine . '$/', $v);
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgDN"
     *
1110
     * @param array|string|Dn|StructureEntity|null $value
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
     * @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();
1124
            } elseif ($val instanceof StructureEntity) {
1125
1126
1127
1128
1129
1130
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1131
        $this->appendOrNot('eduPersonOrgDN', array_filter($value), $append);
1132
1133
1134
1135
1136
1137
1138

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgUnitDN"
     *
1139
     * @param array|string|Dn|StructureEntity|null $value
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
     * @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();
1153
            } elseif ($val instanceof StructureEntity) {
1154
1155
1156
1157
1158
1159
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1160
        $this->appendOrNot('eduPersonOrgUnitDN', array_filter($value), $append);
1161
1162
1163
1164
1165
1166
1167

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonPrimaryOrgUnitDN"
     *
1168
     * @param array|string|Dn|StructureEntity|null $value
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
     * @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();
1182
            } elseif ($val instanceof StructureEntity) {
1183
1184
1185
1186
1187
1188
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1189
        $this->appendOrNot('eduPersonPrimaryOrgUnitDN', array_filter($value), $append);
1190
1191
1192
1193

        return $this;
    }

1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
    /**
     * 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)) {
1209
                if (preg_match("/^" . $supannLabel . "[\w\-]+$/", $val)) {
1210
                    return $val;
1211
                } elseif (preg_match("/^[\w\-]+$/", $val)) {
1212
1213
                    return sprintf('%s%s', $supannLabel, $val);
                }
1214
            }
1215
            return null;
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
        }, $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) {
1238
            if (preg_match(self::$role_pattern, $v, $matches)) {
1239
1240
1241
1242
1243
                /**
                 * @var string $role
                 * @var string $type
                 * @var string $code
                 */
1244
                foreach (['role', 'type'] as $part) {
1245
                    $$part = preg_match("/^" . $supannLabel . "[\w\-]+$/", $matches[$part])
1246
1247
1248
1249
                        ? $matches[$part]
                        : sprintf('%s%s', $supannLabel, $matches[$part]);
                }

1250
                $prefixe = $this->service->getLdapStructureService()->getCodeStructurePrefixe();
1251
1252
1253
                $code = (0 !== strpos($matches['code'], $prefixe))
                    ? sprintf('%s%s', $prefixe, $matches['code'])
                    : $matches['code'];
1254

1255
                return preg_replace(self::$role_pattern, "[role=$role][type=$type][code=$code][libelle=\\4]", $v, 1);
1256
            } else {
1257
                return null;
1258
1259
1260
1261
1262
1263
1264
1265
1266
            }

        }, $value);

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

        return $this;
    }

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