aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Entity/User.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/UserBundle/Entity/User.php')
-rw-r--r--src/Wallabag/UserBundle/Entity/User.php204
1 files changed, 204 insertions, 0 deletions
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php
new file mode 100644
index 00000000..8f02e070
--- /dev/null
+++ b/src/Wallabag/UserBundle/Entity/User.php
@@ -0,0 +1,204 @@
1<?php
2
3namespace Wallabag\UserBundle\Entity;
4
5use Doctrine\Common\Collections\ArrayCollection;
6use Doctrine\ORM\Mapping as ORM;
7use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
8use Symfony\Component\Security\Core\User\UserInterface;
9use JMS\Serializer\Annotation\ExclusionPolicy;
10use JMS\Serializer\Annotation\Expose;
11use FOS\UserBundle\Model\User as BaseUser;
12use Wallabag\CoreBundle\Entity\Config;
13use Wallabag\CoreBundle\Entity\Entry;
14use Wallabag\CoreBundle\Entity\Tag;
15
16/**
17 * User.
18 *
19 * @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository")
20 * @ORM\Table
21 * @ORM\HasLifecycleCallbacks()
22 * @ExclusionPolicy("all")
23 *
24 * @UniqueEntity("email")
25 * @UniqueEntity("username")
26 */
27class User extends BaseUser
28{
29 /**
30 * @var int
31 *
32 * @Expose
33 * @ORM\Column(name="id", type="integer")
34 * @ORM\Id
35 * @ORM\GeneratedValue(strategy="AUTO")
36 */
37 protected $id;
38
39 /**
40 * @var string
41 *
42 * @ORM\Column(name="name", type="text", nullable=true)
43 */
44 protected $name;
45
46 /**
47 * @var date
48 *
49 * @ORM\Column(name="created_at", type="datetime")
50 */
51 protected $createdAt;
52
53 /**
54 * @var date
55 *
56 * @ORM\Column(name="updated_at", type="datetime")
57 */
58 protected $updatedAt;
59
60 /**
61 * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\Entry", mappedBy="user", cascade={"remove"})
62 */
63 protected $entries;
64
65 /**
66 * @ORM\OneToOne(targetEntity="Wallabag\CoreBundle\Entity\Config", mappedBy="user")
67 */
68 protected $config;
69
70 /**
71 * @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\Tag", mappedBy="user", cascade={"remove"})
72 */
73 protected $tags;
74
75 public function __construct()
76 {
77 parent::__construct();
78 $this->entries = new ArrayCollection();
79 $this->tags = new ArrayCollection();
80 $this->roles = array('ROLE_USER');
81 }
82
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
96 /**
97 * Set name.
98 *
99 * @param string $name
100 *
101 * @return User
102 */
103 public function setName($name)
104 {
105 $this->name = $name;
106
107 return $this;
108 }
109
110 /**
111 * Get name.
112 *
113 * @return string
114 */
115 public function getName()
116 {
117 return $this->name;
118 }
119
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
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
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 }
175
176 public function isEqualTo(UserInterface $user)
177 {
178 return $this->username === $user->getUsername();
179 }
180
181 /**
182 * Set config.
183 *
184 * @param Config $config
185 *
186 * @return User
187 */
188 public function setConfig(Config $config = null)
189 {
190 $this->config = $config;
191
192 return $this;
193 }
194
195 /**
196 * Get config.
197 *
198 * @return Config
199 */
200 public function getConfig()
201 {
202 return $this->config;
203 }
204}