People.php 43.2 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
10
use UnicaenLdap\Exception;
use Zend\Ldap\Dn;
11
12
13
14
15
use Zend\Ldap\Exception\LdapException;

/**
 * Classe mère des entités de la branche "people" de l'annuaire LDAP.
 *
16
 * @author David Surville <david.surville@unicaen.fr>
17
18
19
20
21
22
 */
class People extends Entity
{
    protected $type = 'People';

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

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
    /**
     * Liste des attributs autorisés pour une entité "People"
     *
     * @var array
     */
    protected $authorizedAttributes = [
        // Attributes classes
        'objectClass',
        // Attributes
        'cn',
        'displayName',
        'dateDeNaissance',
        'eduPersonPrincipalName',
        'eduPersonNickname', // no getter and setter
        'eduPersonAffiliation',
        'eduPersonPrimaryAffiliation',
        'eduPersonOrgDN',
        'eduPersonOrgUnitDN',
        'eduPersonPrimaryOrgUnitDN',
        'dateFinInscription',
        'facsimileTelephoneNumber', // no getter and setter
        'gidNumber',
        'givenName',
        'homeDirectory',
        'labeledURI', // no getter and setter
        'leoCode',
        'loginShell',
        'mail',
        'mobile',
        'pager',
        'postalAddress',
        'preferredLanguage',
        'rid',
        'sambaSID',
        'schacDateOfBirth',
        'schacExpiryDate',
        'sexe',
        'sn',
        'supannActivite',
        'supannAffectation',
        'supannAliasLogin',
        'supannAutreTelephone',
        'supannCivilite',
        'supannCodeINE',
        'supannEmpCorps',
        'supannEmpId',
        'supannEntiteAffectation',
        'supannEntiteAffectationPrincipale',
        'supannEtablissement',
        'supannEtuAnneeInscription',
        'supannEtuCursusAnnee',
        'supannEtuDiplome',
        'supannEtuElementPedagogique',
        'supannEtuEtape',
        'supannEtuId',
        'supannEtuInscription',
        'supannEtuRegimeInscription',
        'supannEtuSecteurDisciplinaire',
        'supannEtuTypeDiplome',
        'supannListeRouge',
        'supannMailPerso',
        'supannParrainDN',
        'supannRoleGenerique',
        'supannRoleEntite',
        'supannRefId',
        'supannTypeEntiteAffectation',
        'telephoneNumber',
        'title', // no getter and setter
        'ucbnAnneePostBac',
        'ucbnCodeEtape',
        'ucbnEtuComplementInscription',
        'ucbnFonctionStructurelle',
        'ucbnOrganisme',
        'ucbnPrivateAddress',
        'ucbnPrivateAddressBis',
        'ucbnSecteurDisciplinaire',
        'ucbnServiceADE',
        'ucbnServicePapercut',
        'ucbnSiteLocalisation',
        'ucbnSousStructure',
        'ucbnStatus',
        'ucbnStructureRecherche',
        'unicaenMonEtupass',
        'unicaenTermsOfUse',
        'userCertificate',
        'uidNumber',
    ];

133
134
135
136
137
    /**
     * Liste des attributs contenant des dates
     *
     * @var array
     */
138
139
140
    protected $dateTimeAttributes = [
        'schacExpiryDate',
    ];
141

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

178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
    /**
     * Liste des valeurs autorisées pour les attributs "eduPersonAffiliation" et "eduPersonPrimaryAffiliation"
     *
     * - affiliate : personne qui ne dépend pas de l'établissement (exemple : un partenaire extérieur). La valeur
     * "member" est exclue pour ces personnes.
     * - alum : ancien étudiant conservant des relations avec l'établissement.
     * - emeritus :  professeur ayant obtenu l'éméritat dans l'établissement.
     * - employee : tout personnel rémunéré par l'établissement, quelque soit son activité.
     * - faculty : personnel dont l'activité principale (dans l'établissement) est pédagogique, d'enseignement ou/et de
     * recherche. La valeur “member” est positionnée si ce personnel est géré par l'établissement.
     * - member : personne inscrite dans la (les) base(s) de gestion des étudiants ou celle(s) des personnels.
     * - registered-reader : lecteur de bibliothèque autorisé.
     * - researcher : personne assurant une activité de recherche. La valeur “member” est positionnée si ce personnel
     * est géré par l'établissement.
     * - retired :  personne à la retraite conservant des relations avec l'établissement.
     * - staff : personnel dont l'activité principale (dans l'établissement) est autre qu'enseignant ou chercheur
     * (typiquement BIATOS).
     * - student : personne suivant une formation quelconque dans l'établissement. Si la valeur “member” est positionnée,
     * la personne est enregistrée dans la base des étudiants.
     * - teacher : personnel assurant une activité d'enseignement.
     *
     * @var array
     */
    protected $eduPersonAffiliationAuthorizedValues = [
        'affiliate',
        'alum',
        'emeritus',
        'employee',
        'faculty',
        'member',
        'registered-reader',
        'researcher',
        'retired',
        'staff',
        'student',
        'teacher',
    ];

    /**
     * Liste des valeurs autorisées pour l'attribut "ucbnStatus"
     *
     * @var array
     */
    protected $ucbnStatusAuthorizedValues = [
        'ALUMNI',
        'APPRENANT',
        'AUDITEUR_LIBRE',
        'CONTRACTUEL',
        'ETUDIANT',
227
        'HEBERGE',
228
229
230
231
232
        'INVITE',
        'LECTEUR_SCD',
        'TITULAIRE',
    ];

233
234
    /**
     * Liste des patterns spécifiques utilisés pour différents attributs
235
     */
236
    static protected $structure_pattern = '/^(?<code>[\w\-]+);(?<libelle>.+)$/';
237
    static protected $secteur_disciplinaire_pattern = '/^(?<code>[\d]+);(?<libelle>.+)$/';
238
    static protected $role_pattern = '/^\[role=(?<role>[\w\-]+)\]\[type=(?<type>[\w\-]+)\]\[code=(?<code>[\w\-]+)\]\[libelle=(?<libelle>.+)\]$/';
239
    static protected $role_src_pattern = '/^(?<code>[\d]{4});(?<libelle>.+)$/';
240

241
242
243
244
245
246
247
248
249

    /**
     * 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é
     *
250
     * @param array|string|null $value
251
252
     * @param bool $append
     * @return self
253
     * @throws Exception
254
255
     * @throws LdapException
     */
256
    public function setSn($value = null, $append = false)
257
    {
258
259
260
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('sn', $value, $append);
261
262
263
264
265
266
267

        return $this;
    }

    /**
     * Attribut Ldap "givenName"
     *
268
     * @param array|string|null $value
269
270
     * @param bool $append
     * @return self
271
     * @throws Exception
272
273
     * @throws LdapException
     */
274
    public function setGivenName($value = null, $append = false)
275
    {
276
277
278
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('givenName', $value, $append);
279
280
281
282
283
284
285

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

    /**
     * Attribut Ldap "dateDeNaissance"
     *
322
323
324
     * @deprecated Deprecated, use {@link self::setSchacDateOfBirth}
     *
     * @param array|string|DateTime|null $value
325
326
     * @param bool $append
     * @return self
327
     * @throws Exception
328
329
     * @throws LdapException
     */
330
    public function setDateDeNaissance($value = null, $append = false)
331
    {
332
333
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
334
335
336
337
            if (is_string($val)) {
                $val = new DateTime($val);
            }
            return $val->format('Ymd');
338
        }, $value);
339

340
        $this->appendOrNot('dateDeNaissance', $value, $append);
341
342
343
344
345
346
347

        return $this;
    }

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

364
        $this->appendOrNot('schacDateOfBirth', $value, $append);
365
366
367
368

        return $this;
    }

369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
    /**
     * Attribut Ldap "dateFinInscription"
     *
     * @deprecated Deprecated, use {@link self::setSchacExpiryDate}
     *
     * @param array|string|DateTime|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setDateFinInscription($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                $val = new DateTime($val);
            }
            return $val->format('Ymd');
        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "schacDateOfBirth"
     *
     * @param array|string|DateTime|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSchacExpiryDate($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                $val = new DateTime($val, new \DateTimeZone('+0000')); // définition du timezone à +0h
            }
            return (int)$val->format('U');
        }, $value);

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

        return $this;
    }

419
420
421
    /**
     * Attribut Ldap "sexe"
     *
422
     * @param array|string|null $value
423
424
     * @param bool $append
     * @return self
425
     * @throws Exception
426
427
     * @throws LdapException
     */
428
    public function setSexe($value = null, $append = false)
429
    {
430
431
432
433
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['F', 'M']);
        });
434

435
        $this->appendOrNot('sexe', $value, $append);
436

437
        return $this;
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
471
472
473
474
475
476
477
478
479
480
481
    /**
     * 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;
    }

482
483
484
    /**
     * Attribut Ldap "postalAddress"
     *
485
     * @param array|string|null $value
486
487
     * @param bool $append
     * @return self
488
     * @throws Exception
489
490
     * @throws LdapException
     */
491
    public function setPostalAddress($value = null, $append = false)
492
    {
493
494
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
495
            return preg_match(self::$postal_address_pattern, $v);
496
497
        });

498
        $this->appendOrNot('postalAddress', $value, $append);
499
500
501
502
503
504
505

        return $this;
    }

    /**
     * Attribut Ldap "telephoneNumber"
     *
506
     * @param array|string|null $value
507
508
     * @param bool $append
     * @return self
509
     * @throws Exception
510
511
     * @throws LdapException
     */
512
    public function setTelephoneNumber($value = null, $append = false)
513
    {
514
515
516
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatTel'], $value);
        $this->appendOrNot('telephoneNumber', $value, $append);
517
518
519
520
521
522
523

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

    /**
     * Attribut Ldap "leoCode"
     *
578
     * @param array|string|null $value
579
580
     * @param bool $append
     * @return self
581
     * @throws Exception
582
583
     * @throws LdapException
     */
584
    public function setLeoCode($value = null, $append = false)
585
    {
586
587
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
588
589
590
            return preg_match('/^\d+$/', $v);
        });

591
        $this->appendOrNot('leoCode', $value, $append);
592
593
594
595
596
597
598

        return $this;
    }

    /**
     * Attribut Ldap "supannALiasLogin"
     *
599
     * @param array|string|null $value
600
601
     * @param bool $append
     * @return self
602
     * @throws Exception
603
604
     * @throws LdapException
     */
605
    public function setSupannAliasLogin($value = null, $append = false)
606
    {
607
608
609
        $value = $this->preFormat($value);
        $value = array_map('strtolower', $value);
        $value = array_filter($value, function ($v) {
610
611
612
            return preg_match('/^[0-9a-z\-]+$/', $v);
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEmpId"
     *
621
     * @param array|string|null $value
622
623
     * @param bool $append
     * @return self
624
     * @throws Exception
625
626
     * @throws LdapException
     */
627
    public function setSupannEmpId($value = null, $append = false)
628
    {
629
630
631
632
        $value = $this->preFormat($value);
        $this->appendOrNot('supannEmpId', $value, $append);

        return $this;
633
634
635
636
637
    }

    /**
     * Attribut Ldap "supannEtuId"
     *
638
     * @param array|string|null $value
639
640
     * @param bool $append
     * @return self
641
     * @throws Exception
642
643
     * @throws LdapException
     */
644
    public function setSupannEtuId($value = null, $append = false)
645
    {
646
647
648
649
        $value = $this->preFormat($value);
        $this->appendOrNot('supannEtuId', $value, $append);

        return $this;
650
651
652
653
654
    }

    /**
     * Attribut Ldap "supannCodeINE"
     *
655
     * @param array|string|null $value
656
657
     * @param bool $append
     * @return self
658
     * @throws Exception
659
660
     * @throws LdapException
     */
661
    public function setSupannCodeINE($value = null, $append = false)
662
    {
663
664
665
        $value = $this->preFormat($value);
        $value = array_map('strtoupper', $value);
        $value = array_filter($value, function ($v) {
666
667
668
            return preg_match('/^[0-9]{10}[A-Z]{1}$/', $v);
        });

669
        $this->appendOrNot('supannCodeINE', $value, $append);
670
671
672
673
674
675
676

        return $this;
    }

    /**
     * Attribut Ldap "supannCivilite"
     *
677
     * @param array|string|null $value
678
679
     * @param bool $append
     * @return self
680
     * @throws Exception
681
682
     * @throws LdapException
     */
683
    public function setSupannCivilite($value = null, $append = false)
684
    {
685
686
687
688
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['Mme', 'M.']);
        });
689

690
        $this->appendOrNot('supannCivilite', $value, $append);
691

692
        return $this;
693
694
695
696
697
    }

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

        return $this;
    }

    /**
     * Attribut Ldap "supannMailPerso"
     *
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
     * @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"
     *
734
     * @param array|string|StructureEntity|null $value
735
736
737
738
739
740
741
742
743
744
     * @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)) {
745
746
747
748
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->getService()->getCodeStructurePrefixe(), ''), $val->get('description'));
                return preg_match(self::$structure_pattern, $val) ? $val : null;
749
750
751
752
753
            } else {
                return null;
            }
        }, $value);

754
        $this->appendOrNot('supannAffectation', array_filter($value), $append);
755
756
757
758
759
760
761

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectation"
     *
762
     * @param array|string|StructureEntity|null $value
763
764
     * @param bool $append
     * @return self
765
     * @throws Exception
766
767
     * @throws LdapException
     */
768
    public function setSupannEntiteAffectation($value = null, $append = false)
769
    {
770
771
772
773
774
775
776
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                if (0 !== strpos($val, $this->getService()->getCodeStructurePrefixe())) {
                    $val = $this->getService()->getCodeStructurePrefixe() . $val;
                }
                return $val;
777
            } elseif ($val instanceof StructureEntity) {
778
779
780
781
782
783
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

784
        $this->appendOrNot('supannEntiteAffectation', array_filter($value), $append);
785
786
787
788
789
790
791

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectationPrincipale"
     *
792
     * @param array|string|StructureEntity|null $value
793
794
795
796
797
798
799
800
801
802
803
804
805
806
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEntiteAffectationPrincipale($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                if (0 !== strpos($val, $this->getService()->getCodeStructurePrefixe())) {
                    $val = $this->getService()->getCodeStructurePrefixe() . $val;
                }
                return $val;
807
            } elseif ($val instanceof StructureEntity) {
808
809
810
811
812
813
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

814
        $this->appendOrNot('supannEntiteAffectationPrincipale', array_filter($value), $append);
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830

        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);
831
832
        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($val) use ($supannLabel) {
833
            if (is_string($val)) {
834
                return preg_match("/^$supannLabel.+$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val);
835
            } else {
836
                return null;
837
838
839
            }
        }, $value);

840
        $this->appendOrNot('supannTypeEntiteAffectation', array_filter($value), $append);
841
842
843
844

        return $this;
    }

845
846
847
    /**
     * Attribut Ldap "ucbnSousStructure"
     *
848
     * @param array|string|StructureEntity|null $value
849
850
851
852
853
854
855
856
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnSousStructure($value = null, $append = false)
    {
        $value = $this->preFormat($value);
857
858
859
860
861
862
863
864
865
866
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->getService()->getCodeStructurePrefixe(), ''), $val->get('description'));
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);
867

868
        $this->appendOrNot('ucbnSousStructure', array_filter($value), $append);
869
870
871
872
873
874
875

        return $this;
    }

    /**
     * Attribut Ldap "ucbnStructureRecherche"
     *
876
     * @param array|string|StructureEntity|null $value
877
878
879
880
881
882
883
884
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnStructureRecherche($value = null, $append = false)
    {
        $value = $this->preFormat($value);
885
886
887
888
889
890
891
892
893
894
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } elseif ($val instanceof StructureEntity) {
                $val = sprintf('%s;%s', strtr($val->get('supannCodeEntite'), $this->getService()->getCodeStructurePrefixe(), ''), $val->get('description'));
                return preg_match(self::$structure_pattern, $val) ? $val : null;
            } else {
                return null;
            }
        }, $value);
895

896
        $this->appendOrNot('ucbnStructureRecherche', array_filter($value), $append);
897
898
899
900

        return $this;
    }

901
902
903
904
905
906
907
908
909
910
911
912
    /**
     * Attribut Ldap "eduPersonPrincipalName"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setEduPersonPrincipalName($value = null, $append = false)
    {
        $value = $this->preFormat($value);
913
914
915
        $value = array_map(function ($v) {
            list($identifiant, $domaine) = array_pad(explode('@', strtolower($v)), 2, null);
            if ($domaine != self::$etablissement_domaine) {
916
917
918
919
920
                $v = sprintf('%s@%s', $v, self::$etablissement_domaine);
            }
            return $v;
        }, $value);
        $value = array_filter($value, function ($v) {
921
            return preg_match('/^[0-9a-z\-]+@' . self::$etablissement_domaine . '$/', $v);
922
923
924
925
926
927
928
929
930
931
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgDN"
     *
932
     * @param array|string|Dn|StructureEntity|null $value
933
934
935
936
937
938
939
940
941
942
943
944
945
     * @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();
946
            } elseif ($val instanceof StructureEntity) {
947
948
949
950
951
952
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

953
        $this->appendOrNot('eduPersonOrgDN', array_filter($value), $append);
954
955
956
957
958
959
960

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgUnitDN"
     *
961
     * @param array|string|Dn|StructureEntity|null $value
962
963
964
965
966
967
968
969
970
971
972
973
974
     * @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();
975
            } elseif ($val instanceof StructureEntity) {
976
977
978
979
980
981
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonPrimaryOrgUnitDN"
     *
990
     * @param array|string|Dn|StructureEntity|null $value
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
     * @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();
1004
            } elseif ($val instanceof StructureEntity) {
1005
1006
1007
1008
1009
1010
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

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

        return $this;
    }

1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
    /**
     * 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)) {
1031
                return preg_match("/^$supannLabel.+$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val);
1032
            } else {
1033
                return null;
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
            }
        }, $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) {
1057
            if (preg_match(self::$role_pattern, $v, $matches)) {
1058
1059
1060
1061
1062
                /**
                 * @var string $role
                 * @var string $type
                 * @var string $code
                 */
1063
                foreach (['role', 'type'] as $part) {
1064
                    $$part = preg_match("/^$supannLabel.+$/", $matches[$part])
1065
1066
1067
1068
1069
1070
1071
1072
1073
                        ? $matches[$part]
                        : sprintf('%s%s', $supannLabel, $matches[$part]);
                }

                $prefixe = $this->getService()->getCodeStructurePrefixe();
                $code = (0 !== strpos($matches['code'], $prefixe))
                    ? sprintf('%s%s', $prefixe, $matches['code'])
                    : $matches['code'];
                return preg_replace(self::$role_pattern, "[role=$role][type=$type][code=$code][libelle=\\4]", $v, 1);
1074
            } else {
1075
                return null;
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
            }

        }, $value);

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

        return $this;
    }

    /**
1086
     * Attribut Ldap "ucbnFonctionStructurelle"
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnFonctionStructurelle($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$role_src_pattern, $v);

        });

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

        return $this;
    }

1107
1108
1109
    /**
     * Attribut Ldap "supannParrainDN"
     *
1110
     * @param array|string|Dn|PeopleEntity|null $value
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannParrainDN($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
            if (is_string($val)) {
                return Dn::checkDn($val) ? $val : null;
            } elseif ($val instanceof Dn) {
                return $val->toString();
1124
            } elseif ($val instanceof PeopleEntity) {
1125
1126
1127
1128
1129
1130
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

1131
        $this->appendOrNot('supannParrainDN', array_filter($value), $append);
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148

        return $this;
    }

    /**
     * Attribut Ldap "supannRefId"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannRefId($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
1149
            return preg_match(self::$attribute_with_label_pattern, $v);
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
        });

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

        return $this;
    }

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

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

        return $this;
    }

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

        return $this;
    }

1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
    /**
     * Attribut Ldap "supannActivite"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannActivite($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$attribute_with_label_pattern, $v);
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "ucbnSecteurDisciplinaire"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnSecteurDisciplinaire($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$secteur_disciplinaire_pattern, $v);

        });

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEmpCorps"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEmpCorps($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $corpsLabel = $this->getLabel('NCORPS');
        $value = array_map(function ($val) use ($corpsLabel) {
            if (is_string($val)) {
                return preg_match("/^$corpsLabel.+$/", $val) ? $val : sprintf('%s%s', $corpsLabel, $val);
            } else {
                return null;
            }
        }, $value);

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

        return $this;
    }

1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
    /**
     * Attribut Ldap "supannEtablissement"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEtablissement($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$attribute_with_label_pattern, $v);
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEtuAnneeInscription"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEtuAnneeInscription($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match('/\d{4}/', $v);
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEtuCursusAnnee"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEtuCursusAnnee($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($val) use ($supannLabel) {
            if (is_string($val)) {
                return preg_match("/^".$supannLabel."[\d]{4}$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val);
            } else {
                return null;
            }
        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEtuDiplome"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEtuDiplome($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$attribute_with_label_pattern, $v);
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEtuEtape"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSupannEtuEtape($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match(self::$attribute_with_label_pattern, $v);
        });

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

        return $this;
    }

1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
    /**
     * Attribut Ldap "rid"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setRid($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match('/[0-9]+/', $v);
        });
        $this->appendOrNot('rid', $value, $append);

        return $this;
    }

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

        return $this;
    }

    /**
     * Attribut Ldap "uidNumber"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setUidNumber($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match('/[0-9]+/', $v);
        });
        $this->appendOrNot('uidNumber', $value, $append);

        return $this;
    }

    /**
     * Attribut Ldap "gidNumber"
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setGidNumber($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return preg_match('/[0-9]+/', $v);
        });
        $this->appendOrNot('gidNumber', $value, $append);

        return $this;
    }

    /**
     * Attribut Ldap "loginShell"
     * @todo tester le format
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setLoginShell($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $this->appendOrNot('loginShell', $value, $append);

        return $this;
    }

    /**
     * Attribut Ldap "homeDirectory"
     * @todo tester le format
     *
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setHomeDirectory($value = null, $append = false)
    {
        $value = $this->preFormat($value);
        $this->appendOrNot('homeDirectory', $value, $append);

        return $this;
    }

1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
    /**
     * Retourne les structures auxquelles appartiennent la personne
     *
     * @return Structure[]
     */
    public function getEduPersonOrgUnit()
    {
        $structure = $this->getService()->getServiceLocator()->get('ldapServiceStructure');
        $dn = $this->eduPersonOrgUnitDN;
        if (empty($dn)) return null;

        return $structure->getAllBy($dn, 'dn');
    }

    /**
     * Retourne la structure principale à laquelle appartient la personne
     *
     * @return Structure
     */
    public function getEduPersonPrimaryOrgUnit()
    {
        $structure = $this->getService()->getServiceLocator()->get('ldapServiceStructure');
        $dn = $this->eduPersonPrimaryOrgUnitDN;
        if (empty($dn)) return null;

        return $structure->getBy($dn, 'dn');
    }

    /**
     * Retourne la structure d'affectation de la personne
     *
     * @todo à terminer
     * @return Structure[]
     * @throws \Exception
     */
    public function getSupannEntiteAffectation()
    {
        throw new \Exception('Méthode pas finie');
        $structure = $this->getService()->getServiceLocator()->get('ldapServiceStructure');
        $codes = $this->getNode()->getAttribute('supannEntiteAffectation');
        var_dump($codes);

        return $structure->getBy($dn, 'dn');
    }

    /**
     * Retourne la structure d'affectation de la personne
     *
     * @todo à terminer
     * @return Structure
     * @throws \Exception
     */
    public function getSupannEntiteAffectationPrincipale()
    {
        throw new \Exception('Méthode pas finie');
        $structure = $this->getService()->getServiceLocator()->get('ldapServiceStructure');

        $codes = [];
        $affectations = $this->getNode()->getAttribute('supannAffectation');


        list($code, $description) = explode(';', $this->supannAffectation);
        $code = $this->supannAffectation;
        if (empty($dn)) return null;

        return $structure->getBy($dn, 'dn');
    }
}