]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Entity/Entry.php
Move readingTime & domainName in ContentProxy
[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
98f0929f
JB
96 /**
97 * @var string
98 *
99 * @ORM\Column(name="language", type="text", nullable=true)
100 */
101 private $language;
102
34d15eb4 103 /**
4346a860 104 * @var int
34d15eb4 105 *
26864574 106 * @ORM\Column(name="reading_time", type="integer", nullable=true)
34d15eb4
NL
107 */
108 private $readingTime;
109
110 /**
111 * @var string
112 *
113 * @ORM\Column(name="domain_name", type="text", nullable=true)
114 */
115 private $domainName;
116
fad31615
JB
117 /**
118 * @var string
119 *
120 * @ORM\Column(name="preview_picture", type="text", nullable=true)
121 */
122 private $previewPicture;
123
34d15eb4 124 /**
4346a860 125 * @var bool
34d15eb4
NL
126 *
127 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
128 */
129 private $isPublic;
130
5f09650e
NL
131 /**
132 * @ORM\ManyToOne(targetEntity="User", inversedBy="entries")
133 */
134 private $user;
135
0a018fe0 136 /**
46bbd8d3 137 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
164bd801 138 * @ORM\JoinTable
0a018fe0
NL
139 */
140 private $tags;
141
5f09650e
NL
142 /*
143 * @param User $user
144 */
145 public function __construct(User $user)
146 {
147 $this->user = $user;
0a018fe0 148 $this->tags = new ArrayCollection();
5f09650e
NL
149 }
150
9d50517c 151 /**
4346a860 152 * Get id.
9d50517c 153 *
4346a860 154 * @return int
9d50517c
NL
155 */
156 public function getId()
157 {
158 return $this->id;
159 }
160
161 /**
4346a860
JB
162 * Set title.
163 *
164 * @param string $title
9d50517c 165 *
be463487 166 * @return Entry
9d50517c
NL
167 */
168 public function setTitle($title)
169 {
170 $this->title = $title;
171
172 return $this;
173 }
174
175 /**
4346a860 176 * Get title.
9d50517c 177 *
7df80cb3 178 * @return string
9d50517c
NL
179 */
180 public function getTitle()
181 {
182 return $this->title;
183 }
184
185 /**
4346a860
JB
186 * Set url.
187 *
188 * @param string $url
9d50517c 189 *
be463487 190 * @return Entry
9d50517c
NL
191 */
192 public function setUrl($url)
193 {
194 $this->url = $url;
195
196 return $this;
197 }
198
199 /**
4346a860 200 * Get url.
9d50517c 201 *
7df80cb3 202 * @return string
9d50517c
NL
203 */
204 public function getUrl()
205 {
206 return $this->url;
207 }
208
209 /**
4346a860
JB
210 * Set isArchived.
211 *
212 * @param string $isArchived
9d50517c 213 *
be463487 214 * @return Entry
9d50517c 215 */
905ae369 216 public function setArchived($isArchived)
9d50517c 217 {
905ae369 218 $this->isArchived = $isArchived;
9d50517c
NL
219
220 return $this;
221 }
222
223 /**
4346a860 224 * Get isArchived.
9d50517c 225 *
7df80cb3 226 * @return string
9d50517c 227 */
905ae369 228 public function isArchived()
9d50517c 229 {
905ae369 230 return $this->isArchived;
9d50517c
NL
231 }
232
163eae0b
NL
233 public function toggleArchive()
234 {
905ae369 235 $this->isArchived = $this->isArchived() ^ 1;
7df80cb3 236
163eae0b
NL
237 return $this;
238 }
239
9d50517c 240 /**
4346a860
JB
241 * Set isStarred.
242 *
243 * @param string $isStarred
9d50517c 244 *
be463487 245 * @return Entry
9d50517c 246 */
905ae369 247 public function setStarred($isStarred)
9d50517c 248 {
905ae369 249 $this->isStarred = $isStarred;
9d50517c
NL
250
251 return $this;
252 }
253
254 /**
4346a860 255 * Get isStarred.
9d50517c 256 *
7df80cb3 257 * @return string
9d50517c 258 */
905ae369 259 public function isStarred()
9d50517c 260 {
905ae369 261 return $this->isStarred;
9d50517c
NL
262 }
263
163eae0b
NL
264 public function toggleStar()
265 {
905ae369 266 $this->isStarred = $this->isStarred() ^ 1;
163eae0b
NL
267
268 return $this;
269 }
270
9d50517c 271 /**
4346a860
JB
272 * Set content.
273 *
274 * @param string $content
9d50517c 275 *
be463487 276 * @return Entry
9d50517c
NL
277 */
278 public function setContent($content)
279 {
280 $this->content = $content;
281
282 return $this;
283 }
284
285 /**
4346a860 286 * Get content.
9d50517c 287 *
7df80cb3 288 * @return string
9d50517c
NL
289 */
290 public function getContent()
291 {
292 return $this->content;
293 }
294
295 /**
5f09650e 296 * @return User
9d50517c 297 */
5f09650e 298 public function getUser()
9d50517c 299 {
5f09650e 300 return $this->user;
9d50517c 301 }
42a90646 302
34d15eb4 303 /**
2f69eb4a 304 * @return string
34d15eb4
NL
305 */
306 public function getCreatedAt()
307 {
308 return $this->createdAt;
309 }
310
34d15eb4
NL
311 /**
312 * @return string
313 */
314 public function getUpdatedAt()
315 {
316 return $this->updatedAt;
317 }
318
319 /**
be463487 320 * @ORM\PrePersist
34d15eb4
NL
321 * @ORM\PreUpdate
322 */
be463487 323 public function timestamps()
34d15eb4 324 {
be463487
NL
325 if (is_null($this->createdAt)) {
326 $this->createdAt = new \DateTime();
327 }
328
34d15eb4
NL
329 $this->updatedAt = new \DateTime();
330 }
331
332 /**
333 * @return string
334 */
335 public function getComments()
336 {
337 return $this->comments;
338 }
339
340 /**
341 * @param string $comments
342 */
343 public function setComments($comments)
344 {
345 $this->comments = $comments;
346 }
347
348 /**
349 * @return string
350 */
351 public function getMimetype()
352 {
353 return $this->mimetype;
354 }
355
356 /**
357 * @param string $mimetype
358 */
359 public function setMimetype($mimetype)
360 {
361 $this->mimetype = $mimetype;
362 }
363
364 /**
365 * @return int
366 */
367 public function getReadingTime()
368 {
369 return $this->readingTime;
370 }
371
372 /**
373 * @param int $readingTime
374 */
375 public function setReadingTime($readingTime)
376 {
377 $this->readingTime = $readingTime;
378 }
379
380 /**
381 * @return string
382 */
383 public function getDomainName()
384 {
385 return $this->domainName;
386 }
387
388 /**
389 * @param string $domainName
390 */
391 public function setDomainName($domainName)
392 {
393 $this->domainName = $domainName;
394 }
395
396 /**
4346a860 397 * @return bool
34d15eb4 398 */
2c093b03 399 public function isPublic()
34d15eb4
NL
400 {
401 return $this->isPublic;
402 }
403
404 /**
4346a860 405 * @param bool $isPublic
34d15eb4 406 */
82d6d9cb 407 public function setIsPublic($isPublic)
34d15eb4
NL
408 {
409 $this->isPublic = $isPublic;
410 }
0a018fe0
NL
411
412 /**
413 * @return ArrayCollection<Tag>
414 */
415 public function getTags()
416 {
417 return $this->tags;
418 }
419
420 /**
421 * @param Tag $tag
422 */
423 public function addTag(Tag $tag)
424 {
425 $this->tags[] = $tag;
46bbd8d3 426 $tag->addEntry($this);
0a018fe0 427 }
092ca707
NL
428
429 public function removeTag(Tag $tag)
430 {
431 $this->tags->removeElement($tag);
432 }
fad31615
JB
433
434 /**
a1413a3d 435 * Set previewPicture.
fad31615
JB
436 *
437 * @param string $previewPicture
438 *
439 * @return Entry
440 */
441 public function setPreviewPicture($previewPicture)
442 {
443 $this->previewPicture = $previewPicture;
444
445 return $this;
446 }
447
448 /**
a1413a3d 449 * Get previewPicture.
fad31615
JB
450 *
451 * @return string
452 */
453 public function getPreviewPicture()
454 {
455 return $this->previewPicture;
456 }
98f0929f
JB
457
458 /**
459 * Set language.
460 *
461 * @param string $language
462 *
463 * @return Entry
464 */
465 public function setLanguage($language)
466 {
467 $this->language = $language;
468
469 return $this;
470 }
471
472 /**
473 * Get language.
474 *
475 * @return string
476 */
477 public function getLanguage()
478 {
479 return $this->language;
480 }
9d50517c 481}