People.php 57.7 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
21
22
23
 */
class People extends Entity
{
    protected $type = 'People';

    /**
24
     * Liste des classes d'objet nécessaires à la création d'une entité "People"
25
26
27
28
29
30
31
32
33
34
35
36
     * 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',
37
38
39
40
        'schacPersonalCharacteristics',
        'schacEntryMetadata',
        'ucbnEmp',
        'ucbnEtu',
41
        'posixAccount',
42
        'sambaAccount',
43
        'sambaSamAccount',
44
45
    ];

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
    /**
     * 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',
75
        'ntPassword',
76
77
78
79
        'pager',
        'postalAddress',
        'preferredLanguage',
        'rid',
80
        'sambaNTPassword',
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
        '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',
128
        'ucbnSquidHash',
129
130
        'ucbnStatus',
        'ucbnStructureRecherche',
131
        'uidNumber',
132
133
134
        'unicaenMonEtupass',
        'unicaenTermsOfUse',
        'userCertificate',
135
        'userPassword',
136
137
    ];

138
139
140
141
142
    /**
     * Liste des attributs contenant des dates
     *
     * @var array
     */
143
144
145
    protected $dateTimeAttributes = [
        'schacExpiryDate',
    ];
146

147
148
149
150
151
152
153
154
    /**
     * Liste des attributs monovalués
     *
     * @var array
     */
    protected $monoValuedAttributes = [
        'cn',
        'dateDeNaissance',
155
        'dateFinInscription',
156
157
        'displayName',
        'eduPersonOrgDN',
158
        'eduPersonPrimaryAffiliation',
159
160
        'eduPersonPrimaryOrgUnitDN',
        'eduPersonPrincipalName',
161
        'gidNumber',
162
        'givenName',
163
        'homeDirectory',
164
        'leoCode',
165
166
        'loginShell',
        'ntPassword',
167
        'preferredLanguage',
168
169
170
        'rid',
        'sambaNTPassword',
        'sambaSID',
171
        'schacDateOfBirth',
172
        'schacExpiryDate',
173
174
175
176
177
178
179
180
181
        'sexe',
        'supannAliasLogin',
        'supannCivilite',
        'supannCodeINE',
        'supannEmpId',
        'supannEntiteAffectationPrincipale',
        'supannEtuId',
        'supannListeRouge',
        'telephoneNumber',
182
        'ucbnSquidHash',
183
        'uidNumber',
184
        'userPassword',
185
186
    ];

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
230
231
232
233
234
235
    /**
     * 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 = [
        'affiliate',
        'alum',
        'emeritus',
        'employee',
        'faculty',
        'member',
        'registered-reader',
        'researcher',
        'retired',
        'staff',
        'student',
        'teacher',
    ];

    /**
     * Liste des valeurs autorisées pour l'attribut "ucbnStatus"
     *
     * @var array
     */
    protected $ucbnStatusAuthorizedValues = [
        'ALUMNI',
        'APPRENANT',
        'AUDITEUR_LIBRE',
        'CONTRACTUEL',
        'ETUDIANT',
236
        'HEBERGE',
237
238
239
240
241
        'INVITE',
        'LECTEUR_SCD',
        'TITULAIRE',
    ];

242
243
    /**
     * Liste des patterns spécifiques utilisés pour différents attributs
244
     */
245
    static protected $structure_pattern = '/^(?<code>[\w\-]+);(?<libelle>.+)$/';
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
    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\-:]+\}.+)\]' .
          '\[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\-:]+\}.+)\]$/';
    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>.+)$/';
262

263
264
265
266
267
268
269
270
271

    /**
     * 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é
     *
272
     * @param array|string|null $value
273
274
     * @param bool $append
     * @return self
275
     * @throws Exception
276
277
     * @throws LdapException
     */
278
    public function setSn($value = null, $append = false)
279
    {
280
281
282
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('sn', $value, $append);
283
284
285
286
287
288
289

        return $this;
    }

    /**
     * Attribut Ldap "givenName"
     *
290
     * @param array|string|null $value
291
292
     * @param bool $append
     * @return self
293
     * @throws Exception
294
295
     * @throws LdapException
     */
296
    public function setGivenName($value = null, $append = false)
297
    {
298
299
300
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('givenName', $value, $append);
301
302
303
304
305
306
307

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

    /**
     * Attribut Ldap "dateDeNaissance"
     *
344
345
346
     * @deprecated Deprecated, use {@link self::setSchacDateOfBirth}
     *
     * @param array|string|DateTime|null $value
347
348
     * @param bool $append
     * @return self
349
     * @throws Exception
350
351
     * @throws LdapException
     */
352
    public function setDateDeNaissance($value = null, $append = false)
353
    {
354
355
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
356
357
358
359
            if (is_string($val)) {
                $val = new DateTime($val);
            }
            return $val->format('Ymd');
360
        }, $value);
361

362
        $this->appendOrNot('dateDeNaissance', $value, $append);
363
364
365
366
367
368
369

        return $this;
    }

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

386
        $this->appendOrNot('schacDateOfBirth', $value, $append);
387
388
389
390

        return $this;
    }

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
    /**
     * Attribut Ldap "dateFinInscription"
     *
     * @deprecated Deprecated, use {@link self::setSchacExpiryDate}
     *
     * @param array|string|DateTime|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    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;
    }

441
442
443
    /**
     * Attribut Ldap "sexe"
     *
444
     * @param array|string|null $value
445
446
     * @param bool $append
     * @return self
447
     * @throws Exception
448
449
     * @throws LdapException
     */
450
    public function setSexe($value = null, $append = false)
451
    {
452
453
454
455
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['F', 'M']);
        });
456

457
        $this->appendOrNot('sexe', $value, $append);
458

459
        return $this;
460
461
    }

462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
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
    /**
     * 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;
    }

504
505
506
    /**
     * Attribut Ldap "postalAddress"
     *
507
     * @param array|string|null $value
508
509
     * @param bool $append
     * @return self
510
     * @throws Exception
511
512
     * @throws LdapException
     */
513
    public function setPostalAddress($value = null, $append = false)
514
    {
515
516
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
517
            return preg_match(self::$postal_address_pattern, $v);
518
519
        });

520
        $this->appendOrNot('postalAddress', $value, $append);
521
522
523
524
525
526
527

        return $this;
    }

    /**
     * Attribut Ldap "telephoneNumber"
     *
528
     * @param array|string|null $value
529
530
     * @param bool $append
     * @return self
531
     * @throws Exception
532
533
     * @throws LdapException
     */
534
    public function setTelephoneNumber($value = null, $append = false)
535
    {
536
537
538
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatTel'], $value);
        $this->appendOrNot('telephoneNumber', $value, $append);
539
540
541
542
543
544
545

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

    /**
     * Attribut Ldap "leoCode"
     *
600
     * @param array|string|null $value
601
602
     * @param bool $append
     * @return self
603
     * @throws Exception
604
605
     * @throws LdapException
     */
606
    public function setLeoCode($value = null, $append = false)
607
    {
608
609
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
610
            return preg_match('/^\d{13}$/', $v);
611
612
        });

613
        $this->appendOrNot('leoCode', $value, $append);
614
615
616
617
618
619
620

        return $this;
    }

    /**
     * Attribut Ldap "supannALiasLogin"
     *
621
     * @param array|string|null $value
622
623
     * @param bool $append
     * @return self
624
     * @throws Exception
625
626
     * @throws LdapException
     */
627
    public function setSupannAliasLogin($value = null, $append = false)
628
    {
629
630
631
        $value = $this->preFormat($value);
        $value = array_map('strtolower', $value);
        $value = array_filter($value, function ($v) {
632
633
634
            return preg_match('/^[0-9a-z\-]+$/', $v);
        });

635
        $this->appendOrNot('supannAliasLogin', $value, $append);
636
637
638
639
640
641
642

        return $this;
    }

    /**
     * Attribut Ldap "supannEmpId"
     *
643
     * @param array|string|null $value
644
645
     * @param bool $append
     * @return self
646
     * @throws Exception
647
648
     * @throws LdapException
     */
649
    public function setSupannEmpId($value = null, $append = false)
650
    {
651
652
653
654
        $value = $this->preFormat($value);
        $this->appendOrNot('supannEmpId', $value, $append);

        return $this;
655
656
657
658
659
    }

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

        return $this;
672
673
    }

674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
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
    /**
     * 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;
    }

741
742
743
    /**
     * Attribut Ldap "supannCodeINE"
     *
744
     * @param array|string|null $value
745
746
     * @param bool $append
     * @return self
747
     * @throws Exception
748
749
     * @throws LdapException
     */
750
    public function setSupannCodeINE($value = null, $append = false)
751
    {
752
753
754
        $value = $this->preFormat($value);
        $value = array_map('strtoupper', $value);
        $value = array_filter($value, function ($v) {
755
            return preg_match('/^[\w]{11}$/', $v);
756
757
        });

758
        $this->appendOrNot('supannCodeINE', $value, $append);
759
760
761
762
763
764
765

        return $this;
    }

    /**
     * Attribut Ldap "supannCivilite"
     *
766
     * @param array|string|null $value
767
768
     * @param bool $append
     * @return self
769
     * @throws Exception
770
771
     * @throws LdapException
     */
772
    public function setSupannCivilite($value = null, $append = false)
773
    {
774
775
776
777
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['Mme', 'M.']);
        });
778

779
        $this->appendOrNot('supannCivilite', $value, $append);
780

781
        return $this;
782
783
784
785
786
    }

    /**
     * Attribut Ldap "supannListeRouge"
     *
787
     * @param array|string|null $value
788
789
     * @param bool $append
     * @return self
790
     * @throws Exception
791
792
     * @throws LdapException
     */
793
    public function setSupannListeRouge($value = null, $append = false)
794
    {
795
796
797
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatBoolean'], $value);
        $this->appendOrNot('supannListeRouge', $value, $append);
798
799
800
801
802
803
804

        return $this;
    }

    /**
     * Attribut Ldap "supannMailPerso"
     *
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
     * @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"
     *
823
     * @param array|string|StructureEntity|null $value
824
825
826
827
828
829
830
831
832
833
     * @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)) {
834
835
836
837
                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;
838
839
840
841
842
            } else {
                return null;
            }
        }, $value);

843
        $this->appendOrNot('supannAffectation', array_filter($value), $append);
844
845
846
847
848
849
850

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectation"
     *
851
     * @param array|string|StructureEntity|null $value
852
853
     * @param bool $append
     * @return self
854
     * @throws Exception
855
856
     * @throws LdapException
     */
857
    public function setSupannEntiteAffectation($value = null, $append = false)
858
    {
859
860
861
862
863
864
865
        $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;
866
            } elseif ($val instanceof StructureEntity) {
867
868
869
870
871
872
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

873
        $this->appendOrNot('supannEntiteAffectation', array_filter($value), $append);
874
875
876
877
878
879
880

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectationPrincipale"
     *
881
     * @param array|string|StructureEntity|null $value
882
883
884
885
886
887
888
889
890
891
892
893
894
895
     * @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;
896
            } elseif ($val instanceof StructureEntity) {
897
898
899
900
901
902
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

903
        $this->appendOrNot('supannEntiteAffectationPrincipale', array_filter($value), $append);
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919

        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);
920
921
        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($val) use ($supannLabel) {
922
            if (is_string($val)) {
923
924
925
926
927
928
                if(preg_match("/^".$supannLabel."[\w\-]+$/", $val)) {
                    return $val;
                }
                elseif(preg_match("/^[\w\-]+$/", $val)) {
                    return sprintf('%s%s', $supannLabel, $val);
                }
929
            }
930
            return null;
931
932
        }, $value);

933
        $this->appendOrNot('supannTypeEntiteAffectation', array_filter($value), $append);
934
935
936
937

        return $this;
    }

938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
    /**
     * 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;
    }

959
960
961
    /**
     * Attribut Ldap "ucbnSousStructure"
     *
962
     * @param array|string|StructureEntity|null $value
963
964
965
966
967
968
969
970
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnSousStructure($value = null, $append = false)
    {
        $value = $this->preFormat($value);
971
972
973
974
975
976
977
978
979
980
        $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);
981

982
        $this->appendOrNot('ucbnSousStructure', array_filter($value), $append);
983
984
985
986
987
988
989

        return $this;
    }

    /**
     * Attribut Ldap "ucbnStructureRecherche"
     *
990
     * @param array|string|StructureEntity|null $value
991
992
993
994
995
996
997
998
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnStructureRecherche($value = null, $append = false)
    {
        $value = $this->preFormat($value);
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
        $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);
1009

1010
        $this->appendOrNot('ucbnStructureRecherche', array_filter($value), $append);
1011
1012
1013
1014

        return $this;
    }

1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
    /**
     * 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);
1027
1028
1029
        $value = array_map(function ($v) {
            list($identifiant, $domaine) = array_pad(explode('@', strtolower($v)), 2, null);
            if ($domaine != self::$etablissement_domaine) {
1030
1031
1032
1033
1034
                $v = sprintf('%s@%s', $v, self::$etablissement_domaine);
            }
            return $v;
        }, $value);
        $value = array_filter($value, function ($v) {
1035
            return preg_match('/^[0-9a-z\-]+@' . self::$etablissement_domaine . '$/', $v);
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgDN"
     *
1046
     * @param array|string|Dn|StructureEntity|null $value
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
     * @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();
1060
            } elseif ($val instanceof StructureEntity) {
1061
1062
1063
1064
1065
1066
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1067
        $this->appendOrNot('eduPersonOrgDN', array_filter($value), $append);
1068
1069
1070
1071
1072
1073
1074

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgUnitDN"
     *
1075
     * @param array|string|Dn|StructureEntity|null $value
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
     * @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();
1089
            } elseif ($val instanceof StructureEntity) {
1090
1091
1092
1093
1094
1095
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1096
        $this->appendOrNot('eduPersonOrgUnitDN', array_filter($value), $append);
1097
1098
1099
1100
1101
1102
1103

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonPrimaryOrgUnitDN"
     *
1104
     * @param array|string|Dn|StructureEntity|null $value
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
     * @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();
1118
            } elseif ($val instanceof StructureEntity) {
1119
1120
1121
1122
1123
1124
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1125
        $this->appendOrNot('eduPersonPrimaryOrgUnitDN', array_filter($value), $append);
1126
1127
1128
1129

        return $this;
    }

1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
    /**
     * 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)) {
1145
1146
1147
1148
1149
1150
                if(preg_match("/^".$supannLabel."[\w\-]+$/", $val)) {
                    return $val;
                }
                elseif(preg_match("/^[\w\-]+$/", $val)) {
                    return sprintf('%s%s', $supannLabel, $val);
                }
1151
            }
1152
            return null;
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
        }, $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) {
1175
            if (preg_match(self::$role_pattern, $v, $matches)) {
1176
1177
1178
1179
1180
                /**
                 * @var string $role
                 * @var string $type
                 * @var string $code
                 */
1181
                foreach (['role', 'type'] as $part) {
1182
                    $$part = preg_match("/^".$supannLabel."[\w\-]+$/", $matches[$part])
1183
1184
1185
1186
1187
1188
1189
1190
                        ? $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'];
1191

1192
                return preg_replace(self::$role_pattern, "[role=$role][type=$type][code=$code][libelle=\\4]", $v, 1);
1193
            } else {
1194
                return null;
1195
1196
1197
1198
1199
1200
1201
1202
1203
            }

        }, $value);

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

        return $this;
    }

1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
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
    /**
     * 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;
    }

1288
    /**
1289
     * Attribut Ldap "ucbnFonctionStructurelle"
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
     *
     * @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;
    }

1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
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
    /**
     * 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;
    }

1352
1353
1354
    /**
     * Attribut Ldap "supannParrainDN"
     *
1355
     * @param array|string|Dn|PeopleEntity|null $value
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
     * @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();
1369
            } elseif ($val instanceof PeopleEntity) {
1370
1371
1372
1373
1374
1375
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1376
        $this->appendOrNot('supannParrainDN', array_filter($value), $append);
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393

        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);
        $value = array_filter($value, function ($v) {
1394
            return preg_match(self::$attribute_with_label_pattern, $v);
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
        });

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

        return $this;
    }

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

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

        return $this;
    }

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

        return $this;
    }

1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
    /**
     * Attribut Ldap "supannActivite"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannActivite($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$attribute_with_label_pattern, $v);
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "ucbnSecteurDisciplinaire"
     *
     * @param