]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Entity/User.php
create an Entry with a User in parameter
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / User.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Entity;
4
5 use Doctrine\Common\Collections\ArrayCollection;
6 use Doctrine\ORM\Mapping as ORM;
7 use Symfony\Component\Security\Core\User\UserInterface;
8 use Symfony\Component\Security\Core\User\AdvancedUserInterface;
9
10 /**
11 * User
12 *
13 * @ORM\Table(name="user")
14 * @ORM\Entity
15 * @ORM\HasLifecycleCallbacks()
16 */
17 class User implements AdvancedUserInterface, \Serializable
18 {
19 /**
20 * @var integer
21 *
22 * @ORM\Column(name="id", type="integer")
23 * @ORM\Id
24 * @ORM\GeneratedValue(strategy="AUTO")
25 */
26 private $id;
27
28 /**
29 * @var string
30 *
31 * @ORM\Column(name="username", type="text")
32 */
33 private $username;
34
35 /**
36 * @var string
37 *
38 * @ORM\Column(type="string", length=32)
39 */
40 private $salt;
41
42 /**
43 * @var string
44 *
45 * @ORM\Column(name="password", type="text")
46 */
47 private $password;
48
49 /**
50 * @var string
51 *
52 * @ORM\Column(name="name", type="text", nullable=true)
53 */
54 private $name;
55
56 /**
57 * @var string
58 *
59 * @ORM\Column(name="email", type="text", nullable=true)
60 */
61 private $email;
62
63 /**
64 * @ORM\Column(name="is_active", type="boolean")
65 */
66 private $isActive;
67
68 /**
69 * @var date
70 *
71 * @ORM\Column(name="created_at", type="datetime")
72 */
73 private $createdAt;
74
75 /**
76 * @var date
77 *
78 * @ORM\Column(name="updated_at", type="datetime")
79 */
80 private $updatedAt;
81
82 /**
83 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
84 */
85 private $entries;
86
87 public function __construct()
88 {
89 $this->isActive = true;
90 $this->salt = md5(uniqid(null, true));
91 $this->entries = new ArrayCollection();
92 }
93
94 /**
95 * @ORM\PrePersist
96 * @ORM\PreUpdate
97 */
98 public function timestamps()
99 {
100 if (is_null($this->createdAt)) {
101 $this->createdAt = new \DateTime();
102 }
103
104 $this->updatedAt = new \DateTime();
105 }
106
107 /**
108 * Get id
109 *
110 * @return integer
111 */
112 public function getId()
113 {
114 return $this->id;
115 }
116
117 /**
118 * Set username
119 *
120 * @param string $username
121 * @return User
122 */
123 public function setUsername($username)
124 {
125 $this->username = $username;
126
127 return $this;
128 }
129
130 /**
131 * Get username
132 *
133 * @return string
134 */
135 public function getUsername()
136 {
137 return $this->username;
138 }
139
140 /**
141 * @inheritDoc
142 */
143 public function getSalt()
144 {
145 return $this->salt;
146 }
147
148 /**
149 * @inheritDoc
150 */
151 public function getRoles()
152 {
153 return array('ROLE_USER');
154 }
155
156 /**
157 * Set password
158 *
159 * @param string $password
160 * @return User
161 */
162 public function setPassword($password)
163 {
164 $this->password = $password;
165
166 return $this;
167 }
168
169 /**
170 * Get password
171 *
172 * @return string
173 */
174 public function getPassword()
175 {
176 return $this->password;
177 }
178
179 /**
180 * Set name
181 *
182 * @param string $name
183 * @return User
184 */
185 public function setName($name)
186 {
187 $this->name = $name;
188
189 return $this;
190 }
191
192 /**
193 * Get name
194 *
195 * @return string
196 */
197 public function getName()
198 {
199 return $this->name;
200 }
201
202 /**
203 * Set email
204 *
205 * @param string $email
206 * @return User
207 */
208 public function setEmail($email)
209 {
210 $this->email = $email;
211
212 return $this;
213 }
214
215 /**
216 * Get email
217 *
218 * @return string
219 */
220 public function getEmail()
221 {
222 return $this->email;
223 }
224
225 /**
226 * @return string
227 */
228 public function getCreatedAt()
229 {
230 return $this->createdAt;
231 }
232
233 /**
234 * @return string
235 */
236 public function getUpdatedAt()
237 {
238 return $this->updatedAt;
239 }
240
241 /**
242 * @param Entry $entry
243 *
244 * @return User
245 */
246 public function addEntry(Entry $entry)
247 {
248 $this->entries[] = $entry;
249
250 return $this;
251 }
252
253 /**
254 * @return ArrayCollection<Entry>
255 */
256 public function getEntries()
257 {
258 return $this->entries;
259 }
260
261 /**
262 * @inheritDoc
263 */
264 public function eraseCredentials()
265 {
266 }
267
268 /**
269 * @see \Serializable::serialize()
270 */
271 public function serialize()
272 {
273 return serialize(array(
274 $this->id,
275 ));
276 }
277
278 /**
279 * @see \Serializable::unserialize()
280 */
281 public function unserialize($serialized)
282 {
283 list(
284 $this->id,
285 ) = unserialize($serialized);
286 }
287
288 public function isEqualTo(UserInterface $user)
289 {
290 return $this->username === $user->getUsername();
291 }
292
293 public function isAccountNonExpired()
294 {
295 return true;
296 }
297
298 public function isAccountNonLocked()
299 {
300 return true;
301 }
302
303 public function isCredentialsNonExpired()
304 {
305 return true;
306 }
307
308 public function isEnabled()
309 {
310 return $this->isActive;
311 }
312 }