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