-
Notifications
You must be signed in to change notification settings - Fork 5
/
AppUser.php
101 lines (88 loc) · 2.13 KB
/
AppUser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
/**
* Class AppUser
* @package AppBundle\Entity
*
* @ORM\Entity()
* @ORM\Table(name="users")
*/
class AppUser
{
/**
* @var string $firstName
* @ORM\Column(name="first_name", type="string", nullable=false)
*/
private $firstName;
/**
* @var string $lastName
* @ORM\Column(name="last_name", type="string", nullable=false)
*/
private $lastName;
/**
* @var Uuid $id
* @ORM\Id()
* @ORM\Column(name="id", type="guid", nullable=false)
*/
private $id;
/**
* @var ArrayCollection $roles
* @ORM\ManyToMany(targetEntity="AppRole")
* @ORM\JoinTable(
* name="users_roles",
* joinColumns={@ORM\JoinColumn(name="userId", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="roleId", referencedColumnName="id")}
* )
*/
private $roles;
/**
* AppUser constructor.
* @param string $firstName
* @param string $lastName
*/
public function __construct($firstName, $lastName)
{
$this->id = Uuid::uuid4();
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->roles = new ArrayCollection();
}
/**
* @return Uuid
*/
public function getId()
{
return $this->id;
}
public function assignRole(AppRole $role)
{
$this->roles->add($role);
}
public function hasRole(AppRole $role)
{
$hasRoleCriteria =
Criteria::create()->andWhere(
Criteria::expr()->eq(
'id',
$role->getId()
)
);
return $this->roles->matching($hasRoleCriteria)->count() > 0;
}
public function getFirstName()
{
return $this->firstName;
}
public function getLastName()
{
return $this->lastName;
}
public function is(AppUser $userToCompare)
{
return $this->getId() === $userToCompare->getId();
}
}