]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Entity/Entry.php
Move readingTime & domainName in ContentProxy
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Entity;
4
5 use Doctrine\Common\Collections\ArrayCollection;
6 use Doctrine\ORM\Mapping as ORM;
7 use Symfony\Component\Validator\Constraints as Assert;
8 use Hateoas\Configuration\Annotation as Hateoas;
9 use JMS\Serializer\Annotation\XmlRoot;
10
11 /**
12 * Entry.
13 *
14 * @XmlRoot("entry")
15 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
16 * @ORM\Table
17 * @ORM\HasLifecycleCallbacks()
18 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
19 */
20 class Entry
21 {
22 /** @Serializer\XmlAttribute */
23 /**
24 * @var int
25 *
26 * @ORM\Column(name="id", type="integer")
27 * @ORM\Id
28 * @ORM\GeneratedValue(strategy="AUTO")
29 */
30 private $id;
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 *
42 * @Assert\NotBlank()
43 * @ORM\Column(name="url", type="text", nullable=true)
44 */
45 private $url;
46
47 /**
48 * @var bool
49 *
50 * @ORM\Column(name="is_archived", type="boolean")
51 */
52 private $isArchived = false;
53
54 /**
55 * @var bool
56 *
57 * @ORM\Column(name="is_starred", type="boolean")
58 */
59 private $isStarred = false;
60
61 /**
62 * @var string
63 *
64 * @ORM\Column(name="content", type="text", nullable=true)
65 */
66 private $content;
67
68 /**
69 * @var date
70 *
71 * @ORM\Column(name="created_at", type="datetime")
72 */
73 private $createdAt;
74
75 /**
76 * @var date
77 *
78 * @ORM\Column(name="updated_at", type="datetime")
79 */
80 private $updatedAt;
81
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 /**
97 * @var string
98 *
99 * @ORM\Column(name="language", type="text", nullable=true)
100 */
101 private $language;
102
103 /**
104 * @var int
105 *
106 * @ORM\Column(name="reading_time", type="integer", nullable=true)
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
117 /**
118 * @var string
119 *
120 * @ORM\Column(name="preview_picture", type="text", nullable=true)
121 */
122 private $previewPicture;
123
124 /**
125 * @var bool
126 *
127 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
128 */
129 private $isPublic;
130
131 /**
132 * @ORM\ManyToOne(targetEntity="User", inversedBy="entries")
133 */
134 private $user;
135
136 /**
137 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
138 * @ORM\JoinTable
139 */
140 private $tags;
141
142 /*
143 * @param User $user
144 */
145 public function __construct(User $user)
146 {
147 $this->user = $user;
148 $this->tags = new ArrayCollection();
149 }
150
151 /**
152 * Get id.
153 *
154 * @return int
155 */
156 public function getId()
157 {
158 return $this->id;
159 }
160
161 /**
162 * Set title.
163 *
164 * @param string $title
165 *
166 * @return Entry
167 */
168 public function setTitle($title)
169 {
170 $this->title = $title;
171
172 return $this;
173 }
174
175 /**
176 * Get title.
177 *
178 * @return string
179 */
180 public function getTitle()
181 {
182 return $this->title;
183 }
184
185 /**
186 * Set url.
187 *
188 * @param string $url
189 *
190 * @return Entry
191 */
192 public function setUrl($url)
193 {
194 $this->url = $url;
195
196 return $this;
197 }
198
199 /**
200 * Get url.
201 *
202 * @return string
203 */
204 public function getUrl()
205 {
206 return $this->url;
207 }
208
209 /**
210 * Set isArchived.
211 *
212 * @param string $isArchived
213 *
214 * @return Entry
215 */
216 public function setArchived($isArchived)
217 {
218 $this->isArchived = $isArchived;
219
220 return $this;
221 }
222
223 /**
224 * Get isArchived.
225 *
226 * @return string
227 */
228 public function isArchived()
229 {
230 return $this->isArchived;
231 }
232
233 public function toggleArchive()
234 {
235 $this->isArchived = $this->isArchived() ^ 1;
236
237 return $this;
238 }
239
240 /**
241 * Set isStarred.
242 *
243 * @param string $isStarred
244 *
245 * @return Entry
246 */
247 public function setStarred($isStarred)
248 {
249 $this->isStarred = $isStarred;
250
251 return $this;
252 }
253
254 /**
255 * Get isStarred.
256 *
257 * @return string
258 */
259 public function isStarred()
260 {
261 return $this->isStarred;
262 }
263
264 public function toggleStar()
265 {
266 $this->isStarred = $this->isStarred() ^ 1;
267
268 return $this;
269 }
270
271 /**
272 * Set content.
273 *
274 * @param string $content
275 *
276 * @return Entry
277 */
278 public function setContent($content)
279 {
280 $this->content = $content;
281
282 return $this;
283 }
284
285 /**
286 * Get content.
287 *
288 * @return string
289 */
290 public function getContent()
291 {
292 return $this->content;
293 }
294
295 /**
296 * @return User
297 */
298 public function getUser()
299 {
300 return $this->user;
301 }
302
303 /**
304 * @return string
305 */
306 public function getCreatedAt()
307 {
308 return $this->createdAt;
309 }
310
311 /**
312 * @return string
313 */
314 public function getUpdatedAt()
315 {
316 return $this->updatedAt;
317 }
318
319 /**
320 * @ORM\PrePersist
321 * @ORM\PreUpdate
322 */
323 public function timestamps()
324 {
325 if (is_null($this->createdAt)) {
326 $this->createdAt = new \DateTime();
327 }
328
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 /**
397 * @return bool
398 */
399 public function isPublic()
400 {
401 return $this->isPublic;
402 }
403
404 /**
405 * @param bool $isPublic
406 */
407 public function setIsPublic($isPublic)
408 {
409 $this->isPublic = $isPublic;
410 }
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;
426 $tag->addEntry($this);
427 }
428
429 public function removeTag(Tag $tag)
430 {
431 $this->tags->removeElement($tag);
432 }
433
434 /**
435 * Set previewPicture.
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 /**
449 * Get previewPicture.
450 *
451 * @return string
452 */
453 public function getPreviewPicture()
454 {
455 return $this->previewPicture;
456 }
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 }
481 }