1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Matks\Bundle\CustomerSupportBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Knp\DoctrineBehaviors\Model as ORMBehaviors; |
7
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
8
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
9
|
|
|
use LogicException; |
10
|
|
|
|
11
|
|
|
use Matks\Bundle\CustomerSupportBundle\Model\UserInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* User entity |
15
|
|
|
* |
16
|
|
|
* @ORM\Entity(repositoryClass="Matks\Bundle\CustomerSupportBundle\Repository\UserRepository") |
17
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
18
|
|
|
* @ORM\DiscriminatorColumn(name="discr", type="string") |
19
|
|
|
* @ORM\Table(name="users", indexes={@ORM\Index(name="user_email_idx", columns={"email"})}) |
20
|
|
|
* @UniqueEntity(fields="email", message="this email already exists") |
21
|
|
|
* @ORM\HasLifecycleCallbacks |
22
|
|
|
* |
23
|
|
|
* @author Mathieu Ferment <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class User implements UserInterface |
26
|
|
|
{ |
27
|
|
|
use ORMBehaviors\Timestampable\Timestampable; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var int |
31
|
|
|
* |
32
|
|
|
* @ORM\Id |
33
|
|
|
* @ORM\Column(type="integer") |
34
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
35
|
|
|
*/ |
36
|
|
|
private $id; |
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
* |
41
|
|
|
* @ORM\Column(type="string", length=255) |
42
|
|
|
*/ |
43
|
|
|
private $email; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
* |
48
|
|
|
* @ORM\Column(type="string", length=255, name="first_name") |
49
|
|
|
* @Assert\NotBlank() |
50
|
|
|
*/ |
51
|
|
|
private $firstName; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string |
55
|
|
|
* |
56
|
|
|
* @ORM\Column(type="string", length=255, name="last_name") |
57
|
|
|
* @Assert\NotBlank() |
58
|
|
|
*/ |
59
|
|
|
private $lastName; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var Name |
|
|
|
|
63
|
|
|
*/ |
64
|
|
|
private $name; |
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Constructor |
68
|
|
|
* |
69
|
|
|
* @param string $firstName |
70
|
|
|
* @param string $lastName |
71
|
|
|
* @param string $email |
72
|
|
|
*/ |
73
|
6 |
|
public function __construct($firstName, $lastName, $email) |
74
|
|
|
{ |
75
|
6 |
|
$this->firstName = $firstName; |
76
|
6 |
|
$this->lastName = $lastName; |
77
|
6 |
|
$this->email = $email; |
78
|
6 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
1 |
|
public function __toString() |
84
|
|
|
{ |
85
|
1 |
|
return $this->email; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get full name |
90
|
|
|
* |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
1 |
|
public function getName() |
94
|
|
|
{ |
95
|
1 |
|
return $this->firstName . ' ' . $this->lastName; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get first name |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getFirstName() |
104
|
|
|
{ |
105
|
|
|
return $this->firstName; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Get last name |
110
|
|
|
* |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function getLastName() |
114
|
|
|
{ |
115
|
|
|
return $this->lastName; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get email |
120
|
|
|
* |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
public function getEmail() |
124
|
|
|
{ |
125
|
|
|
return $this->email; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return bool |
130
|
|
|
* @throws Exception: should be called on children classes |
131
|
|
|
*/ |
132
|
1 |
|
public function isACustomer() |
133
|
|
|
{ |
134
|
1 |
|
throw new LogicException("This function should never be called on a user"); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|