1
|
|
|
<?php namespace Modules\User\Entities\Usher; |
2
|
|
|
|
3
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
4
|
|
|
use Doctrine\ORM\Mapping as ORM; |
5
|
|
|
use Laracasts\Presenter\PresentableTrait; |
6
|
|
|
use Maatwebsite\Usher\Domain\Users\User as UsherUser; |
7
|
|
|
use Modules\User\Entities\UserInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @ORM\Entity |
11
|
|
|
* @ORM\Table(name="users") |
12
|
|
|
* @ORM\HasLifecycleCallbacks() |
13
|
|
|
*/ |
14
|
|
|
class User extends UsherUser implements UserInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Traits |
18
|
|
|
*/ |
19
|
|
|
use PresentableTrait; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $presenter = 'Modules\User\Presenters\UserPresenter'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @ORM\ManyToMany(targetEntity="Role", inversedBy="users") |
28
|
|
|
* @ORM\JoinTable(name="user_roles") |
29
|
|
|
* @var ArrayCollection|\Maatwebsite\Usher\Contracts\Roles\Role[] |
30
|
|
|
*/ |
31
|
|
|
protected $roles; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return ArrayCollection|\Maatwebsite\Usher\Contracts\Roles\Role[] |
35
|
|
|
*/ |
36
|
|
|
public function getRoles() |
37
|
|
|
{ |
38
|
|
|
return $this->roles; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param ArrayCollection|Role[] $roles |
43
|
|
|
*/ |
44
|
|
|
public function setRoles(ArrayCollection $roles) |
45
|
|
|
{ |
46
|
|
|
$this->roles = $roles; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
public function getFirstName() |
53
|
|
|
{ |
54
|
|
|
return $this->getName()->getFirstname(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getLastName() |
61
|
|
|
{ |
62
|
|
|
return $this->getName()->getLastname(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param $attribute |
67
|
|
|
* @return null|string |
68
|
|
|
*/ |
69
|
|
|
public function __get($attribute) |
70
|
|
|
{ |
71
|
|
|
$method = 'get' . studly_case($attribute); |
72
|
|
|
|
73
|
|
|
if (method_exists($this, $method)) { |
74
|
|
|
return $this->{$method}(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return null; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param $attribute |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
|
|
public function __isset($attribute) |
85
|
|
|
{ |
86
|
|
|
$method = 'get' . studly_case($attribute); |
87
|
|
|
|
88
|
|
|
if (method_exists($this, $method)) { |
89
|
|
|
return true; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return false; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Checks if a user belongs to the given Role ID |
97
|
|
|
* @param int $roleId |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
|
|
public function hasRoleId($roleId) |
101
|
|
|
{ |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Checks if a user belongs to the given Role Name |
106
|
|
|
* @param string $name |
107
|
|
|
* @return bool |
108
|
|
|
*/ |
109
|
|
|
public function hasRoleName($name) |
110
|
|
|
{ |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Check if the current user is activated |
115
|
|
|
* @return bool |
116
|
|
|
*/ |
117
|
|
|
public function isActivated() |
118
|
|
|
{ |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|