|
1 | 1 | <?php |
2 | 2 | namespace ProspectOne\UserModule\Entity; |
3 | 3 |
|
| 4 | +use Doctrine\Common\Collections\ArrayCollection; |
4 | 5 | use Doctrine\ORM\Mapping as ORM; |
5 | 6 |
|
6 | 7 | /** |
7 | 8 | * This class represents a registered user. |
| 9 | + * Adds role system |
8 | 10 | * @ORM\Entity() |
9 | 11 | * @ORM\Table(name="user") |
10 | 12 | */ |
11 | | -class User |
| 13 | +class User |
12 | 14 | { |
13 | 15 | // User status constants. |
14 | 16 | const STATUS_ACTIVE = 1; // Active user. |
15 | 17 | const STATUS_RETIRED = 2; // Retired user. |
16 | | - |
| 18 | + |
| 19 | + /** |
| 20 | + * @var \Doctrine\Common\Collections\Collection |
| 21 | + * @ORM\ManyToMany(targetEntity="ProspectOne\UserModule\Entity\Role") |
| 22 | + * @ORM\JoinTable(name="user_role_linker", |
| 23 | + * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, |
| 24 | + * inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")} |
| 25 | + * ) |
| 26 | + */ |
| 27 | + protected $roles; |
| 28 | + |
| 29 | + /** |
| 30 | + * Initialies the roles variable. |
| 31 | + */ |
| 32 | + public function __construct() |
| 33 | + { |
| 34 | + $this->roles = new ArrayCollection(); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Get role. |
| 39 | + * @return array |
| 40 | + */ |
| 41 | + public function getRoles() |
| 42 | + { |
| 43 | + return $this->roles->getValues(); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Add a role to the user. |
| 48 | + * @param Role $role |
| 49 | + * @return void |
| 50 | + */ |
| 51 | + public function addRole($role) |
| 52 | + { |
| 53 | + $this->roles[] = $role; |
| 54 | + } |
| 55 | + |
17 | 56 | /** |
18 | 57 | * @ORM\Id |
19 | 58 | * @ORM\Column(name="id", type="integer") |
20 | 59 | * @ORM\GeneratedValue |
21 | 60 | */ |
22 | 61 | protected $id; |
23 | 62 |
|
24 | | - /** |
25 | | - * @ORM\Column(name="email") |
| 63 | + /** |
| 64 | + * @ORM\Column(name="email") |
26 | 65 | */ |
27 | 66 | protected $email; |
28 | | - |
29 | | - /** |
30 | | - * @ORM\Column(name="full_name") |
| 67 | + |
| 68 | + /** |
| 69 | + * @ORM\Column(name="full_name") |
31 | 70 | */ |
32 | 71 | protected $fullName; |
33 | 72 |
|
34 | | - /** |
35 | | - * @ORM\Column(name="password") |
| 73 | + /** |
| 74 | + * @ORM\Column(name="password") |
36 | 75 | */ |
37 | 76 | protected $password; |
38 | 77 |
|
39 | | - /** |
40 | | - * @ORM\Column(name="status") |
| 78 | + /** |
| 79 | + * @ORM\Column(name="status") |
41 | 80 | */ |
42 | 81 | protected $status; |
43 | | - |
| 82 | + |
44 | 83 | /** |
45 | | - * @ORM\Column(name="date_created") |
| 84 | + * @ORM\Column(name="date_created") |
46 | 85 | */ |
47 | 86 | protected $dateCreated; |
48 | | - |
| 87 | + |
49 | 88 | /** |
50 | 89 | * @ORM\Column(name="pwd_reset_token", nullable=true) |
51 | 90 | */ |
52 | 91 | protected $passwordResetToken; |
53 | | - |
| 92 | + |
54 | 93 | /** |
55 | 94 | * @ORM\Column(name="pwd_reset_token_creation_date", nullable=true) |
56 | 95 | */ |
57 | 96 | protected $passwordResetTokenCreationDate; |
58 | | - |
| 97 | + |
59 | 98 | /** |
60 | 99 | * Returns user ID. |
61 | 100 | * @return integer |
62 | 101 | */ |
63 | | - public function getId() |
| 102 | + public function getId() |
64 | 103 | { |
65 | 104 | return $this->id; |
66 | 105 | } |
67 | 106 |
|
68 | 107 | /** |
69 | | - * Sets user ID. |
70 | | - * @param int $id |
| 108 | + * Sets user ID. |
| 109 | + * @param int $id |
71 | 110 | */ |
72 | | - public function setId($id) |
| 111 | + public function setId($id) |
73 | 112 | { |
74 | 113 | $this->id = $id; |
75 | 114 | } |
76 | 115 |
|
77 | 116 | /** |
78 | | - * Returns email. |
| 117 | + * Returns email. |
79 | 118 | * @return string |
80 | 119 | */ |
81 | | - public function getEmail() |
| 120 | + public function getEmail() |
82 | 121 | { |
83 | 122 | return $this->email; |
84 | 123 | } |
85 | 124 |
|
86 | 125 | /** |
87 | | - * Sets email. |
| 126 | + * Sets email. |
88 | 127 | * @param string $email |
89 | 128 | */ |
90 | | - public function setEmail($email) |
| 129 | + public function setEmail($email) |
91 | 130 | { |
92 | 131 | $this->email = $email; |
93 | 132 | } |
94 | | - |
| 133 | + |
95 | 134 | /** |
96 | 135 | * Returns full name. |
97 | | - * @return string |
| 136 | + * @return string |
98 | 137 | */ |
99 | | - public function getFullName() |
| 138 | + public function getFullName() |
100 | 139 | { |
101 | 140 | return $this->fullName; |
102 | | - } |
| 141 | + } |
103 | 142 |
|
104 | 143 | /** |
105 | 144 | * Sets full name. |
106 | 145 | * @param string $fullName |
107 | 146 | */ |
108 | | - public function setFullName($fullName) |
| 147 | + public function setFullName($fullName) |
109 | 148 | { |
110 | 149 | $this->fullName = $fullName; |
111 | 150 | } |
112 | | - |
| 151 | + |
113 | 152 | /** |
114 | 153 | * Returns status. |
115 | 154 | * @return int |
|
0 commit comments