|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
ÁTICA - Aplicación web para la gestión documental de centros educativos |
|
4
|
|
|
|
|
5
|
|
|
Copyright (C) 2015-2016: 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
|
|
|
use Doctrine\ORM\EntityRepository; |
|
24
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
25
|
|
|
use Symfony\Component\Security\Core\User\UserProviderInterface; |
|
26
|
|
|
|
|
27
|
|
|
class UserRepository extends EntityRepository implements UserProviderInterface |
|
28
|
|
|
{ |
|
29
|
|
|
public function loadUserByUsername($username) { |
|
30
|
|
|
|
|
31
|
|
|
if (!$username) { |
|
32
|
|
|
return null; |
|
33
|
|
|
} |
|
34
|
|
|
return $this->getEntityManager() |
|
35
|
|
|
->createQuery('SELECT u FROM AppBundle:User u JOIN u.person p |
|
36
|
|
|
WHERE u.username = :username |
|
37
|
|
|
OR p.email = :username') |
|
38
|
|
|
->setParameters([ |
|
39
|
|
|
'username' => $username |
|
40
|
|
|
]) |
|
41
|
|
|
->getOneOrNullResult(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function refreshUser(UserInterface $user) { |
|
45
|
|
|
return $this->loadUserByUsername($user->getUsername()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function supportsClass($class) { |
|
49
|
|
|
return $class === 'AppBundle\Entity\User'; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Crea un nuevo usuario y su persona asociada |
|
54
|
|
|
* |
|
55
|
|
|
* @return User |
|
56
|
|
|
*/ |
|
57
|
|
|
public function createNewUser() |
|
58
|
|
|
{ |
|
59
|
|
|
$user = new User(); |
|
60
|
|
|
$person = new Person(); |
|
61
|
|
|
$person->setDisplayName(''); |
|
62
|
|
|
$user->setPerson($person); |
|
63
|
|
|
|
|
64
|
|
|
$this->getEntityManager()->persist($user->getPerson()); |
|
65
|
|
|
$this->getEntityManager()->persist($user); |
|
66
|
|
|
|
|
67
|
|
|
return $user; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|