People.php 59.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
 */
class People extends Entity
{
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    /**
     * Constantes pour les champs eduPersonAffiliation et eduPersonPrimaryAffiliation
     */
    const STATUS_AFFILIATE = 'affiliate';
    const STATUS_ALUM = 'alum';
    const STATUS_EMERITUS = 'emeritus';
    const STATUS_EMPLOYEE = 'employee';
    const STATUS_FACULTY = 'faculty';
    const STATUS_MEMBER = 'member';
    const STATUS_REGISTERED_READER = 'registered-reader';
    const STATUS_RESEARCHER = 'researcher';
    const STATUS_RETIRED = 'retired';
    const STATUS_STAFF = 'staff';
    const STATUS_STUDENT = 'student';
    const STATUS_TEACHER = 'teacher';

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

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

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

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

168
169
170
171
172
173
174
175
    /**
     * Liste des attributs monovalués
     *
     * @var array
     */
    protected $monoValuedAttributes = [
        'cn',
        'dateDeNaissance',
176
        'dateFinInscription',
177
178
        'displayName',
        'eduPersonOrgDN',
179
        'eduPersonPrimaryAffiliation',
180
181
        'eduPersonPrimaryOrgUnitDN',
        'eduPersonPrincipalName',
182
        'gidNumber',
183
        'givenName',
184
        'homeDirectory',
185
        'leoCode',
186
187
        'loginShell',
        'ntPassword',
188
        'preferredLanguage',
189
190
191
        'rid',
        'sambaNTPassword',
        'sambaSID',
192
        'schacDateOfBirth',
193
        'schacExpiryDate',
194
195
196
197
198
199
200
201
202
        'sexe',
        'supannAliasLogin',
        'supannCivilite',
        'supannCodeINE',
        'supannEmpId',
        'supannEntiteAffectationPrincipale',
        'supannEtuId',
        'supannListeRouge',
        'telephoneNumber',
203
204
        'ucbnServiceADE',
        'ucbnServicePapercut',
205
        'ucbnSquidHash',
206
        'uidNumber',
207
        'userPassword',
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
    /**
     * 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 = [
234
235
236
237
238
239
240
241
242
243
244
245
        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,
246
247
248
249
250
251
252
253
254
255
256
257
258
    ];

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

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

293
294
295
296
297
298
299
300
301

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

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

421
422
423
424
425
426
427
428
    /**
     * Attribut Ldap "dateFinInscription"
     *
     * @param array|string|DateTime|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
429
430
     * @deprecated Deprecated, use {@link self::setSchacExpiryDate}
     *
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
     */
    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;
    }

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

487
        $this->appendOrNot('sexe', $value, $append);
488

489
        return $this;
490
491
    }

492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
    /**
     * 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;
    }

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

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

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

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

609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
    /**
     * 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;
    }

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

        return $this;
    }

663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
    /**
     * 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;
    }

681
682
683
    /**
     * Attribut Ldap "preferredLanguage"
     *
684
     * @param array|string|null $value
685
686
     * @param bool $append
     * @return self
687
     * @throws Exception
688
689
     * @throws LdapException
     */
690
    public function setPreferredLanguage($value = null, $append = false)
691
    {
692
693
694
        $value = $this->preFormat($value);
        $value = array_map('strtolower', $value);
        $this->appendOrNot('preferredLanguage', $value, $append);
695
696
697
698
699
700
701

        return $this;
    }

    /**
     * Attribut Ldap "leoCode"
     *
702
     * @param array|string|null $value
703
704
     * @param bool $append
     * @return self
705
     * @throws Exception
706
707
     * @throws LdapException
     */
708
    public function setLeoCode($value = null, $append = false)
709
    {
710
711
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
712
            return preg_match('/^\d{13}$/', $v);
713
714
        });

715
        $this->appendOrNot('leoCode', $value, $append);
716
717
718
719
720
721
722

        return $this;
    }

    /**
     * Attribut Ldap "supannALiasLogin"
     *
723
     * @param array|string|null $value
724
725
     * @param bool $append
     * @return self
726
     * @throws Exception
727
728
     * @throws LdapException
     */
729
    public function setSupannAliasLogin($value = null, $append = false)
730
    {
731
732
733
        $value = $this->preFormat($value);
        $value = array_map('strtolower', $value);
        $value = array_filter($value, function ($v) {
734
735
736
            return preg_match('/^[0-9a-z\-]+$/', $v);
        });

737
        $this->appendOrNot('supannAliasLogin', $value, $append);
738
739
740
741
742
743
744

        return $this;
    }

    /**
     * Attribut Ldap "supannEmpId"
     *
745
     * @param array|string|null $value
746
747
     * @param bool $append
     * @return self
748
     * @throws Exception
749
750
     * @throws LdapException
     */
751
    public function setSupannEmpId($value = null, $append = false)
752
    {
753
754
755
756
        $value = $this->preFormat($value);
        $this->appendOrNot('supannEmpId', $value, $append);

        return $this;
757
758
759
760
761
    }

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

        return $this;
774
775
    }

776
777
778
779
780
781
782
783
784
785
786
787
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
    /**
     * 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]);
                }

816
                $prefixe = $this->service->getLdapStructureService()->getCodeStructurePrefixe();
817
818
819
820
                $affect = (0 !== strpos($matches['affect'], $prefixe))
                    ? sprintf('%s%s', $structure_prefixe, $matches['affect'])
                    : $matches['affect'];

821
                $prefixe = $this->service->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
                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;
    }

843
844
845
    /**
     * Attribut Ldap "supannCodeINE"
     *
846
     * @param array|string|null $value
847
848
     * @param bool $append
     * @return self
849
     * @throws Exception
850
851
     * @throws LdapException
     */
852
    public function setSupannCodeINE($value = null, $append = false)
853
    {
854
855
856
        $value = $this->preFormat($value);
        $value = array_map('strtoupper', $value);
        $value = array_filter($value, function ($v) {
857
            return preg_match('/^[\w]{11}$/', $v);
858
859
        });

860
        $this->appendOrNot('supannCodeINE', $value, $append);
861
862
863
864
865
866
867

        return $this;
    }

    /**
     * Attribut Ldap "supannCivilite"
     *
868
     * @param array|string|null $value
869
870
     * @param bool $append
     * @return self
871
     * @throws Exception
872
873
     * @throws LdapException
     */
874
    public function setSupannCivilite($value = null, $append = false)
875
    {
876
877
878
879
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['Mme', 'M.']);
        });
880

881
        $this->appendOrNot('supannCivilite', $value, $append);
882

883
        return $this;
884
885
886
887
888
    }

    /**
     * Attribut Ldap "supannListeRouge"
     *
889
     * @param array|string|null $value
890
891
     * @param bool $append
     * @return self
892
     * @throws Exception
893
894
     * @throws LdapException
     */
895
    public function setSupannListeRouge($value = null, $append = false)
896
    {
897
898
899
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatBoolean'], $value);
        $this->appendOrNot('supannListeRouge', $value, $append);
900
901
902
903
904
905
906

        return $this;
    }

    /**
     * Attribut Ldap "supannMailPerso"
     *
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
     * @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"
     *
925
     * @param array|string|StructureEntity|null $value
926
927
928
929
930
931
932
933
934
935
     * @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)) {
936
937
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
938
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->service->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
939
                return preg_match(self::$structure_pattern, $val) ? $val : null;
940
941
942
943
944
            } else {
                return null;
            }
        }, $value);

945
        $this->appendOrNot('supannAffectation', array_filter($value), $append);
946
947
948
949
950
951
952

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectation"
     *
953
     * @param array|string|StructureEntity|null $value
954
955
     * @param bool $append
     * @return self
956
     * @throws Exception
957
958
     * @throws LdapException
     */
959
    public function setSupannEntiteAffectation($value = null, $append = false)
960
    {
961
962
963
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
964
965
                if (0 !== strpos($val, $this->service->getLdapStructureService()->getCodeStructurePrefixe())) {
                    $val = $this->service->getLdapStructureService()->getCodeStructurePrefixe() . $val;
966
967
                }
                return $val;
968
            } elseif ($val instanceof StructureEntity) {
969
970
971
972
973
974
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

975
        $this->appendOrNot('supannEntiteAffectation', array_filter($value), $append);
976
977
978
979
980
981
982

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectationPrincipale"
     *
983
     * @param array|string|StructureEntity|null $value
984
985
986
987
988
989
990
991
992
993
     * @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)) {
994
995
                if (0 !== strpos($val, $this->service->getLdapStructureService()->getCodeStructurePrefixe())) {
                    $val = $this->service->getLdapStructureService()->getCodeStructurePrefixe() . $val;
996
997
                }
                return $val;
998
            } elseif ($val instanceof StructureEntity) {
999
1000
1001
1002
1003
1004
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

1005
        $this->appendOrNot('supannEntiteAffectationPrincipale', array_filter($value), $append);
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021

        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);
1022
1023
        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($val) use ($supannLabel) {
1024
            if (is_string($val)) {
1025
                if (preg_match("/^" . $supannLabel . "[\w\-]+$/", $val)) {
1026
                    return $val;
1027
                } elseif (preg_match("/^[\w\-]+$/", $val)) {
1028
1029
                    return sprintf('%s%s', $supannLabel, $val);
                }
1030
            }
1031
            return null;
1032
1033
        }, $value);

1034
        $this->appendOrNot('supannTypeEntiteAffectation', array_filter($value), $append);
1035
1036
1037
1038

        return $this;
    }

1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
    /**
     * 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;
    }

1060
1061
1062
    /**
     * Attribut Ldap "ucbnSousStructure"
     *
1063
     * @param array|string|StructureEntity|null $value
1064
1065
1066
1067
1068
1069
1070
1071
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnSousStructure($value = null, $append = false)
    {
        $value = $this->preFormat($value);
1072
1073
1074
1075
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
1076
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->service->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
1077
1078
1079
1080
1081
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);
1082

1083
        $this->appendOrNot('ucbnSousStructure', array_filter($value), $append);
1084
1085
1086
1087
1088
1089
1090

        return $this;
    }

    /**
     * Attribut Ldap "ucbnStructureRecherche"
     *
1091
     * @param array|string|StructureEntity|null $value
1092
1093
1094
1095
1096
1097
1098
1099
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnStructureRecherche($value = null, $append = false)
    {
        $value = $this->preFormat($value);
1100
1101
1102
1103
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
1104
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->service->getLdapStructureService()->getCodeStructurePrefixe(), ''), $val->get('description'));
1105
1106
1107
1108
1109
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);
1110

1111
        $this->appendOrNot('ucbnStructureRecherche', array_filter($value), $append);
1112
1113
1114
1115

        return $this;
    }

1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
    /**
     * Attribut Ldap "eduPersonPrincipalName"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setEduPersonPrincipalName($value = null, $append = false)
    {
1127
        $universiteDomaine = $this->service->getLdapRootService()->getEtablissementDomain();
1128
        $value = $this->preFormat($value);
1129
        $value = array_map(function ($v) use ($universiteDomaine) {
1130
            list($identifiant, $domaine) = array_pad(explode('@', strtolower($v)), 2, null);
1131
1132
            if ($domaine != $universiteDomaine) {
                $v = sprintf('%s@%s', $v, $universiteDomaine);
1133
1134
1135
            }
            return $v;
        }, $value);
1136
        $value = array_filter($value, function ($v) use ($universiteDomaine) {
1137
            return preg_match('/^[0-9a-z\-]+@' . $universiteDomaine . '$/', $v);
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgDN"
     *
1148
     * @param array|string|Dn|StructureEntity|null $value
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
     * @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();
1162
            } elseif ($val instanceof StructureEntity) {
1163
1164
1165
1166
1167
1168
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1169
        $this->appendOrNot('eduPersonOrgDN', array_filter($value), $append);
1170
1171
1172
1173
1174
1175
1176

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgUnitDN"
     *
1177
     * @param array|string|Dn|StructureEntity|null $value
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
     * @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();
1191
            } elseif ($val instanceof StructureEntity) {
1192
1193
1194
1195
1196
1197
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1198
        $this->appendOrNot('eduPersonOrgUnitDN', array_filter($value), $append);
1199
1200
1201
1202
1203
1204
1205

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonPrimaryOrgUnitDN"
     *
1206
     * @param array|string|Dn|StructureEntity|null $value
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
     * @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();
1220
            } elseif ($val instanceof StructureEntity) {
1221
1222
1223
1224
1225
1226
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1227
        $this->appendOrNot('eduPersonPrimaryOrgUnitDN', array_filter($value), $append);
1228
1229
1230
1231

        return $this;
    }

1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
    /**
     * 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)) {
1247
                if (preg_match("/^" . $supannLabel . "[\w\-]+$/", $val)) {
1248
                    return $val;
1249
                } elseif (preg_match("/^[\w\-]+$/", $val)) {
1250
1251
                    return sprintf('%s%s', $supannLabel, $val);
                }
1252
            }
1253
            return null;
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
        }, $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) {
1276
            if (preg_match(self::$role_pattern, $v, $matches)) {
1277
1278
1279
1280
1281
                /**
                 * @var string $role
                 * @var string $type
                 * @var string $code
                 */
1282
                foreach (['role', 'type'] as $part) {
1283
                    $$part = preg_match("/^" . $supannLabel . "[\w\-]+$/", $matches[$part])
1284
1285
1286
1287
                        ? $matches[$part]
                        : sprintf('%s%s', $supannLabel, $matches[$part]);
                }

1288
                $prefixe = $this->service->getLdapStructureService()->getCodeStructurePrefixe();
1289
1290
1291
                $code