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