Completed
Push — fix-tutores ( d23092...a0755b )
by Luis Ramón
04:52
created

Usuario::getEsOrientador()   A

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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
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
     * Constructor
135
     */
136
    public function __construct()
137
    {
138
        $this->partes = new ArrayCollection();
139
        $this->sanciones = new ArrayCollection();
140
    }
141
142
    /**
143
     *
144
     * @return int
145
     */
146
    public function getId()
147
    {
148
        return $this->id;
149
    }
150
151
    /**
152
     *
153
     * @return string
154
     */
155
    public function getApellidos()
156
    {
157
        return $this->apellidos;
158
    }
159
160
    /**
161
     *
162
     * @param string $valor
163
     * @return Usuario
164
     */
165
    public function setApellidos($valor)
166
    {
167
        $this->apellidos = $valor;
168
169
        return $this;
170
    }
171
172
173
    /**
174
     *
175
     * @return string
176
     */
177
    public function getEmail()
178
    {
179
        return $this->email;
180
    }
181
182
    /**
183
     *
184
     * @param string|null $valor
185
     * @return Usuario
186
     */
187
    public function setEmail($valor)
188
    {
189
        $this->email = $valor;
190
191
        return $this;
192
    }
193
194
    /**
195
     *
196
     * @return string
197
     */
198
    public function __toString() {
199
        return $this->getApellidos() . ', ' . $this->getNombre();
200
    }
201
202
    /**
203
     *
204
     * @return string
205
     */
206
    public function getNombre()
207
    {
208
        return $this->nombre;
209
    }
210
211
    /**
212
     *
213
     * @param string $valor
214
     * @return Usuario
215
     */
216
    public function setNombre($valor)
217
    {
218
        $this->nombre = $valor;
219
220
        return $this;
221
    }
222
223
    /**
224
     * Get tutoria
225
     *
226
     * @return Grupo
227
     */
228
    public function getTutoria()
229
    {
230
        return $this->tutoria;
231
    }
232
233
    /**
234
     *
235
     * @param Grupo|null $tutoria
236
     * @return Usuario
237
     */
238
    public function setTutoria($tutoria)
239
    {
240
        $this->tutoria = $tutoria;
241
242
        return $this;
243
    }
244
245
    /**
246
     * Add partes
247
     *
248
     * @param Parte $partes
249
     * @return Usuario
250
     */
251
    public function addParte(Parte $partes)
252
    {
253
        $this->partes[] = $partes;
254
255
        return $this;
256
    }
257
258
    /**
259
     * Remove partes
260
     *
261
     * @param Parte $partes
262
     */
263
    public function removeParte(Parte $partes)
264
    {
265
        $this->partes->removeElement($partes);
266
    }
267
268
    /**
269
     * Get partes
270
     *
271
     * @return Collection
272
     */
273
    public function getPartes()
274
    {
275
        return $this->partes;
276
    }
277
278
    /**
279
     * Get notificaciones
280
     *
281
     * @return boolean
282
     */
283
    public function getNotificaciones()
284
    {
285
        return $this->notificaciones;
286
    }
287
288
    /**
289
     * Set notificaciones
290
     *
291
     * @param boolean $notificaciones
292
     * @return Usuario
293
     */
294
    public function setNotificaciones($notificaciones)
295
    {
296
        $this->notificaciones = $notificaciones;
297
298
        return $this;
299
    }
300
301
    /**
302
     * Get esAdministrador
303
     *
304
     * @return boolean
305
     */
306
    public function getEsAdministrador()
307
    {
308
        return $this->esAdministrador;
309
    }
310
311
    /**
312
     * Set esAdministrador
313
     *
314
     * @param boolean $esAdministrador
315
     * @return Usuario
316
     */
317
    public function setEsAdministrador($esAdministrador)
318
    {
319
        $this->esAdministrador = $esAdministrador;
320
321
        return $this;
322
    }
323
324
    /**
325
     * Get esRevisor
326
     *
327
     * @return boolean
328
     */
329
    public function getEsRevisor()
330
    {
331
        return $this->esRevisor;
332
    }
333
334
    /**
335
     * Set esRevisor
336
     *
337
     * @param boolean $esRevisor
338
     * @return Usuario
339
     */
340
    public function setEsRevisor($esRevisor)
341
    {
342
        $this->esRevisor = $esRevisor;
343
344
        return $this;
345
    }
346
347
    /**
348
     * Get esOrientador
349
     *
350
     * @return boolean
351
     */
352
    public function getEsOrientador()
353
    {
354
        return $this->esOrientador;
355
    }
356
357
    /**
358
     * Set esOrientador
359
     *
360
     * @param boolean $esOrientador
361
     * @return Usuario
362
     */
363
    public function setEsOrientador($esOrientador)
364
    {
365
        $this->esOrientador = $esOrientador;
366
367
        return $this;
368
    }
369
370
    /**
371
     * Get esDirectivo
372
     *
373
     * @return boolean
374
     */
375
    public function getEsDirectivo()
376
    {
377
        return $this->esDirectivo;
378
    }
379
380
    /**
381
     * Set esAdministrador
382
     *
383
     * @param boolean $esDirectivo
384
     * @return Usuario
385
     */
386
    public function setEsDirectivo($esDirectivo)
387
    {
388
        $this->esDirectivo = $esDirectivo;
389
390
        return $this;
391
    }
392
393
    /**
394
     * Add sanciones
395
     *
396
     * @param Sancion $sanciones
397
     * @return Usuario
398
     */
399
    public function addSancion(Sancion $sanciones)
400
    {
401
        $this->sanciones[] = $sanciones;
402
403
        return $this;
404
    }
405
406
    /**
407
     * Remove sanciones
408
     *
409
     * @param Sancion $sanciones
410
     */
411
    public function removeSancion(Sancion $sanciones)
412
    {
413
        $this->sanciones->removeElement($sanciones);
414
    }
415
416
    /**
417
     * Get sanciones
418
     *
419
     * @return Collection
420
     */
421
    public function getSanciones()
422
    {
423
        return $this->sanciones;
424
    }
425
426
    /**
427
     * Set nombreUsuario
428
     *
429
     * @param string $nombreUsuario
430
     * @return Usuario
431
     */
432
    public function setNombreUsuario($nombreUsuario)
433
    {
434
        $this->nombreUsuario = $nombreUsuario;
435
436
        return $this;
437
    }
438
439
    /**
440
     * Get nombreUsuario
441
     *
442
     * @return string
443
     */
444
    public function getNombreUsuario()
445
    {
446
        return $this->nombreUsuario;
447
    }
448
449
    /**
450
     * Set password
451
     *
452
     * @param string $password
453
     * @return Usuario
454
     */
455
    public function setPassword($password)
456
    {
457
        $this->password = $password;
458
459
        return $this;
460
    }
461
462
    /**
463
     * Get password
464
     *
465
     * @return string
466
     */
467
    public function getPassword()
468
    {
469
        return $this->password;
470
    }
471
472
    /**
473
     * Set estaActivo
474
     *
475
     * @param boolean $estaActivo
476
     * @return Usuario
477
     */
478
    public function setEstaActivo($estaActivo)
479
    {
480
        $this->estaActivo = $estaActivo;
481
482
        return $this;
483
    }
484
485
    /**
486
     * Get estaActivo
487
     *
488
     * @return boolean
489
     */
490
    public function getEstaActivo()
491
    {
492
        return $this->estaActivo;
493
    }
494
495
    /**
496
     * Set estaBloqueado
497
     *
498
     * @param boolean $estaBloqueado
499
     * @return Usuario
500
     */
501
    public function setEstaBloqueado($estaBloqueado)
502
    {
503
        $this->estaBloqueado = $estaBloqueado;
504
505
        return $this;
506
    }
507
508
    /**
509
     * Get estaBloqueado
510
     *
511
     * @return boolean
512
     */
513
    public function getEstaBloqueado()
514
    {
515
        return $this->estaBloqueado;
516
    }
517
518
    /**
519
     * Checks whether the user's account has expired.
520
     *
521
     * Internally, if this method returns false, the authentication system
522
     * will throw an AccountExpiredException and prevent login.
523
     *
524
     * @return bool true if the user's account is non expired, false otherwise
525
     *
526
     * @see AccountExpiredException
527
     */
528
    public function isAccountNonExpired()
529
    {
530
        return true;
531
    }
532
533
    /**
534
     * Checks whether the user is locked.
535
     *
536
     * Internally, if this method returns false, the authentication system
537
     * will throw a LockedException and prevent login.
538
     *
539
     * @return bool true if the user is not locked, false otherwise
540
     *
541
     * @see LockedException
542
     */
543
    public function isAccountNonLocked()
544
    {
545
        return (!$this->getEstaBloqueado());
546
    }
547
548
    /**
549
     * Checks whether the user's credentials (password) has expired.
550
     *
551
     * Internally, if this method returns false, the authentication system
552
     * will throw a CredentialsExpiredException and prevent login.
553
     *
554
     * @return bool true if the user's credentials are non expired, false otherwise
555
     *
556
     * @see CredentialsExpiredException
557
     */
558
    public function isCredentialsNonExpired()
559
    {
560
        return true;
561
    }
562
563
    /**
564
     * Checks whether the user is enabled.
565
     *
566
     * Internally, if this method returns false, the authentication system
567
     * will throw a DisabledException and prevent login.
568
     *
569
     * @return bool true if the user is enabled, false otherwise
570
     *
571
     * @see DisabledException
572
     */
573
    public function isEnabled()
574
    {
575
        return $this->getEstaActivo();
576
    }
577
578
    /**
579
     * Returns the roles granted to the user.
580
     *
581
     * <code>
582
     * public function getRoles()
583
     * {
584
     *     return array('ROLE_USER');
585
     * }
586
     * </code>
587
     *
588
     * Alternatively, the roles might be stored on a ``roles`` property,
589
     * and populated in any number of different ways when the user object
590
     * is created.
591
     *
592
     * @return Role[] The user roles
593
     */
594
    public function getRoles()
595
    {
596
        // realmente new Role() no es necesario, pero para que el valor
597
        // devuelto se corresponda con la anotación lo hacemos así
598
        $roles = array(new Role('ROLE_USUARIO'));
599
600
        if ($this->getEsAdministrador()) {
601
            $roles[] = new Role('ROLE_ADMIN');
602
        }
603
604
        if ($this->getEsOrientador()) {
605
            $roles[] = new Role('ROLE_ORIENTADOR');
606
        }
607
608
        if ($this->getEsRevisor()) {
609
            $roles[] = new Role('ROLE_REVISOR');
610
        }
611
612
        if ($this->getEsDirectivo()) {
613
            $roles[] = new Role('ROLE_DIRECTIVO');
614
        }
615
616
        if ($this->getTutoria()) {
617
            $roles[] = new Role('ROLE_TUTOR');
618
        }
619
620
        return $roles;
621
    }
622
623
    /**
624
     * Returns the salt that was originally used to encode the password.
625
     *
626
     * This can return null if the password was not encoded using a salt.
627
     *
628
     * @return string|null The salt
629
     */
630
    public function getSalt()
631
    {
632
        return null;
633
    }
634
635
    /**
636
     * Returns the username used to authenticate the user.
637
     *
638
     * @return string The username
639
     */
640
    public function getUsername()
641
    {
642
        return $this->getNombreUsuario();
643
    }
644
645
    /**
646
     * Removes sensitive data from the user.
647
     *
648
     * This is important if, at any given point, sensitive information like
649
     * the plain-text password is stored on this object.
650
     */
651
    public function eraseCredentials()
652
    {
653
654
    }
655
}
656