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

namespace UnicaenLdap\Entity\Base;

use DateTime;
use UnicaenLdap\Entity\Entity;
7
8
9
use UnicaenLdap\Entity\Structure;
use UnicaenLdap\Exception;
use Zend\Ldap\Dn;
10
11
12
13
14
use Zend\Ldap\Exception\LdapException;

/**
 * Classe mère des entités de la branche "people" de l'annuaire LDAP.
 *
15
 * @author David Surville <david.surville@unicaen.fr>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 */
class People extends Entity
{
    protected $type = 'People';

    /**
     * Liste des classes d'objet nécessaires à la création d'une personne
     * 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',
35
        'posixAccount',
36
37
        'sambaAccount',
        'sambaSamAcount',
38
39
        "schacPersonalCharacteristics",
        "schacEntryMetadata"
40
41
42
43
44
45
46
47
48
    ];

    /**
     * Liste des attributs contenant des dates
     *
     * @var array
     */
    protected $dateTimeAttributes = [];

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
    /**
     * Liste des attributs monovalués
     *
     * @var array
     */
    protected $monoValuedAttributes = [
        'cn',
        'dateDeNaissance',
        'displayName',
        'eduPersonOrgDN',
        'eduPersonPrimaryOrgUnitDN',
        'eduPersonPrincipalName',
        'givenName',
        'leoCode',
        'preferredLanguage',
        'schacDateOfBirth',
        'sexe',
        'supannAliasLogin',
        'supannCivilite',
        'supannCodeINE',
        'supannEmpId',
        'supannEntiteAffectationPrincipale',
        'supannEtuId',
        'supannListeRouge',
        'telephoneNumber',
    ];

76
77
78
    static protected $postal_address_pattern = '/(.*)\$(.*)\$(.*)\$(.*)\$(.*)\$(.*)/';
    static protected $role_pattern = '/^\[role=(?<role>.+)\]\[type=(?<type>.+)\]\[code=(?<code>.+)\]\[libelle=(?<libelle>.+)\]$/';
    static protected $role_src_pattern = '/^(?<code>[\d]{4});(?<libelle>.+)/';
79

80
81

    /**
82
83
     * Ajoute ou affecte une valeur à un attribut Ldap
     *
84
85
86
     * @param string $attrName
     * @param mixed $value
     * @param bool $append
87
88
     * @throws Exception
     * @throws LdapException
89
     */
90
    private function appendOrNot($attrName, $value, $append)
91
92
93
94
95
96
    {
        (!$append)
            ? $this->set($attrName, $value)
            : $this->add($attrName, $value);
    }

97
98
99
100
101
102
103
104
    /**
     * Vérifie une valeur et supprime les valeurs nulles
     *
     * @param mixed $value
     * @return array
     */
    private function preFormat($value)
    {
105
        if (is_scalar($value) || is_null($value)) {
106
107
108
109
110
111
112
113
            $value = [$value];
        }

        $value = array_filter($value);

        return $value;
    }

114
115
116
117
118
119
120
121
    /**
     * 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é
     *
122
     * @param array|string|null $value
123
124
     * @param bool $append
     * @return self
125
     * @throws Exception
126
127
     * @throws LdapException
     */
128
    public function setSn($value = null, $append = false)
129
    {
130
131
132
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('sn', $value, $append);
133
134
135
136
137
138
139

        return $this;
    }

    /**
     * Attribut Ldap "givenName"
     *
140
     * @param array|string|null $value
141
142
     * @param bool $append
     * @return self
143
     * @throws Exception
144
145
     * @throws LdapException
     */
146
    public function setGivenName($value = null, $append = false)
147
    {
148
149
150
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('givenName', $value, $append);
151
152
153
154
155
156
157

        return $this;
    }

    /**
     * Attribut Ldap "displayName"
     *
158
     * @param array|string|null $value
159
160
     * @param bool $append
     * @return self
161
     * @throws Exception
162
163
     * @throws LdapException
     */
164
    public function setDisplayName($value = null, $append = false)
165
    {
166
167
168
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value);
        $this->appendOrNot('displayName', $value, $append);
169
170
171
172
173
174
175

        return $this;
    }

    /**
     * Attribut Ldap "cn"
     *
176
     * @param array|string|null $value
177
178
     * @param bool $append
     * @return self
179
     * @throws Exception
180
181
     * @throws LdapException
     */
182
    public function setCn($value = null, $append = false)
183
    {
184
185
186
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatName'], $value, [true]);
        $this->appendOrNot('cn', $value, $append);
187
188
189
190
191
192
193

        return $this;
    }

    /**
     * Attribut Ldap "dateDeNaissance"
     *
194
     * @param array|string|null $value
195
196
     * @param bool $append
     * @return self
197
     * @throws Exception
198
199
     * @throws LdapException
     */
200
    public function setDateDeNaissance($value = null, $append = false)
201
    {
202
203
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
204
205
206
207
            if (is_string($val)) {
                $val = new DateTime($val);
            }
            return $val->format('Ymd');
208
        }, $value);
209

210
        $this->appendOrNot('dateDeNaissance', $value, $append);
211
212
213
214
215
216
217

        return $this;
    }

    /**
     * Attribut Ldap "schacDateOfBirth"
     *
218
     * @param array|string|null $value
219
220
     * @param bool $append
     * @return self
221
     * @throws Exception
222
223
     * @throws LdapException
     */
224
    public function setSchacDateOfBirth($value = null, $append = false)
225
    {
226
227
        $value = $this->preFormat($value);
        $value = array_map(function ($val) {
228
229
230
231
            if (is_string($val)) {
                $val = new DateTime($val);
            }
            return $val->format('Ymd');
232
        }, $value);
233

234
        $this->appendOrNot('schacDateOfBirth', $value, $append);
235
236
237
238
239
240
241

        return $this;
    }

    /**
     * Attribut Ldap "sexe"
     *
242
     * @param array|string|null $value
243
244
     * @param bool $append
     * @return self
245
     * @throws Exception
246
247
     * @throws LdapException
     */
248
    public function setSexe($value = null, $append = false)
249
    {
250
251
252
253
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['F', 'M']);
        });
254

255
        $this->appendOrNot('sexe', $value, $append);
256

257
        return $this;
258
259
260
261
262
    }

    /**
     * Attribut Ldap "postalAddress"
     *
263
     * @param array|string|null $value
264
265
     * @param bool $append
     * @return self
266
     * @throws Exception
267
268
     * @throws LdapException
     */
269
    public function setPostalAddress($value = null, $append = false)
270
    {
271
272
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
273
            return preg_match(self::$postal_address_pattern, $v);
274
275
        });

276
        $this->appendOrNot('postalAddress', $value, $append);
277
278
279
280
281
282
283

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

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

        return $this;
    }

    /**
     * Attribut Ldap "leoCode"
     *
356
     * @param array|string|null $value
357
358
     * @param bool $append
     * @return self
359
     * @throws Exception
360
361
     * @throws LdapException
     */
362
    public function setLeoCode($value = null, $append = false)
363
    {
364
365
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
366
367
368
            return preg_match('/^\d+$/', $v);
        });

369
        $this->appendOrNot('leoCode', $value, $append);
370
371
372
373
374
375
376

        return $this;
    }

    /**
     * Attribut Ldap "supannALiasLogin"
     *
377
     * @param array|string|null $value
378
379
     * @param bool $append
     * @return self
380
     * @throws Exception
381
382
     * @throws LdapException
     */
383
    public function setSupannAliasLogin($value = null, $append = false)
384
    {
385
386
387
        $value = $this->preFormat($value);
        $value = array_map('strtolower', $value);
        $value = array_filter($value, function ($v) {
388
389
390
            return preg_match('/^[0-9a-z\-]+$/', $v);
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEmpId"
     *
399
     * @param array|string|null $value
400
401
     * @param bool $append
     * @return self
402
     * @throws Exception
403
404
     * @throws LdapException
     */
405
    public function setSupannEmpId($value = null, $append = false)
406
    {
407
        $value = $this->preFormat($value);
408

409
410
411
        $this->appendOrNot('supannEmpId', $value, $append);

        return $this;
412
413
414
415
416
    }

    /**
     * Attribut Ldap "supannEtuId"
     *
417
     * @param array|string|null $value
418
419
     * @param bool $append
     * @return self
420
     * @throws Exception
421
422
     * @throws LdapException
     */
423
    public function setSupannEtuId($value = null, $append = false)
424
    {
425
        $value = $this->preFormat($value);
426

427
428
429
        $this->appendOrNot('supannEtuId', $value, $append);

        return $this;
430
431
432
433
434
    }

    /**
     * Attribut Ldap "supannCodeINE"
     *
435
     * @param array|string|null $value
436
437
     * @param bool $append
     * @return self
438
     * @throws Exception
439
440
     * @throws LdapException
     */
441
    public function setSupannCodeINE($value = null, $append = false)
442
    {
443
444
445
        $value = $this->preFormat($value);
        $value = array_map('strtoupper', $value);
        $value = array_filter($value, function ($v) {
446
447
448
            return preg_match('/^[0-9]{10}[A-Z]{1}$/', $v);
        });

449
        $this->appendOrNot('supannCodeINE', $value, $append);
450
451
452
453
454
455
456

        return $this;
    }

    /**
     * Attribut Ldap "supannCivilite"
     *
457
     * @param array|string|null $value
458
459
     * @param bool $append
     * @return self
460
     * @throws Exception
461
462
     * @throws LdapException
     */
463
    public function setSupannCivilite($value = null, $append = false)
464
    {
465
466
467
468
        $value = $this->preFormat($value);
        $value = array_filter($value, function ($v) {
            return in_array($v, ['Mme', 'M.']);
        });
469

470
        $this->appendOrNot('supannCivilite', $value, $append);
471

472
        return $this;
473
474
475
476
477
    }

    /**
     * Attribut Ldap "supannListeRouge"
     *
478
     * @param array|string|null $value
479
480
     * @param bool $append
     * @return self
481
     * @throws Exception
482
483
     * @throws LdapException
     */
484
    public function setSupannListeRouge($value = null, $append = false)
485
    {
486
487
488
        $value = $this->preFormat($value);
        $value = array_map([$this, 'formatBoolean'], $value);
        $this->appendOrNot('supannListeRouge', $value, $append);
489
490
491
492
493
494
495

        return $this;
    }

    /**
     * Attribut Ldap "supannMailPerso"
     *
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
     * @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"
     *
     * @param array|string|Structure|null $value
     * @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)) {
                return preg_match('/.+;.+/', $val) ? $val : null;
            } elseif ($val instanceof Structure) {
                return sprintf('%s;%s', substr($val->get('supannCodeEntite'), 3), $val->get('description'));
            } else {
                return null;
            }
        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectation"
     *
     * @param array|string|Structure|null $value
542
543
     * @param bool $append
     * @return self
544
     * @throws Exception
545
546
     * @throws LdapException
     */
547
    public function setSupannEntiteAffectation($value = null, $append = false)
548
    {
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
        $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;
            } elseif ($val instanceof Structure) {
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "supannEntiteAffectationPrincipale"
     *
     * @param array|string|Structure|null $value
     * @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;
            } elseif ($val instanceof Structure) {
                return $val->get('supannCodeEntite');
            } else {
                return null;
            }
        }, $value);

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

        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);
610
611
        $supannLabel = $this->getLabel('SUPANN');
        $value = array_map(function ($val) use ($supannLabel) {
612
            if (is_string($val)) {
613
                return preg_match("/^$supannLabel.*$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val);
614
            } else {
615
                return false;
616
617
618
            }
        }, $value);

619
        $this->appendOrNot('supannTypeEntiteAffectation', array_filter($value), $append);
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635

        return $this;
    }

    /**
     * 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);
636
637
638
        $value = array_map(function ($v) {
            list($identifiant, $domaine) = array_pad(explode('@', strtolower($v)), 2, null);
            if ($domaine != self::$etablissement_domaine) {
639
640
641
642
643
                $v = sprintf('%s@%s', $v, self::$etablissement_domaine);
            }
            return $v;
        }, $value);
        $value = array_filter($value, function ($v) {
644
            return preg_match('/^[0-9a-z\-]+@' . self::$etablissement_domaine . '$/', $v);
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
        });

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

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgDN"
     *
     * @param array|string|Dn|Structure|null $value
     * @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();
            } elseif ($val instanceof Structure) {
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonOrgUnitDN"
     *
     * @param array|string|Dn|Structure|null $value
     * @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();
            } elseif ($val instanceof Structure) {
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

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

        return $this;
    }

    /**
     * Attribut Ldap "eduPersonPrimaryOrgUnitDN"
     *
     * @param array|string|Dn|Structure|null $value
     * @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();
            } elseif ($val instanceof Structure) {
                return $val->getDn();
            } else {
                return null;
            }
        }, $value);

        $this->appendOrNot('eduPersonPrimaryOrgUnitDN', $value, $append);
735
736
737
738

        return $this;
    }

739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
    /**
     * 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)) {
                return preg_match("/^$supannLabel.*$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val);
            } else {
                return false;
            }
        }, $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) {
            if(preg_match(self::$role_pattern, $v, $matches)) {
                /**
                 * @var string $role
                 * @var string $type
                 * @var string $code
                 */
                foreach(['role', 'type'] as $part) {
                    $$part = preg_match("/^$supannLabel.*$/", $matches[$part])
                        ? $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);
            }
            else {
                return false;
            }

        }, $value);

        $this->appendOrNot('supannRoleEntite', 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 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;
    }

831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
    /**
     * 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');
    }
}