]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Entity/User.php
implement FosUser
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / User.php
CommitLineData
9d50517c
NL
1<?php
2
ad4d1caa 3namespace Wallabag\CoreBundle\Entity;
9d50517c 4
5f09650e 5use Doctrine\Common\Collections\ArrayCollection;
9d50517c 6use Doctrine\ORM\Mapping as ORM;
c844dc0c 7use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
c3235553 8use Symfony\Component\Security\Core\User\UserInterface;
c3235553 9use Symfony\Component\Security\Core\User\AdvancedUserInterface;
c0d9eba0 10use Symfony\Component\Validator\Constraints as Assert;
0f006880
NL
11use JMS\Serializer\Annotation\ExclusionPolicy;
12use JMS\Serializer\Annotation\Expose;
a1691859 13use FOS\UserBundle\Model\User as BaseUser;
9d50517c
NL
14
15/**
4346a860 16 * User.
9d50517c 17 *
0c83fd59 18 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
164bd801 19 * @ORM\Table
2f69eb4a 20 * @ORM\HasLifecycleCallbacks()
0f006880 21 * @ExclusionPolicy("all")
c844dc0c
J
22 *
23 * @UniqueEntity("email")
24 * @UniqueEntity("username")
9d50517c 25 */
a1691859 26class User extends BaseUser implements AdvancedUserInterface, \Serializable
9d50517c
NL
27{
28 /**
4346a860 29 * @var int
9d50517c 30 *
0f006880 31 * @Expose
2f69eb4a 32 * @ORM\Column(name="id", type="integer")
9d50517c 33 * @ORM\Id
2f69eb4a 34 * @ORM\GeneratedValue(strategy="AUTO")
9d50517c 35 */
a1691859 36 protected $id;
9d50517c
NL
37
38 /**
39 * @var string
40 *
41 * @ORM\Column(name="name", type="text", nullable=true)
42 */
a1691859 43 protected $name;
6894d48e 44
2f69eb4a
NL
45 /**
46 * @var date
47 *
48 * @ORM\Column(name="created_at", type="datetime")
49 */
a1691859 50 protected $createdAt;
2f69eb4a
NL
51
52 /**
53 * @var date
54 *
55 * @ORM\Column(name="updated_at", type="datetime")
56 */
a1691859 57 protected $updatedAt;
2f69eb4a 58
5f09650e
NL
59 /**
60 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
61 */
a1691859 62 protected $entries;
5f09650e 63
32da2a70
J
64 /**
65 * @ORM\OneToOne(targetEntity="Config", mappedBy="user")
66 */
a1691859 67 protected $config;
32da2a70 68
092ca707
NL
69 /**
70 * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
71 */
a1691859 72 protected $tags;
092ca707 73
c3235553
NL
74 public function __construct()
75 {
a1691859
NL
76 parent::__construct();
77 $this->entries = new ArrayCollection();
78 $this->tags = new ArrayCollection();
c3235553 79 }
9d50517c 80
2f69eb4a
NL
81 /**
82 * @ORM\PrePersist
83 * @ORM\PreUpdate
84 */
85 public function timestamps()
86 {
87 if (is_null($this->createdAt)) {
88 $this->createdAt = new \DateTime();
89 }
90
91 $this->updatedAt = new \DateTime();
92 }
93
9d50517c 94 /**
4346a860
JB
95 * Set password.
96 *
97 * @param string $password
9d50517c 98 *
2f69eb4a 99 * @return User
9d50517c
NL
100 */
101 public function setPassword($password)
102 {
d9169157
J
103 if (!$password && 0 === strlen($password)) {
104 return;
105 }
106
107 $this->password = sha1($password.$this->getUsername().$this->getSalt());
9d50517c
NL
108
109 return $this;
110 }
111
9d50517c 112 /**
4346a860
JB
113 * Set name.
114 *
115 * @param string $name
9d50517c 116 *
2f69eb4a 117 * @return User
9d50517c
NL
118 */
119 public function setName($name)
120 {
121 $this->name = $name;
122
123 return $this;
124 }
125
126 /**
4346a860 127 * Get name.
9d50517c 128 *
7df80cb3 129 * @return string
9d50517c
NL
130 */
131 public function getName()
132 {
133 return $this->name;
134 }
135
2f69eb4a
NL
136 /**
137 * @return string
138 */
139 public function getCreatedAt()
140 {
141 return $this->createdAt;
142 }
143
144 /**
145 * @return string
146 */
147 public function getUpdatedAt()
148 {
149 return $this->updatedAt;
150 }
151
5f09650e
NL
152 /**
153 * @param Entry $entry
154 *
155 * @return User
156 */
157 public function addEntry(Entry $entry)
158 {
159 $this->entries[] = $entry;
160
161 return $this;
162 }
163
164 /**
165 * @return ArrayCollection<Entry>
166 */
167 public function getEntries()
168 {
169 return $this->entries;
170 }
171
092ca707
NL
172 /**
173 * @param Entry $entry
174 *
175 * @return User
176 */
177 public function addTag(Tag $tag)
178 {
179 $this->tags[] = $tag;
180
181 return $this;
182 }
183
184 /**
185 * @return ArrayCollection<Tag>
186 */
187 public function getTags()
188 {
189 return $this->tags;
190 }
c3235553
NL
191
192 public function isEqualTo(UserInterface $user)
193 {
194 return $this->username === $user->getUsername();
195 }
196
32da2a70 197 /**
4346a860
JB
198 * Set config.
199 *
200 * @param \Wallabag\CoreBundle\Entity\Config $config
32da2a70 201 *
32da2a70
J
202 * @return User
203 */
204 public function setConfig(\Wallabag\CoreBundle\Entity\Config $config = null)
205 {
206 $this->config = $config;
207
208 return $this;
209 }
210
211 /**
4346a860 212 * Get config.
32da2a70
J
213 *
214 * @return \Wallabag\CoreBundle\Entity\Config
215 */
216 public function getConfig()
217 {
218 return $this->config;
219 }
9d50517c 220}