People.php 65.8 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
    /**
     * Liste des attributs autorisés pour une entité "People"
     *
     * @var array
     */
    protected $authorizedAttributes = [
        // Attributes classes
        'objectClass',
        // Attributes
74
        'campusPassword',
75
76
        'cn',
        'dateDeNaissance',
77
78
        'dateFinInscription',
        'displayName',
79
        'eduPersonAffiliation',
80
        'eduPersonNickname',
81
82
        'eduPersonOrgDN',
        'eduPersonOrgUnitDN',
83
        'eduPersonPrimaryAffiliation',
84
        'eduPersonPrimaryOrgUnitDN',
85
86
        'eduPersonPrincipalName',
        'facsimileTelephoneNumber',
87
88
89
        'gidNumber',
        'givenName',
        'homeDirectory',
90
        'labeledURI',
91
92
93
        'leoCode',
        'loginShell',
        'mail',
94
        'mailForwardingAddress',
95
        'mobile',
96
        'ntPassword',
97
98
99
100
        'pager',
        'postalAddress',
        'preferredLanguage',
        'rid',
101
        'sambaNTPassword',
102
103
104
105
106
107
108
109
        'sambaSID',
        'schacDateOfBirth',
        'schacExpiryDate',
        'sexe',
        'sn',
        'supannActivite',
        'supannAffectation',
        'supannAliasLogin',
110
        'supannAutreMail',
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
        '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',
137
        'title',
138
139
140
141
142
143
144
145
146
        'ucbnAnneePostBac',
        'ucbnCodeEtape',
        'ucbnEtuComplementInscription',
        'ucbnFonctionStructurelle',
        'ucbnOrganisme',
        'ucbnPrivateAddress',
        'ucbnPrivateAddressBis',
        'ucbnSecteurDisciplinaire',
        'ucbnServiceADE',
147
148
149
150
        'ucbnServiceAD',
        'ucbnServiceAnnuaire',
        'ucbnServiceEspacePerso',
        'ucbnServiceIMAP',
151
        'ucbnServicePapercut',
152
        'ucbnServiceRessourcesDoc',
153
        'ucbnServiceWIFI',
154
155
        'ucbnSiteLocalisation',
        'ucbnSousStructure',
156
        'ucbnSquidHash',
157
158
        'ucbnStatus',
        'ucbnStructureRecherche',
159
        'uidNumber',
160
        'unicaenLeocarteCSN',
161
        'unicaenMonEtupass',
David Surville's avatar
David Surville committed
162
        'unicaenRefId',
163
164
        'unicaenSecuriteCompte',
        'unicaenServiceEtat',
165
166
        'unicaenTermsOfUse',
        'userCertificate',
167
        'userPassword',
168
169
    ];

170
171
172
173
174
    /**
     * Liste des attributs contenant des dates
     *
     * @var array
     */
175
176
177
    protected $dateTimeAttributes = [
        'schacExpiryDate',
    ];
178

179
180
181
182
183
184
185
186
    /**
     * Liste des attributs monovalués
     *
     * @var array
     */
    protected $monoValuedAttributes = [
        'cn',
        'dateDeNaissance',
187
        'dateFinInscription',
188
189
        'displayName',
        'eduPersonOrgDN',
190
        'eduPersonPrimaryAffiliation',
191
192
        'eduPersonPrimaryOrgUnitDN',
        'eduPersonPrincipalName',
193
        'gidNumber',
194
        'givenName',
195
        'homeDirectory',
196
        'leoCode',
197
198
        'loginShell',
        'ntPassword',
199
        'preferredLanguage',
200
201
202
        'rid',
        'sambaNTPassword',
        'sambaSID',
203
        'schacDateOfBirth',
204
        'schacExpiryDate',
205
206
207
208
209
210
211
212
213
        'sexe',
        'supannAliasLogin',
        'supannCivilite',
        'supannCodeINE',
        'supannEmpId',
        'supannEntiteAffectationPrincipale',
        'supannEtuId',
        'supannListeRouge',
        'telephoneNumber',
214
215
        'ucbnServiceADE',
        'ucbnServicePapercut',
216
        'ucbnSquidHash',
217
        'uidNumber',
218
        'unicaenLeocarteCSN',
David Surville's avatar
David Surville committed
219
        'unicaenRefId',
220
        'userPassword',
221
222
    ];

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
    /**
     * 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 = [
247
248
249
250
251
252
253
254
255
256
257
258
        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,
259
260
261
262
263
264
265
266
267
268
269
270
271
    ];

    /**
     * Liste des valeurs autorisées pour l'attribut "ucbnStatus"
     *
     * @var array
     */
    protected $ucbnStatusAuthorizedValues = [
        'ALUMNI',
        'APPRENANT',
        'AUDITEUR_LIBRE',
        'CONTRACTUEL',
        'ETUDIANT',
272
        'HEBERGE',
273
274
275
276
277
        'INVITE',
        'LECTEUR_SCD',
        'TITULAIRE',
    ];

278
279
    /**
     * Liste des patterns spécifiques utilisés pour différents attributs
280
     */
281
    static protected $structure_pattern = '/^(?<code>[\w\-]+);(?<libelle>.+)$/';
282
283
284
285
286
    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\-:]+\}.+)\]' .
287
288
289
290
291
292
293
294
        '\[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\-:]+\}.+)\]$/';
295
296
297
298
299
300
301
302
303
    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>.+)\]$/';
304
    static protected $role_src_pattern = '/^(?<code>\d{4});(?<libelle>.+)$/';
305
    static protected $service_etat_pattern = '/^(?<etiquette>\{[\w\-]+\})(?<value>(A|I|S){1})$/';
306

307
308
309
310
311
312
313
314
315

    /**
     * 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é
     *
316
     * @param array|string|null $value
317
318
     * @param bool $append
     * @return self
319
     * @throws Exception
320
321
     * @throws LdapException
     */
322
    public function setSn($value = null, $append = false)
323
    {
324
325
326
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('sn', $value, $append);
327
328
329
330
331
332
333

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

    /**
     * Attribut Ldap "cn"
     *
370
     * @param array|string|null $value
371
372
     * @param bool $append
     * @return self
373
     * @throws Exception
374
375
     * @throws LdapException
     */
376
    public function setCn($value = null, $append = false)
377
    {
378
379
380
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value, [true]);
        $this->appendOrNot('cn', $value, $append);
381
382
383
384
385
386
387

        return $this;
    }

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

406
        $this->appendOrNot('dateDeNaissance', $value, $append);
407
408
409
410
411
412
413

        return $this;
    }

    /**
     * Attribut Ldap "schacDateOfBirth"
     *
414
     * @param array|string|DateTime|null $value
415
416
     * @param bool $append
     * @return self
417
     * @throws Exception
418
419
     * @throws LdapException
     */
420
    public function setSchacDateOfBirth($value = null, $append = false)
421
    {
422
423
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
424
425
426
427
            if (is_string($val)) {
                $val = new DateTime($val);
            }
            return $val->format('Ymd');
428
        }, $value);
429

430
        $this->appendOrNot('schacDateOfBirth', $value, $append);
431
432
433
434

        return $this;
    }

435
436
437
438
439
440
441
442
    /**
     * Attribut Ldap "dateFinInscription"
     *
     * @param array|string|DateTime|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
443
444
     * @deprecated Deprecated, use {@link self::setSchacExpiryDate}
     *
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
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
     */
    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;
    }

485
486
487
    /**
     * Attribut Ldap "sexe"
     *
488
     * @param array|string|null $value
489
490
     * @param bool $append
     * @return self
491
     * @throws Exception
492
493
     * @throws LdapException
     */
494
    public function setSexe($value = null, $append = false)
495
    {
496
497
498
499
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['F', 'M']);
        });
500

501
        $this->appendOrNot('sexe', $value, $append);
502

503
        return $this;
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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
    /**
     * 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;
    }

548
549
550
    /**
     * Attribut Ldap "postalAddress"
     *
551
     * @param array|string|null $value
552
553
     * @param bool $append
     * @return self
554
     * @throws Exception
555
556
     * @throws LdapException
     */
557
    public function setPostalAddress($value = null, $append = false)
558
    {
559
560
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
561
            return preg_match(self::$postal_address_pattern, $v);
562
563
        });

564
        $this->appendOrNot('postalAddress', $value, $append);
565
566
567
568
569
570
571

        return $this;
    }

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

        return $this;
    }

    /**
     * Attribut Ldap "supannAutreTelephone"
     *
590
     * @param array|string|null $value
591
592
     * @param bool $append
     * @return self
593
     * @throws Exception
594
595
     * @throws LdapException
     */
596
    public function setSupannAutreTelephone($value = null, $append = false)
597
    {
598
599
600
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatTel'], $value);
        $this->appendOrNot('supannAutreTelephone', $value, $append);
601
602
603
604

        return $this;
    }

605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
    /**
     * 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;
    }

623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
    /**
     * Attribut Ldap "supannAutreMail"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannAutreMail($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter(filter_var_array($value, FILTER_VALIDATE_EMAIL));
        $this->appendOrNot('supannAutreMail', $value, $append);

        return $this;
    }

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

        return $this;
    }

659
660
661
    /**
     * Attribut Ldap "mobile"
     *
662
     * @param array|string|null $value
663
664
     * @param bool $append
     * @return self
665
     * @throws Exception
666
667
     * @throws LdapException
     */
668
    public function setMobile($value = null, $append = false)
669
    {
670
671
672
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatTel'], $value);
        $this->appendOrNot('mobile', $value, $append);
673
674
675
676

        return $this;
    }

677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
    /**
     * 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;
    }

695
696
697
    /**
     * Attribut Ldap "preferredLanguage"
     *
698
     * @param array|string|null $value
699
700
     * @param bool $append
     * @return self
701
     * @throws Exception
702
703
     * @throws LdapException
     */
704
    public function setPreferredLanguage($value = null, $append = false)
705
    {
706
707
708
        $value = $this->preFormat($value);
        $value = array_map('strtolower', $value);
        $this->appendOrNot('preferredLanguage', $value, $append);
709
710
711
712
713
714
715

        return $this;
    }

    /**
     * Attribut Ldap "leoCode"
     *
716
     * @param array|string|null $value
717
718
     * @param bool $append
     * @return self
719
     * @throws Exception
720
721
     * @throws LdapException
     */
722
    public function setLeoCode($value = null, $append = false)
723
    {
724
725
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
726
            return preg_match('/^\d{13}$/', $v);
727
728
        });

729
        $this->appendOrNot('leoCode', $value, $append);
730
731
732
733
734
735
736

        return $this;
    }

    /**
     * Attribut Ldap "supannALiasLogin"
     *
737
     * @param array|string|null $value
738
739
     * @param bool $append
     * @return self
740
     * @throws Exception
741
742
     * @throws LdapException
     */
743
    public function setSupannAliasLogin($value = null, $append = false)
744
    {
745
746
747
        $value = $this->preFormat($value);
        $value = array_map('strtolower', $value);
        $value = array_filter($value, function ($v) {
748
749
750
            return preg_match('/^[0-9a-z\-]+$/', $v);
        });

751
        $this->appendOrNot('supannAliasLogin', $value, $append);
752
753
754
755
756
757
758

        return $this;
    }

    /**
     * Attribut Ldap "supannEmpId"
     *
759
     * @param array|string|null $value
760
761
     * @param bool $append
     * @return self
762
     * @throws Exception
763
764
     * @throws LdapException
     */
765
    public function setSupannEmpId($value = null, $append = false)
766
    {
767
768
769
770
        $value = $this->preFormat($value);
        $this->appendOrNot('supannEmpId', $value, $append);

        return $this;
771
772
773
774
775
    }

    /**
     * Attribut Ldap "supannEtuId"
     *
776
     * @param array|string|null $value
777
778
     * @param bool $append
     * @return self
779
     * @throws Exception
780
781
     * @throws LdapException
     */
782
    public function setSupannEtuId($value = null, $append = false)
783
    {
784
785
786
787
        $value = $this->preFormat($value);
        $this->appendOrNot('supannEtuId', $value, $append);

        return $this;
788
789
    }

790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
    /**
     * 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]);
                }

830
                $prefixe = $this->service->getLdapStructureService()->getCodeStructurePrefixe();
831
832
833
834
                $affect = (0 !== strpos($matches['affect'], $prefixe))
                    ? sprintf('%s%s', $structure_prefixe, $matches['affect'])
                    : $matches['affect'];

835
                $prefixe = $this->service->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
                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;
    }

857
858
859
    /**
     * Attribut Ldap "supannCodeINE"
     *
860
     * @param array|string|null $value
861
862
     * @param bool $append
     * @return self
863
     * @throws Exception
864
865
     * @throws LdapException
     */
866
    public function setSupannCodeINE($value = null, $append = false)
867
    {
868
869
870
        $value = $this->preFormat($value);
        $value = array_map('strtoupper', $value);
        $value = array_filter($value, function ($v) {
871
            return preg_match('/^[\w]{11}$/', $v);
872
873
        });

874
        $this->appendOrNot('supannCodeINE', $value, $append);
875
876
877
878
879
880
881

        return $this;
    }

    /**
     * Attribut Ldap "supannCivilite"
     *
882
     * @param array|string|null $value
883
884
     * @param bool $append
     * @return self
885
     * @throws Exception
886
887
     * @throws LdapException
     */
888
    public function setSupannCivilite($value = null, $append = false)
889
    {
890
891
892
893
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['Mme', 'M.']);
        });
894

895
        $this->appendOrNot('supannCivilite', $value, $append);
896

897
        return $this;
898
899
900
901
902
    }

    /**
     * Attribut Ldap "supannListeRouge"
     *
903
     * @param array|string|null $value
904
905
     * @param bool $append
     * @return self
906
     * @throws Exception
907
908
     * @throws LdapException
     */
909
    public function setSupannListeRouge($value = null, $append = false)
910
    {
911
912
913
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatBoolean'], $value);
        $this->appendOrNot('supannListeRouge', $value, $append);
914
915
916
917
918
919
920

        return $this;
    }

    /**
     * Attribut Ldap "supannMailPerso"
     *
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
     * @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"
     *
939
     * @param array|string|StructureEntity|null $value
940
941
942
943
944
945
946
947
948
949
     * @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)) {
950
951
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
952
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->service->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
953
                return preg_match(self::$structure_pattern, $val) ? $val : null;
954
955
956
957
958
            } else {
                return null;
            }
        }, $value);

959
        $this->appendOrNot('supannAffectation', array_filter($value), $append);
960
961
962
963
964
965
966

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectation"
     *
967
     * @param array|string|StructureEntity|null $value
968
969
     * @param bool $append
     * @return self
970
     * @throws Exception
971
972
     * @throws LdapException
     */
973
    public function setSupannEntiteAffectation($value = null, $append = false)
974
    {
975
976
977
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
978
979
                if (0 !== strpos($val, $this->service->getLdapStructureService()->getCodeStructurePrefixe())) {
                    $val = $this->service->getLdapStructureService()->getCodeStructurePrefixe() . $val;
980
981
                }
                return $val;
982
            } elseif ($val instanceof StructureEntity) {
983
984
985
986
987
988
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

989
        $this->appendOrNot('supannEntiteAffectation', array_filter($value), $append);
990
991
992
993
994
995
996

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectationPrincipale"
     *
997
     * @param array|string|StructureEntity|null $value
998
999
1000
1001
1002
1003
1004
1005
1006
1007
     * @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)) {
1008
1009
                if (0 !== strpos($val, $this->service->getLdapStructureService()->getCodeStructurePrefixe())) {
                    $val = $this->service->getLdapStructureService()->getCodeStructurePrefixe() . $val;
1010
1011
                }
                return $val;
1012
            } elseif ($val instanceof StructureEntity) {
1013
1014
1015
1016
1017
1018
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

1019
        $this->appendOrNot('supannEntiteAffectationPrincipale', array_filter($value), $append);
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035

        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);
1036
1037
        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($val) use ($supannLabel) {
1038
            if (is_string($val)) {
1039
                if (preg_match("/^" . $supannLabel . "[\w\-]+$/", $val)) {
1040
                    return $val;
1041
                } elseif (preg_match("/^[\w\-]+$/", $val)) {
1042
1043
                    return sprintf('%s%s', $supannLabel, $val);
                }
1044
            }
1045
            return null;
1046
1047
        }, $value);

1048
        $this->appendOrNot('supannTypeEntiteAffectation', array_filter($value), $append);
1049
1050
1051
1052

        return $this;
    }

1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
    /**
     * 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;
    }

1074
1075
1076
    /**
     * Attribut Ldap "ucbnSousStructure"
     *
1077
     * @param array|string|StructureEntity|null $value
1078
1079
1080
1081
1082
1083
1084
1085
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnSousStructure($value = null, $append = false)
    {
        $value = $this->preFormat($value);
1086
1087
1088
1089
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
1090
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->service->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
1091
1092
1093
1094
1095
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);
1096

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

        return $this;
    }

    /**
     * Attribut Ldap "ucbnStructureRecherche"
     *
1105
     * @param array|string|StructureEntity|null $value
1106
1107
1108
1109
1110
1111
1112
1113
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnStructureRecherche($value = null, $append = false)
    {
        $value = $this->preFormat($value);
1114
1115
1116
1117
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
1118
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->service->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
1119
1120
1121
1122
1123
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);
1124

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

        return $this;
    }

1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
    /**
     * Attribut Ldap "eduPersonPrincipalName"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setEduPersonPrincipalName($value = null, $append = false)
    {
1141
        $universiteDomaine = $this->service->getLdapRootService()->getEtablissementDomain();
1142
        $value = $this->preFormat($value);
1143
        $value = array_map(function ($v) use ($universiteDomaine) {
1144
            list($identifiant, $domaine) = array_pad(explode('@', strtolower($v)), 2, null);
1145
1146
            if ($domaine != $universiteDomaine) {
                $v = sprintf('%s@%s', $v, $universiteDomaine);
1147
1148
1149
            }
            return $v;
        }, $value);
1150
        $value = array_filter($value, function ($v) use ($universiteDomaine) {
1151
            return preg_match('/^[0-9a-z\-]+@' . $universiteDomaine . '$/', $v);
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgDN"
     *
1162
     * @param array|string|Dn|StructureEntity|null $value
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
     * @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();
1176
            } elseif ($val instanceof StructureEntity) {
1177
1178
1179
1180
1181
1182
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1183
        $this->appendOrNot('eduPersonOrgDN', array_filter($value), $append);
1184
1185
1186
1187
1188
1189
1190

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgUnitDN"
     *
1191
     * @param array|string|Dn|StructureEntity|null $value
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
     * @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();
1205
            } elseif ($val instanceof StructureEntity) {
1206
1207
1208
1209
1210
1211
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1212
        $this->appendOrNot('eduPersonOrgUnitDN', array_filter($value), $append);
1213
1214
1215
1216
1217
1218
1219

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonPrimaryOrgUnitDN"
     *
1220
     * @param array|string|Dn|StructureEntity|null $value
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
     * @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();
1234
            } elseif ($val instanceof StructureEntity) {
1235
1236
1237
1238
1239
1240
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1241
        $this->appendOrNot('eduPersonPrimaryOrgUnitDN', array_filter($value), $append);
1242
1243
1244
1245

        return $this;
    }

1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
    /**
     * 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)) {
1261
                if (preg_match("/^" . $supannLabel . "[\w\-]+$/", $val)) {
1262
                    return $val;
1263
                } elseif (preg_match("/^[\w\-]+$/", $val)) {
1264
1265
                    return sprintf('%s%s', $supannLabel, $val);
                }
1266
            }
1267
            return null;