People.php 63.5 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
        'unicaenMonEtupass',
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
        'unicaenServiceAnnuaire',
        'unicaenServiceControleAcces',
        'unicaenServiceEmploiDuTemps',
        'unicaenServiceEspaceStockage',
        'unicaenServiceImpression',
        'unicaenServiceIntranet',
        'unicaenServiceMessageAlerte',
        'unicaenServiceMessagerie',
        'unicaenServicePosteTravail',
        'unicaenServiceReinscription',
        'unicaenServiceRessourcesDocumentaires',
        'unicaenServiceRestauration',
        'unicaenServiceImpression',
        'unicaenServiceWifiCampus',
        'unicaenServiceWifiEduroam',
176
177
        'unicaenTermsOfUse',
        'userCertificate',
178
        'userPassword',
179
180
    ];

181
182
183
184
185
    /**
     * Liste des attributs contenant des dates
     *
     * @var array
     */
186
187
188
    protected $dateTimeAttributes = [
        'schacExpiryDate',
    ];
189

190
191
192
193
194
195
196
197
    /**
     * Liste des attributs monovalués
     *
     * @var array
     */
    protected $monoValuedAttributes = [
        'cn',
        'dateDeNaissance',
198
        'dateFinInscription',
199
200
        'displayName',
        'eduPersonOrgDN',
201
        'eduPersonPrimaryAffiliation',
202
203
        'eduPersonPrimaryOrgUnitDN',
        'eduPersonPrincipalName',
204
        'gidNumber',
205
        'givenName',
206
        'homeDirectory',
207
        'leoCode',
208
209
        'loginShell',
        'ntPassword',
210
        'preferredLanguage',
211
212
213
        'rid',
        'sambaNTPassword',
        'sambaSID',
214
        'schacDateOfBirth',
215
        'schacExpiryDate',
216
217
218
219
220
221
222
223
224
        'sexe',
        'supannAliasLogin',
        'supannCivilite',
        'supannCodeINE',
        'supannEmpId',
        'supannEntiteAffectationPrincipale',
        'supannEtuId',
        'supannListeRouge',
        'telephoneNumber',
225
226
        'ucbnServiceADE',
        'ucbnServicePapercut',
227
        'ucbnSquidHash',
228
        'uidNumber',
229
        'userPassword',
230
231
    ];

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

    /**
     * Liste des valeurs autorisées pour l'attribut "ucbnStatus"
     *
     * @var array
     */
    protected $ucbnStatusAuthorizedValues = [
        'ALUMNI',
        'APPRENANT',
        'AUDITEUR_LIBRE',
        'CONTRACTUEL',
        'ETUDIANT',
281
        'HEBERGE',
282
283
284
285
286
        'INVITE',
        'LECTEUR_SCD',
        'TITULAIRE',
    ];

287
288
    /**
     * Liste des patterns spécifiques utilisés pour différents attributs
289
     */
290
    static protected $structure_pattern = '/^(?<code>[\w\-]+);(?<libelle>.+)$/';
291
292
293
294
295
    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\-:]+\}.+)\]' .
296
297
298
299
300
301
302
303
        '\[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\-:]+\}.+)\]$/';
304
305
306
307
308
309
310
311
312
    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>.+)\]$/';
313
    static protected $role_src_pattern = '/^(?<code>\d{4});(?<libelle>.+)$/';
314

315
316
317
318
319
320
321
322
323

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

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

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

414
        $this->appendOrNot('dateDeNaissance', $value, $append);
415
416
417
418
419
420
421

        return $this;
    }

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

438
        $this->appendOrNot('schacDateOfBirth', $value, $append);
439
440
441
442

        return $this;
    }

443
444
445
446
447
448
449
450
    /**
     * Attribut Ldap "dateFinInscription"
     *
     * @param array|string|DateTime|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
451
452
     * @deprecated Deprecated, use {@link self::setSchacExpiryDate}
     *
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
487
488
489
490
491
492
     */
    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;
    }

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

509
        $this->appendOrNot('sexe', $value, $append);
510

511
        return $this;
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
550
551
552
553
554
555
    /**
     * 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;
    }

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

572
        $this->appendOrNot('postalAddress', $value, $append);
573
574
575
576
577
578
579

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
    /**
     * 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;
    }

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
661
662
663
664
665
666
    /**
     * 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;
    }

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

        return $this;
    }

685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
    /**
     * 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;
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEmpId"
     *
767
     * @param array|string|null $value
768
769
     * @param bool $append
     * @return self
770
     * @throws Exception
771
772
     * @throws LdapException
     */
773
    public function setSupannEmpId($value = null, $append = false)
774
    {
775
776
777
778
        $value = $this->preFormat($value);
        $this->appendOrNot('supannEmpId', $value, $append);

        return $this;
779
780
781
782
783
    }

    /**
     * Attribut Ldap "supannEtuId"
     *
784
     * @param array|string|null $value
785
786
     * @param bool $append
     * @return self
787
     * @throws Exception
788
789
     * @throws LdapException
     */
790
    public function setSupannEtuId($value = null, $append = false)
791
    {
792
793
794
795
        $value = $this->preFormat($value);
        $this->appendOrNot('supannEtuId', $value, $append);

        return $this;
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
832
833
834
835
836
837
    /**
     * 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]);
                }

838
                $prefixe = $this->service->getLdapStructureService()->getCodeStructurePrefixe();
839
840
841
842
                $affect = (0 !== strpos($matches['affect'], $prefixe))
                    ? sprintf('%s%s', $structure_prefixe, $matches['affect'])
                    : $matches['affect'];

843
                $prefixe = $this->service->getLdapStructureService()->getCodeModuleEnseignementPrefixe();
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
                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;
    }

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

882
        $this->appendOrNot('supannCodeINE', $value, $append);
883
884
885
886
887
888
889

        return $this;
    }

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

903
        $this->appendOrNot('supannCivilite', $value, $append);
904

905
        return $this;
906
907
908
909
910
    }

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

        return $this;
    }

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

967
        $this->appendOrNot('supannAffectation', array_filter($value), $append);
968
969
970
971
972
973
974

        return $this;
    }

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

997
        $this->appendOrNot('supannEntiteAffectation', array_filter($value), $append);
998
999
1000
1001
1002
1003
1004

        return $this;
    }

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

1027
        $this->appendOrNot('supannEntiteAffectationPrincipale', array_filter($value), $append);
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043

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

1056
        $this->appendOrNot('supannTypeEntiteAffectation', array_filter($value), $append);
1057
1058
1059
1060

        return $this;
    }

1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
    /**
     * 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;
    }

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

1105
        $this->appendOrNot('ucbnSousStructure', array_filter($value), $append);
1106
1107
1108
1109
1110
1111
1112

        return $this;
    }

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

1133
        $this->appendOrNot('ucbnStructureRecherche', array_filter($value), $append);
1134
1135
1136
1137

        return $this;
    }

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

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

        return $this;
    }

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

1191
        $this->appendOrNot('eduPersonOrgDN', array_filter($value), $append);
1192
1193
1194
1195
1196
1197
1198

        return $this;
    }

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

1220
        $this->appendOrNot('eduPersonOrgUnitDN', array_filter($value), $append);
1221
1222
1223
1224
1225
1226
1227

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonPrimaryOrgUnitDN"
     *
1228
     * @param array|string|Dn|StructureEntity|null $value
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
     * @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();
1242
            } elseif ($val instanceof StructureEntity) {
1243
1244
1245
1246
1247
1248
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1249
        $this->appendOrNot('eduPersonPrimaryOrgUnitDN', array_filter($value), $append);
1250
1251
1252
1253

        return $this;
    }

1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
    /**
     * 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)) {
1269
                if (preg_match("/^" . $supannLabel . "[\w\-]+$/", $val)) {
1270
                    return $val;
1271
                } elseif (preg_match("/^[\w\-]+$/", $val)) {
1272
1273
                    return sprintf('%s%s', $supannLabel, $val);
                }
1274
            }
1275
            return null;
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293