]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Entity/Entry.php
CS
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
CommitLineData
9d50517c
NL
1<?php
2
ad4d1caa 3namespace Wallabag\CoreBundle\Entity;
9d50517c 4
0a018fe0 5use Doctrine\Common\Collections\ArrayCollection;
9d50517c 6use Doctrine\ORM\Mapping as ORM;
b84a8055 7use Symfony\Component\Validator\Constraints as Assert;
0f006880
NL
8use Hateoas\Configuration\Annotation as Hateoas;
9use JMS\Serializer\Annotation\XmlRoot;
9d50517c
NL
10
11/**
4346a860 12 * Entry.
9d50517c 13 *
0f006880 14 * @XmlRoot("entry")
be463487 15 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
164bd801 16 * @ORM\Table
34d15eb4 17 * @ORM\HasLifecycleCallbacks()
0f006880 18 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
9d50517c 19 */
be463487 20class Entry
9d50517c 21{
0f006880 22 /** @Serializer\XmlAttribute */
9d50517c 23 /**
4346a860 24 * @var int
9d50517c 25 *
be463487 26 * @ORM\Column(name="id", type="integer")
9d50517c 27 * @ORM\Id
34d15eb4 28 * @ORM\GeneratedValue(strategy="AUTO")
9d50517c 29 */
be463487 30 private $id;
9d50517c
NL
31
32 /**
33 * @var string
34 *
35 * @ORM\Column(name="title", type="text", nullable=true)
36 */
37 private $title;
38
39 /**
40 * @var string
41 *
b84a8055 42 * @Assert\NotBlank()
9d50517c
NL
43 * @ORM\Column(name="url", type="text", nullable=true)
44 */
45 private $url;
46
47 /**
4346a860 48 * @var bool
9d50517c 49 *
be463487 50 * @ORM\Column(name="is_archived", type="boolean")
9d50517c 51 */
905ae369 52 private $isArchived = false;
9d50517c
NL
53
54 /**
4346a860 55 * @var bool
9d50517c 56 *
be463487 57 * @ORM\Column(name="is_starred", type="boolean")
9d50517c 58 */
905ae369 59 private $isStarred = false;
9d50517c 60
9d50517c
NL
61 /**
62 * @var string
63 *
eacaf7f8 64 * @ORM\Column(name="content", type="text", nullable=true)
9d50517c 65 */
eacaf7f8 66 private $content;
9d50517c 67
34d15eb4
NL
68 /**
69 * @var date
70 *
be463487 71 * @ORM\Column(name="created_at", type="datetime")
34d15eb4
NL
72 */
73 private $createdAt;
74
75 /**
76 * @var date
77 *
be463487 78 * @ORM\Column(name="updated_at", type="datetime")
34d15eb4
NL
79 */
80 private $updatedAt;
81
34d15eb4
NL
82 /**
83 * @var string
84 *
85 * @ORM\Column(name="comments", type="text", nullable=true)
86 */
87 private $comments;
88
89 /**
90 * @var string
91 *
92 * @ORM\Column(name="mimetype", type="text", nullable=true)
93 */
94 private $mimetype;
95
96 /**
4346a860 97 * @var int
34d15eb4
NL
98 *
99 * @ORM\Column(name="reading_type", type="integer", nullable=true)
100 */
101 private $readingTime;
102
103 /**
104 * @var string
105 *
106 * @ORM\Column(name="domain_name", type="text", nullable=true)
107 */
108 private $domainName;
109
110 /**
4346a860 111 * @var bool
34d15eb4
NL
112 *
113 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
114 */
115 private $isPublic;
116
5f09650e
NL
117 /**
118 * @ORM\ManyToOne(targetEntity="User", inversedBy="entries")
119 */
120 private $user;
121
0a018fe0 122 /**
46bbd8d3 123 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
164bd801 124 * @ORM\JoinTable
0a018fe0
NL
125 */
126 private $tags;
127
5f09650e
NL
128 /*
129 * @param User $user
130 */
131 public function __construct(User $user)
132 {
133 $this->user = $user;
0a018fe0 134 $this->tags = new ArrayCollection();
5f09650e
NL
135 }
136
9d50517c 137 /**
4346a860 138 * Get id.
9d50517c 139 *
4346a860 140 * @return int
9d50517c
NL
141 */
142 public function getId()
143 {
144 return $this->id;
145 }
146
147 /**
4346a860
JB
148 * Set title.
149 *
150 * @param string $title
9d50517c 151 *
be463487 152 * @return Entry
9d50517c
NL
153 */
154 public function setTitle($title)
155 {
156 $this->title = $title;
157
158 return $this;
159 }
160
161 /**
4346a860 162 * Get title.
9d50517c 163 *
7df80cb3 164 * @return string
9d50517c
NL
165 */
166 public function getTitle()
167 {
168 return $this->title;
169 }
170
171 /**
4346a860
JB
172 * Set url.
173 *
174 * @param string $url
9d50517c 175 *
be463487 176 * @return Entry
9d50517c
NL
177 */
178 public function setUrl($url)
179 {
180 $this->url = $url;
181
182 return $this;
183 }
184
185 /**
4346a860 186 * Get url.
9d50517c 187 *
7df80cb3 188 * @return string
9d50517c
NL
189 */
190 public function getUrl()
191 {
192 return $this->url;
193 }
194
195 /**
4346a860
JB
196 * Set isArchived.
197 *
198 * @param string $isArchived
9d50517c 199 *
be463487 200 * @return Entry
9d50517c 201 */
905ae369 202 public function setArchived($isArchived)
9d50517c 203 {
905ae369 204 $this->isArchived = $isArchived;
9d50517c
NL
205
206 return $this;
207 }
208
209 /**
4346a860 210 * Get isArchived.
9d50517c 211 *
7df80cb3 212 * @return string
9d50517c 213 */
905ae369 214 public function isArchived()
9d50517c 215 {
905ae369 216 return $this->isArchived;
9d50517c
NL
217 }
218
163eae0b
NL
219 public function toggleArchive()
220 {
905ae369 221 $this->isArchived = $this->isArchived() ^ 1;
7df80cb3 222
163eae0b
NL
223 return $this;
224 }
225
9d50517c 226 /**
4346a860
JB
227 * Set isStarred.
228 *
229 * @param string $isStarred
9d50517c 230 *
be463487 231 * @return Entry
9d50517c 232 */
905ae369 233 public function setStarred($isStarred)
9d50517c 234 {
905ae369 235 $this->isStarred = $isStarred;
9d50517c
NL
236
237 return $this;
238 }
239
240 /**
4346a860 241 * Get isStarred.
9d50517c 242 *
7df80cb3 243 * @return string
9d50517c 244 */
905ae369 245 public function isStarred()
9d50517c 246 {
905ae369 247 return $this->isStarred;
9d50517c
NL
248 }
249
163eae0b
NL
250 public function toggleStar()
251 {
905ae369 252 $this->isStarred = $this->isStarred() ^ 1;
163eae0b
NL
253
254 return $this;
255 }
256
9d50517c 257 /**
4346a860
JB
258 * Set content.
259 *
260 * @param string $content
9d50517c 261 *
be463487 262 * @return Entry
9d50517c
NL
263 */
264 public function setContent($content)
265 {
266 $this->content = $content;
267
268 return $this;
269 }
270
271 /**
4346a860 272 * Get content.
9d50517c 273 *
7df80cb3 274 * @return string
9d50517c
NL
275 */
276 public function getContent()
277 {
278 return $this->content;
279 }
280
281 /**
5f09650e 282 * @return User
9d50517c 283 */
5f09650e 284 public function getUser()
9d50517c 285 {
5f09650e 286 return $this->user;
9d50517c 287 }
42a90646 288
34d15eb4 289 /**
2f69eb4a 290 * @return string
34d15eb4
NL
291 */
292 public function getCreatedAt()
293 {
294 return $this->createdAt;
295 }
296
34d15eb4
NL
297 /**
298 * @return string
299 */
300 public function getUpdatedAt()
301 {
302 return $this->updatedAt;
303 }
304
305 /**
be463487 306 * @ORM\PrePersist
34d15eb4
NL
307 * @ORM\PreUpdate
308 */
be463487 309 public function timestamps()
34d15eb4 310 {
be463487
NL
311 if (is_null($this->createdAt)) {
312 $this->createdAt = new \DateTime();
313 }
314
34d15eb4
NL
315 $this->updatedAt = new \DateTime();
316 }
317
318 /**
319 * @return string
320 */
321 public function getComments()
322 {
323 return $this->comments;
324 }
325
326 /**
327 * @param string $comments
328 */
329 public function setComments($comments)
330 {
331 $this->comments = $comments;
332 }
333
334 /**
335 * @return string
336 */
337 public function getMimetype()
338 {
339 return $this->mimetype;
340 }
341
342 /**
343 * @param string $mimetype
344 */
345 public function setMimetype($mimetype)
346 {
347 $this->mimetype = $mimetype;
348 }
349
350 /**
351 * @return int
352 */
353 public function getReadingTime()
354 {
355 return $this->readingTime;
356 }
357
358 /**
359 * @param int $readingTime
360 */
361 public function setReadingTime($readingTime)
362 {
363 $this->readingTime = $readingTime;
364 }
365
366 /**
367 * @return string
368 */
369 public function getDomainName()
370 {
371 return $this->domainName;
372 }
373
374 /**
375 * @param string $domainName
376 */
377 public function setDomainName($domainName)
378 {
379 $this->domainName = $domainName;
380 }
381
382 /**
4346a860 383 * @return bool
34d15eb4 384 */
2c093b03 385 public function isPublic()
34d15eb4
NL
386 {
387 return $this->isPublic;
388 }
389
390 /**
4346a860 391 * @param bool $isPublic
34d15eb4 392 */
2c093b03 393 public function setPublic($isPublic)
34d15eb4
NL
394 {
395 $this->isPublic = $isPublic;
396 }
0a018fe0
NL
397
398 /**
399 * @return ArrayCollection<Tag>
400 */
401 public function getTags()
402 {
403 return $this->tags;
404 }
405
406 /**
407 * @param Tag $tag
408 */
409 public function addTag(Tag $tag)
410 {
411 $this->tags[] = $tag;
46bbd8d3 412 $tag->addEntry($this);
0a018fe0 413 }
092ca707
NL
414
415 public function removeTag(Tag $tag)
416 {
417 $this->tags->removeElement($tag);
418 }
9d50517c 419}