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

namespace UnicaenLdap\Entity\Base;

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

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

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

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

65
66
67
68
69
70
71
72
73
    /**
     * 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
        'unicaenMailPrincipal',
162
        'unicaenMonEtupass',
David Surville's avatar
David Surville committed
163
        'unicaenRefId',
164
165
        'unicaenSecuriteCompte',
        'unicaenServiceEtat',
166
167
        'unicaenTermsOfUse',
        'userCertificate',
168
        'userPassword',
169
170
    ];

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

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

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

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

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

309
310
311
312
313
314
315
316
317

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

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

437
438
439
440
441
442
443
444
    /**
     * Attribut Ldap "dateFinInscription"
     *
     * @param array|string|DateTime|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
445
446
     * @deprecated Deprecated, use {@link self::setSchacExpiryDate}
     *
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
485
486
     */
    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;
    }

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

503
        $this->appendOrNot('sexe', $value, $append);
504

505
        return $this;
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
548
549
    /**
     * 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;
    }

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

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

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

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

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
659
660
    /**
     * 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;
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

        return $this;
773
774
775
776
777
    }

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

        return $this;
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
830
831
    /**
     * 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]);
                }

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

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

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

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

        return $this;
    }

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

897
        $this->appendOrNot('supannCivilite', $value, $append);
898

899
        return $this;
900
901
902
903
904
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonPrimaryOrgUnitDN"
     *