]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Entity/User.php
Add test on RegistrationConfirmedListener
[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;
0f006880
NL
9use JMS\Serializer\Annotation\ExclusionPolicy;
10use JMS\Serializer\Annotation\Expose;
a1691859 11use FOS\UserBundle\Model\User as BaseUser;
9d50517c
NL
12
13/**
4346a860 14 * User.
9d50517c 15 *
0c83fd59 16 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
164bd801 17 * @ORM\Table
2f69eb4a 18 * @ORM\HasLifecycleCallbacks()
0f006880 19 * @ExclusionPolicy("all")
c844dc0c
J
20 *
21 * @UniqueEntity("email")
22 * @UniqueEntity("username")
9d50517c 23 */
fcb1fba5 24class User extends BaseUser
9d50517c
NL
25{
26 /**
4346a860 27 * @var int
9d50517c 28 *
0f006880 29 * @Expose
2f69eb4a 30 * @ORM\Column(name="id", type="integer")
9d50517c 31 * @ORM\Id
2f69eb4a 32 * @ORM\GeneratedValue(strategy="AUTO")
9d50517c 33 */
a1691859 34 protected $id;
9d50517c
NL
35
36 /**
37 * @var string
38 *
39 * @ORM\Column(name="name", type="text", nullable=true)
40 */
a1691859 41 protected $name;
6894d48e 42
2f69eb4a
NL
43 /**
44 * @var date
45 *
46 * @ORM\Column(name="created_at", type="datetime")
47 */
a1691859 48 protected $createdAt;
2f69eb4a
NL
49
50 /**
51 * @var date
52 *
53 * @ORM\Column(name="updated_at", type="datetime")
54 */
a1691859 55 protected $updatedAt;
2f69eb4a 56
5f09650e
NL
57 /**
58 * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"})
59 */
a1691859 60 protected $entries;
5f09650e 61
32da2a70
J
62 /**
63 * @ORM\OneToOne(targetEntity="Config", mappedBy="user")
64 */
a1691859 65 protected $config;
32da2a70 66
092ca707
NL
67 /**
68 * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"})
69 */
a1691859 70 protected $tags;
092ca707 71
c3235553
NL
72 public function __construct()
73 {
a1691859 74 parent::__construct();
98f0929f
JB
75 $this->entries = new ArrayCollection();
76 $this->tags = new ArrayCollection();
fcb1fba5 77 $this->roles = array('ROLE_USER');
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 name.
95 *
96 * @param string $name
9d50517c 97 *
2f69eb4a 98 * @return User
9d50517c
NL
99 */
100 public function setName($name)
101 {
102 $this->name = $name;
103
104 return $this;
105 }
106
107 /**
4346a860 108 * Get name.
9d50517c 109 *
7df80cb3 110 * @return string
9d50517c
NL
111 */
112 public function getName()
113 {
114 return $this->name;
115 }
116
2f69eb4a
NL
117 /**
118 * @return string
119 */
120 public function getCreatedAt()
121 {
122 return $this->createdAt;
123 }
124
125 /**
126 * @return string
127 */
128 public function getUpdatedAt()
129 {
130 return $this->updatedAt;
131 }
132
5f09650e
NL
133 /**
134 * @param Entry $entry
135 *
136 * @return User
137 */
138 public function addEntry(Entry $entry)
139 {
140 $this->entries[] = $entry;
141
142 return $this;
143 }
144
145 /**
146 * @return ArrayCollection<Entry>
147 */
148 public function getEntries()
149 {
150 return $this->entries;
151 }
152
092ca707
NL
153 /**
154 * @param Entry $entry
155 *
156 * @return User
157 */
158 public function addTag(Tag $tag)
159 {
160 $this->tags[] = $tag;
161
162 return $this;
163 }
164
165 /**
166 * @return ArrayCollection<Tag>
167 */
168 public function getTags()
169 {
170 return $this->tags;
171 }
c3235553
NL
172
173 public function isEqualTo(UserInterface $user)
174 {
175 return $this->username === $user->getUsername();
176 }
177
32da2a70 178 /**
4346a860
JB
179 * Set config.
180 *
181 * @param \Wallabag\CoreBundle\Entity\Config $config
32da2a70 182 *
32da2a70
J
183 * @return User
184 */
185 public function setConfig(\Wallabag\CoreBundle\Entity\Config $config = null)
186 {
187 $this->config = $config;
188
189 return $this;
190 }
191
192 /**
4346a860 193 * Get config.
32da2a70
J
194 *
195 * @return \Wallabag\CoreBundle\Entity\Config
196 */
197 public function getConfig()
198 {
199 return $this->config;
200 }
9d50517c 201}