Usuario::getEsOrientador()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/*
3
  GESTCONV - Aplicación web para la gestión de la convivencia en centros educativos
4
5
  Copyright (C) 2015: Luis Ramón López López
6
7
  This program is free software: you can redistribute it and/or modify
8
  it under the terms of the GNU Affero General Public License as published by
9
  the Free Software Foundation, either version 3 of the License, or
10
  (at your option) any later version.
11
12
  This program is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
  GNU Affero General Public License for more details.
16
17
  You should have received a copy of the GNU Affero General Public License
18
  along with this program.  If not, see [http://www.gnu.org/licenses/].
19
*/
20
21
namespace AppBundle\Entity;
22
23
24
use Doctrine\Common\Collections\ArrayCollection;
25
use Doctrine\Common\Collections\Collection;
26
use Doctrine\ORM\Mapping as ORM;
27
use Symfony\Component\Security\Core\Role\Role;
28
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
29
30
31
/**
32
 * @ORM\Entity(repositoryClass="AppBundle\Entity\UsuarioRepository")
33
 */
34
class Usuario implements AdvancedUserInterface
35
{
36
    /**
37
     * @ORM\Id
38
     * @ORM\Column(type="integer")
39
     * @ORM\GeneratedValue
40
     */
41
    protected $id;
42
43
    /**
44
     * @ORM\Column(type="string")
45
     * @var string
46
     */
47
    protected $nombreUsuario;
48
49
    /**
50
     * @ORM\Column(type="string")
51
     * @var string
52
     */
53
    protected $password;
54
55
    /**
56
     * @ORM\Column(type="string")
57
     * @var string
58
     */
59
    protected $nombre;
60
61
    /**
62
     * @ORM\Column(type="string")
63
     * @var string
64
     */
65
    protected $apellidos;
66
67
    /**
68
     * @ORM\Column(type="string", nullable=true)
69
     * @var string
70
     */
71
    protected $email;
72
73
    /**
74
     * @ORM\Column(type="boolean", options={"default": true})
75
     * @var boolean
76
     */
77
    protected $notificaciones;
78
79
    /**
80
     * @ORM\Column(type="boolean", options={"default": false})
81
     * @var boolean
82
     */
83
    protected $esAdministrador;
84
85
    /**
86
     * @ORM\Column(type="boolean", options={"default": false})
87
     * @var boolean
88
     */
89
    protected $esRevisor;
90
91
    /**
92
     * @ORM\Column(type="boolean", options={"default": false})
93
     * @var boolean
94
     */
95
    protected $esDirectivo;
96
97
    /**
98
     * @ORM\Column(type="boolean", options={"default": false})
99
     * @var boolean
100
     */
101
    protected $esOrientador;
102
103
    /**
104
     * @ORM\Column(type="boolean", options={"default": true})
105
     * @var boolean
106
     */
107
    protected $estaActivo;
108
109
    /**
110
     * @ORM\Column(type="boolean", options={"default": false})
111
     * @var boolean
112
     */
113
    protected $estaBloqueado;
114
115
    /**
116
     * @ORM\ManyToOne(targetEntity="Grupo", inversedBy="tutores")
117
     * @var Grupo
118
     */
119
    protected $tutoria = null;
120
121
    /**
122
     * @ORM\OneToMany(targetEntity="Parte", mappedBy="usuario")
123
     * @var Collection
124
     */
125
    protected $partes = null;
126
127
    /**
128
     * @ORM\OneToMany(targetEntity="Sancion", mappedBy="usuario")
129
     * @var Collection
130
     */
131
    protected $sanciones = null;
132
133
    /**
134
     * @ORM\Column(type="boolean", options={"default": false})
135
     * @var boolean
136
     */
137
    protected $esExterno;
138
139
    /**
140
     * Constructor
141
     */
142
    public function __construct()
143
    {
144
        $this->partes = new ArrayCollection();
145
        $this->sanciones = new ArrayCollection();
146
    }
147
148
    /**
149
     *
150
     * @return int
151
     */
152
    public function getId()
153
    {
154
        return $this->id;
155
    }
156
157
    /**
158
     *
159
     * @return string
160
     */
161
    public function getApellidos()
162
    {
163
        return $this->apellidos;
164
    }
165
166
    /**
167
     *
168
     * @param string $valor
169
     * @return Usuario
170
     */
171
    public function setApellidos($valor)
172
    {
173
        $this->apellidos = $valor;
174
175
        return $this;
176
    }
177
178
179
    /**
180
     *
181
     * @return string
182
     */
183
    public function getEmail()
184
    {
185
        return $this->email;
186
    }
187
188
    /**
189
     *
190
     * @param string|null $valor
191
     * @return Usuario
192
     */
193
    public function setEmail($valor)
194
    {
195
        $this->email = $valor;
196
197
        return $this;
198
    }
199
200
    /**
201
     *
202
     * @return string
203
     */
204
    public function __toString() {
205
        return $this->getApellidos() . ', ' . $this->getNombre();
206
    }
207
208
    /**
209
     *
210
     * @return string
211
     */
212
    public function getNombre()
213
    {
214
        return $this->nombre;
215
    }
216
217
    /**
218
     *
219
     * @param string $valor
220
     * @return Usuario
221
     */
222
    public function setNombre($valor)
223
    {
224
        $this->nombre = $valor;
225
226
        return $this;
227
    }
228
229
    /**
230
     * Get tutoria
231
     *
232
     * @return Grupo
233
     */
234
    public function getTutoria()
235
    {
236
        return $this->tutoria;
237
    }
238
239
    /**
240
     *
241
     * @param Grupo|null $tutoria
242
     * @return Usuario
243
     */
244
    public function setTutoria($tutoria)
245
    {
246
        $this->tutoria = $tutoria;
247
248
        return $this;
249
    }
250
251
    /**
252
     * Add partes
253
     *
254
     * @param Parte $partes
255
     * @return Usuario
256
     */
257
    public function addParte(Parte $partes)
258
    {
259
        $this->partes[] = $partes;
260
261
        return $this;
262
    }
263
264
    /**
265
     * Remove partes
266
     *
267
     * @param Parte $partes
268
     */
269
    public function removeParte(Parte $partes)
270
    {
271
        $this->partes->removeElement($partes);
272
    }
273
274
    /**
275
     * Get partes
276
     *
277
     * @return Collection
278
     */
279
    public function getPartes()
280
    {
281
        return $this->partes;
282
    }
283
284
    /**
285
     * Get notificaciones
286
     *
287
     * @return boolean
288
     */
289
    public function getNotificaciones()
290
    {
291
        return $this->notificaciones;
292
    }
293
294
    /**
295
     * Set notificaciones
296
     *
297
     * @param boolean $notificaciones
298
     * @return Usuario
299
     */
300
    public function setNotificaciones($notificaciones)
301
    {
302
        $this->notificaciones = $notificaciones;
303
304
        return $this;
305
    }
306
307
    /**
308
     * Get esAdministrador
309
     *
310
     * @return boolean
311
     */
312
    public function getEsAdministrador()
313
    {
314
        return $this->esAdministrador;
315
    }
316
317
    /**
318
     * Set esAdministrador
319
     *
320
     * @param boolean $esAdministrador
321
     * @return Usuario
322
     */
323
    public function setEsAdministrador($esAdministrador)
324
    {
325
        $this->esAdministrador = $esAdministrador;
326
327
        return $this;
328
    }
329
330
    /**
331
     * Get esRevisor
332
     *
333
     * @return boolean
334
     */
335
    public function getEsRevisor()
336
    {
337
        return $this->esRevisor;
338
    }
339
340
    /**
341
     * Set esRevisor
342
     *
343
     * @param boolean $esRevisor
344
     * @return Usuario
345
     */
346
    public function setEsRevisor($esRevisor)
347
    {
348
        $this->esRevisor = $esRevisor;
349
350
        return $this;
351
    }
352
353
    /**
354
     * Get esOrientador
355
     *
356
     * @return boolean
357
     */
358
    public function getEsOrientador()
359
    {
360
        return $this->esOrientador;
361
    }
362
363
    /**
364
     * Set esOrientador
365
     *
366
     * @param boolean $esOrientador
367
     * @return Usuario
368
     */
369
    public function setEsOrientador($esOrientador)
370
    {
371
        $this->esOrientador = $esOrientador;
372
373
        return $this;
374
    }
375
376
    /**
377
     * Get esDirectivo
378
     *
379
     * @return boolean
380
     */
381
    public function getEsDirectivo()
382
    {
383
        return $this->esDirectivo;
384
    }
385
386
    /**
387
     * Set esAdministrador
388
     *
389
     * @param boolean $esDirectivo
390
     * @return Usuario
391
     */
392
    public function setEsDirectivo($esDirectivo)
393
    {
394
        $this->esDirectivo = $esDirectivo;
395
396
        return $this;
397
    }
398
399
    /**
400
     * Add sanciones
401
     *
402
     * @param Sancion $sanciones
403
     * @return Usuario
404
     */
405
    public function addSancion(Sancion $sanciones)
406
    {
407
        $this->sanciones[] = $sanciones;
408
409
        return $this;
410
    }
411
412
    /**
413
     * Remove sanciones
414
     *
415
     * @param Sancion $sanciones
416
     */
417
    public function removeSancion(Sancion $sanciones)
418
    {
419
        $this->sanciones->removeElement($sanciones);
420
    }
421
422
    /**
423
     * Get sanciones
424
     *
425
     * @return Collection
426
     */
427
    public function getSanciones()
428
    {
429
        return $this->sanciones;
430
    }
431
432
    /**
433
     * Set nombreUsuario
434
     *
435
     * @param string $nombreUsuario
436
     * @return Usuario
437
     */
438
    public function setNombreUsuario($nombreUsuario)
439
    {
440
        $this->nombreUsuario = $nombreUsuario;
441
442
        return $this;
443
    }
444
445
    /**
446
     * Get nombreUsuario
447
     *
448
     * @return string
449
     */
450
    public function getNombreUsuario()
451
    {
452
        return $this->nombreUsuario;
453
    }
454
455
    /**
456
     * Set password
457
     *
458
     * @param string $password
459
     * @return Usuario
460
     */
461
    public function setPassword($password)
462
    {
463
        $this->password = $password;
464
465
        return $this;
466
    }
467
468
    /**
469
     * Get password
470
     *
471
     * @return string
472
     */
473
    public function getPassword()
474
    {
475
        return $this->password;
476
    }
477
478
    /**
479
     * Set estaActivo
480
     *
481
     * @param boolean $estaActivo
482
     * @return Usuario
483
     */
484
    public function setEstaActivo($estaActivo)
485
    {
486
        $this->estaActivo = $estaActivo;
487
488
        return $this;
489
    }
490
491
    /**
492
     * Get estaActivo
493
     *
494
     * @return boolean
495
     */
496
    public function getEstaActivo()
497
    {
498
        return $this->estaActivo;
499
    }
500
501
    /**
502
     * Set estaBloqueado
503
     *
504
     * @param boolean $estaBloqueado
505
     * @return Usuario
506
     */
507
    public function setEstaBloqueado($estaBloqueado)
508
    {
509
        $this->estaBloqueado = $estaBloqueado;
510
511
        return $this;
512
    }
513
514
    /**
515
     * Get estaBloqueado
516
     *
517
     * @return boolean
518
     */
519
    public function getEstaBloqueado()
520
    {
521
        return $this->estaBloqueado;
522
    }
523
524
    /**
525
     * Checks whether the user's account has expired.
526
     *
527
     * Internally, if this method returns false, the authentication system
528
     * will throw an AccountExpiredException and prevent login.
529
     *
530
     * @return bool true if the user's account is non expired, false otherwise
531
     *
532
     * @see AccountExpiredException
533
     */
534
    public function isAccountNonExpired()
535
    {
536
        return true;
537
    }
538
539
    /**
540
     * Checks whether the user is locked.
541
     *
542
     * Internally, if this method returns false, the authentication system
543
     * will throw a LockedException and prevent login.
544
     *
545
     * @return bool true if the user is not locked, false otherwise
546
     *
547
     * @see LockedException
548
     */
549
    public function isAccountNonLocked()
550
    {
551
        return (!$this->getEstaBloqueado());
552
    }
553
554
    /**
555
     * Checks whether the user's credentials (password) has expired.
556
     *
557
     * Internally, if this method returns false, the authentication system
558
     * will throw a CredentialsExpiredException and prevent login.
559
     *
560
     * @return bool true if the user's credentials are non expired, false otherwise
561
     *
562
     * @see CredentialsExpiredException
563
     */
564
    public function isCredentialsNonExpired()
565
    {
566
        return true;
567
    }
568
569
    /**
570
     * Checks whether the user is enabled.
571
     *
572
     * Internally, if this method returns false, the authentication system
573
     * will throw a DisabledException and prevent login.
574
     *
575
     * @return bool true if the user is enabled, false otherwise
576
     *
577
     * @see DisabledException
578
     */
579
    public function isEnabled()
580
    {
581
        return $this->getEstaActivo();
582
    }
583
584
    /**
585
     * Returns the roles granted to the user.
586
     *
587
     * <code>
588
     * public function getRoles()
589
     * {
590
     *     return array('ROLE_USER');
591
     * }
592
     * </code>
593
     *
594
     * Alternatively, the roles might be stored on a ``roles`` property,
595
     * and populated in any number of different ways when the user object
596
     * is created.
597
     *
598
     * @return Role[] The user roles
599
     */
600
    public function getRoles()
601
    {
602
        // realmente new Role() no es necesario, pero para que el valor
603
        // devuelto se corresponda con la anotación lo hacemos así
604
        $roles = array(new Role('ROLE_USUARIO'));
605
606
        if ($this->getEsAdministrador()) {
607
            $roles[] = new Role('ROLE_ADMIN');
608
        }
609
610
        if ($this->getEsOrientador()) {
611
            $roles[] = new Role('ROLE_ORIENTADOR');
612
        }
613
614
        if ($this->getEsRevisor()) {
615
            $roles[] = new Role('ROLE_REVISOR');
616
        }
617
618
        if ($this->getEsDirectivo()) {
619
            $roles[] = new Role('ROLE_DIRECTIVO');
620
        }
621
622
        if ($this->getTutoria()) {
623
            $roles[] = new Role('ROLE_TUTOR');
624
        }
625
626
        return $roles;
627
    }
628
629
    /**
630
     * Returns the salt that was originally used to encode the password.
631
     *
632
     * This can return null if the password was not encoded using a salt.
633
     *
634
     * @return string|null The salt
635
     */
636
    public function getSalt()
637
    {
638
        return null;
639
    }
640
641
    /**
642
     * Returns the username used to authenticate the user.
643
     *
644
     * @return string The username
645
     */
646
    public function getUsername()
647
    {
648
        return $this->getNombreUsuario();
649
    }
650
651
    /**
652
     * Removes sensitive data from the user.
653
     *
654
     * This is important if, at any given point, sensitive information like
655
     * the plain-text password is stored on this object.
656
     */
657
    public function eraseCredentials()
658
    {
659
660
    }
661
662
    /**
663
     * @return bool
664
     */
665
    public function getEsExterno()
666
    {
667
        return $this->esExterno;
668
    }
669
670
    /**
671
     * @param bool $esExterno
672
     *
673
     * @return Usuario
674
     */
675
    public function setEsExterno($esExterno)
676
    {
677
        $this->esExterno = $esExterno;
678
        return $this;
679
    }
680
}
681