]>
Commit | Line | Data |
---|---|---|
9d50517c NL |
1 | <?php |
2 | ||
ad4d1caa | 3 | namespace Wallabag\CoreBundle\Entity; |
9d50517c | 4 | |
0a018fe0 | 5 | use Doctrine\Common\Collections\ArrayCollection; |
9d50517c | 6 | use Doctrine\ORM\Mapping as ORM; |
0f006880 | 7 | use Hateoas\Configuration\Annotation as Hateoas; |
7d1fdab2 | 8 | use JMS\Serializer\Annotation\Exclude; |
f808b016 | 9 | use JMS\Serializer\Annotation\Groups; |
7d1fdab2 | 10 | use JMS\Serializer\Annotation\SerializedName; |
f808b016 JB |
11 | use JMS\Serializer\Annotation\VirtualProperty; |
12 | use JMS\Serializer\Annotation\XmlRoot; | |
619cc453 | 13 | use Symfony\Component\Validator\Constraints as Assert; |
4dc87223 | 14 | use Wallabag\AnnotationBundle\Entity\Annotation; |
927c9e79 | 15 | use Wallabag\CoreBundle\Helper\EntityTimestampsTrait; |
4a551637 | 16 | use Wallabag\CoreBundle\Helper\UrlHasher; |
f808b016 | 17 | use Wallabag\UserBundle\Entity\User; |
9d50517c NL |
18 | |
19 | /** | |
4346a860 | 20 | * Entry. |
9d50517c | 21 | * |
0f006880 | 22 | * @XmlRoot("entry") |
be463487 | 23 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") |
7e9c1d65 JB |
24 | * @ORM\Table( |
25 | * name="`entry`", | |
26 | * options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}, | |
81375151 NL |
27 | * indexes={ |
28 | * @ORM\Index(name="created_at", columns={"created_at"}), | |
bfe02a0b | 29 | * @ORM\Index(name="uid", columns={"uid"}), |
5cc0646e | 30 | * @ORM\Index(name="hashed_url_user_id", columns={"user_id", "hashed_url"}, options={"lengths"={null, 40}}) |
b7fa51ae NL |
31 | * }, |
32 | * uniqueConstraints={@ORM\UniqueConstraint(name="IDX_entry_given_url",columns={"url", "given_url", "user_id"})} | |
7e9c1d65 | 33 | * ) |
34d15eb4 | 34 | * @ORM\HasLifecycleCallbacks() |
0f006880 | 35 | * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") |
9d50517c | 36 | */ |
be463487 | 37 | class Entry |
9d50517c | 38 | { |
927c9e79 JB |
39 | use EntityTimestampsTrait; |
40 | ||
0f006880 | 41 | /** @Serializer\XmlAttribute */ |
9d50517c | 42 | /** |
4346a860 | 43 | * @var int |
9d50517c | 44 | * |
be463487 | 45 | * @ORM\Column(name="id", type="integer") |
9d50517c | 46 | * @ORM\Id |
34d15eb4 | 47 | * @ORM\GeneratedValue(strategy="AUTO") |
5b7da076 TC |
48 | * |
49 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 50 | */ |
be463487 | 51 | private $id; |
9d50517c | 52 | |
f3d0cb91 | 53 | /** |
78b3c31d | 54 | * @var string |
f3d0cb91 | 55 | * |
7239082a | 56 | * @ORM\Column(name="uid", type="string", length=23, nullable=true) |
f3d0cb91 NL |
57 | * |
58 | * @Groups({"entries_for_user", "export_all"}) | |
59 | */ | |
7239082a | 60 | private $uid; |
f3d0cb91 | 61 | |
9d50517c NL |
62 | /** |
63 | * @var string | |
64 | * | |
65 | * @ORM\Column(name="title", type="text", nullable=true) | |
5b7da076 TC |
66 | * |
67 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c NL |
68 | */ |
69 | private $title; | |
70 | ||
b7fa51ae NL |
71 | /** |
72 | * @var string | |
73 | * | |
74 | * @ORM\Column(name="given_url", type="text", nullable=true) | |
75 | * | |
76 | * @Groups({"entries_for_user", "export_all"}) | |
77 | */ | |
78 | private $givenUrl; | |
79 | ||
9d50517c NL |
80 | /** |
81 | * @var string | |
82 | * | |
b84a8055 | 83 | * @Assert\NotBlank() |
9d50517c | 84 | * @ORM\Column(name="url", type="text", nullable=true) |
5b7da076 TC |
85 | * |
86 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c NL |
87 | */ |
88 | private $url; | |
89 | ||
bfe02a0b TC |
90 | /** |
91 | * @var string | |
92 | * | |
8a645662 | 93 | * @ORM\Column(name="hashed_url", type="string", length=40, nullable=true) |
bfe02a0b TC |
94 | */ |
95 | private $hashedUrl; | |
96 | ||
9d50517c | 97 | /** |
4346a860 | 98 | * @var bool |
9d50517c | 99 | * |
189ef634 TC |
100 | * @Exclude |
101 | * | |
be463487 | 102 | * @ORM\Column(name="is_archived", type="boolean") |
5b7da076 TC |
103 | * |
104 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 105 | */ |
905ae369 | 106 | private $isArchived = false; |
9d50517c | 107 | |
7975395d SV |
108 | /** |
109 | * @var \DateTime | |
110 | * | |
111 | * @ORM\Column(name="archived_at", type="datetime", nullable=true) | |
112 | * | |
113 | * @Groups({"entries_for_user", "export_all"}) | |
114 | */ | |
115 | private $archivedAt = null; | |
116 | ||
9d50517c | 117 | /** |
4346a860 | 118 | * @var bool |
9d50517c | 119 | * |
189ef634 TC |
120 | * @Exclude |
121 | * | |
be463487 | 122 | * @ORM\Column(name="is_starred", type="boolean") |
5b7da076 TC |
123 | * |
124 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 125 | */ |
905ae369 | 126 | private $isStarred = false; |
9d50517c | 127 | |
9d50517c NL |
128 | /** |
129 | * @var string | |
130 | * | |
eacaf7f8 | 131 | * @ORM\Column(name="content", type="text", nullable=true) |
5b7da076 TC |
132 | * |
133 | * @Groups({"entries_for_user", "export_all"}) | |
9d50517c | 134 | */ |
eacaf7f8 | 135 | private $content; |
9d50517c | 136 | |
34d15eb4 | 137 | /** |
8664069e | 138 | * @var \DateTime |
34d15eb4 | 139 | * |
be463487 | 140 | * @ORM\Column(name="created_at", type="datetime") |
5b7da076 | 141 | * |
9401696f | 142 | * @Groups({"entries_for_user", "export_all"}) |
34d15eb4 NL |
143 | */ |
144 | private $createdAt; | |
145 | ||
146 | /** | |
8664069e | 147 | * @var \DateTime |
34d15eb4 | 148 | * |
be463487 | 149 | * @ORM\Column(name="updated_at", type="datetime") |
5b7da076 | 150 | * |
9401696f | 151 | * @Groups({"entries_for_user", "export_all"}) |
34d15eb4 NL |
152 | */ |
153 | private $updatedAt; | |
154 | ||
5e9009ce NL |
155 | /** |
156 | * @var \DateTime | |
157 | * | |
158 | * @ORM\Column(name="published_at", type="datetime", nullable=true) | |
159 | * | |
160 | * @Groups({"entries_for_user", "export_all"}) | |
161 | */ | |
162 | private $publishedAt; | |
163 | ||
7b0b3622 NL |
164 | /** |
165 | * @var array | |
166 | * | |
1517d577 | 167 | * @ORM\Column(name="published_by", type="array", nullable=true) |
7b0b3622 NL |
168 | * |
169 | * @Groups({"entries_for_user", "export_all"}) | |
170 | */ | |
171 | private $publishedBy; | |
172 | ||
a991c46e F |
173 | /** |
174 | * @var \DateTime | |
175 | * | |
176 | * @ORM\Column(name="starred_at", type="datetime", nullable=true) | |
177 | * | |
178 | * @Groups({"entries_for_user", "export_all"}) | |
179 | */ | |
180 | private $starredAt = null; | |
181 | ||
34d15eb4 | 182 | /** |
4dc87223 | 183 | * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"}) |
f38e03dc | 184 | * @ORM\JoinTable |
5b7da076 | 185 | * |
f38e03dc | 186 | * @Groups({"entries_for_user", "export_all"}) |
34d15eb4 | 187 | */ |
4dc87223 | 188 | private $annotations; |
34d15eb4 NL |
189 | |
190 | /** | |
191 | * @var string | |
192 | * | |
193 | * @ORM\Column(name="mimetype", type="text", nullable=true) | |
5b7da076 TC |
194 | * |
195 | * @Groups({"entries_for_user", "export_all"}) | |
34d15eb4 NL |
196 | */ |
197 | private $mimetype; | |
198 | ||
98f0929f JB |
199 | /** |
200 | * @var string | |
201 | * | |
202 | * @ORM\Column(name="language", type="text", nullable=true) | |
5b7da076 TC |
203 | * |
204 | * @Groups({"entries_for_user", "export_all"}) | |
98f0929f JB |
205 | */ |
206 | private $language; | |
207 | ||
34d15eb4 | 208 | /** |
4346a860 | 209 | * @var int |
34d15eb4 | 210 | * |
88bac4a3 | 211 | * @ORM\Column(name="reading_time", type="integer", nullable=false) |
5b7da076 TC |
212 | * |
213 | * @Groups({"entries_for_user", "export_all"}) | |
34d15eb4 | 214 | */ |
88bac4a3 | 215 | private $readingTime = 0; |
34d15eb4 NL |
216 | |
217 | /** | |
218 | * @var string | |
219 | * | |
220 | * @ORM\Column(name="domain_name", type="text", nullable=true) | |
5b7da076 TC |
221 | * |
222 | * @Groups({"entries_for_user", "export_all"}) | |
34d15eb4 NL |
223 | */ |
224 | private $domainName; | |
225 | ||
fad31615 JB |
226 | /** |
227 | * @var string | |
228 | * | |
229 | * @ORM\Column(name="preview_picture", type="text", nullable=true) | |
5b7da076 TC |
230 | * |
231 | * @Groups({"entries_for_user", "export_all"}) | |
fad31615 JB |
232 | */ |
233 | private $previewPicture; | |
234 | ||
10b35097 | 235 | /** |
e10e6ab3 | 236 | * @var string |
10b35097 | 237 | * |
3ef75cc4 | 238 | * @ORM\Column(name="http_status", type="string", length=3, nullable=true) |
10b35097 NL |
239 | * |
240 | * @Groups({"entries_for_user", "export_all"}) | |
241 | */ | |
242 | private $httpStatus; | |
243 | ||
dda6a6ad NL |
244 | /** |
245 | * @var array | |
246 | * | |
1517d577 | 247 | * @ORM\Column(name="headers", type="array", nullable=true) |
dda6a6ad NL |
248 | * |
249 | * @Groups({"entries_for_user", "export_all"}) | |
250 | */ | |
251 | private $headers; | |
252 | ||
5f09650e | 253 | /** |
7d1fdab2 TC |
254 | * @Exclude |
255 | * | |
1210dae1 | 256 | * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="entries") |
5b7da076 TC |
257 | * |
258 | * @Groups({"export_all"}) | |
5f09650e NL |
259 | */ |
260 | private $user; | |
261 | ||
0a018fe0 | 262 | /** |
af95c09c | 263 | * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) |
e42b13bc JB |
264 | * @ORM\JoinTable( |
265 | * name="entry_tag", | |
266 | * joinColumns={ | |
206bade5 | 267 | * @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade") |
e42b13bc JB |
268 | * }, |
269 | * inverseJoinColumns={ | |
206bade5 | 270 | * @ORM\JoinColumn(name="tag_id", referencedColumnName="id", onDelete="cascade") |
e42b13bc JB |
271 | * } |
272 | * ) | |
0a018fe0 NL |
273 | */ |
274 | private $tags; | |
275 | ||
e0ef1a1c KD |
276 | /** |
277 | * @var string | |
278 | * | |
279 | * @ORM\Column(name="origin_url", type="text", nullable=true) | |
280 | * | |
281 | * @Groups({"entries_for_user", "export_all"}) | |
282 | */ | |
283 | private $originUrl; | |
284 | ||
5f09650e NL |
285 | /* |
286 | * @param User $user | |
287 | */ | |
5d6f6f56 | 288 | public function __construct(User $user) |
5f09650e NL |
289 | { |
290 | $this->user = $user; | |
0a018fe0 | 291 | $this->tags = new ArrayCollection(); |
5f09650e NL |
292 | } |
293 | ||
9d50517c | 294 | /** |
4346a860 | 295 | * Get id. |
9d50517c | 296 | * |
4346a860 | 297 | * @return int |
9d50517c NL |
298 | */ |
299 | public function getId() | |
300 | { | |
301 | return $this->id; | |
302 | } | |
303 | ||
304 | /** | |
4346a860 JB |
305 | * Set title. |
306 | * | |
307 | * @param string $title | |
9d50517c | 308 | * |
be463487 | 309 | * @return Entry |
9d50517c NL |
310 | */ |
311 | public function setTitle($title) | |
312 | { | |
313 | $this->title = $title; | |
314 | ||
315 | return $this; | |
316 | } | |
317 | ||
318 | /** | |
4346a860 | 319 | * Get title. |
9d50517c | 320 | * |
7df80cb3 | 321 | * @return string |
9d50517c NL |
322 | */ |
323 | public function getTitle() | |
324 | { | |
325 | return $this->title; | |
326 | } | |
327 | ||
b7fa51ae NL |
328 | /** |
329 | * Set given url. | |
330 | * | |
331 | * @param string $givenUrl | |
332 | * | |
333 | * @return Entry | |
334 | */ | |
335 | public function setGivenUrl($givenUrl) | |
336 | { | |
337 | $this->givenUrl = $givenUrl; | |
338 | ||
339 | return $this; | |
340 | } | |
341 | ||
342 | /** | |
343 | * Get given Url. | |
344 | * | |
345 | * @return string | |
346 | */ | |
347 | public function getGivenUrl() | |
348 | { | |
349 | return $this->givenUrl; | |
350 | } | |
351 | ||
9d50517c | 352 | /** |
4346a860 JB |
353 | * Set url. |
354 | * | |
355 | * @param string $url | |
9d50517c | 356 | * |
be463487 | 357 | * @return Entry |
9d50517c NL |
358 | */ |
359 | public function setUrl($url) | |
360 | { | |
361 | $this->url = $url; | |
4a551637 | 362 | $this->hashedUrl = UrlHasher::hashUrl($url); |
9d50517c NL |
363 | |
364 | return $this; | |
365 | } | |
366 | ||
367 | /** | |
4346a860 | 368 | * Get url. |
9d50517c | 369 | * |
7df80cb3 | 370 | * @return string |
9d50517c NL |
371 | */ |
372 | public function getUrl() | |
373 | { | |
374 | return $this->url; | |
375 | } | |
376 | ||
377 | /** | |
4346a860 JB |
378 | * Set isArchived. |
379 | * | |
8eedc8cf | 380 | * @param bool $isArchived |
9d50517c | 381 | * |
be463487 | 382 | * @return Entry |
9d50517c | 383 | */ |
905ae369 | 384 | public function setArchived($isArchived) |
9d50517c | 385 | { |
905ae369 | 386 | $this->isArchived = $isArchived; |
9d50517c NL |
387 | |
388 | return $this; | |
389 | } | |
390 | ||
7975395d SV |
391 | /** |
392 | * update isArchived and archive_at fields. | |
393 | * | |
394 | * @param bool $isArchived | |
395 | * | |
396 | * @return Entry | |
397 | */ | |
398 | public function updateArchived($isArchived = false) | |
399 | { | |
400 | $this->setArchived($isArchived); | |
401 | $this->setArchivedAt(null); | |
402 | if ($this->isArchived()) { | |
403 | $this->setArchivedAt(new \DateTime()); | |
404 | } | |
405 | ||
406 | return $this; | |
407 | } | |
408 | ||
409 | /** | |
410 | * @return \DateTime|null | |
411 | */ | |
412 | public function getArchivedAt() | |
413 | { | |
414 | return $this->archivedAt; | |
415 | } | |
416 | ||
417 | /** | |
418 | * @param \DateTime|null $archivedAt | |
419 | * | |
420 | * @return Entry | |
421 | */ | |
422 | public function setArchivedAt($archivedAt = null) | |
423 | { | |
424 | $this->archivedAt = $archivedAt; | |
425 | ||
426 | return $this; | |
427 | } | |
428 | ||
9d50517c | 429 | /** |
4346a860 | 430 | * Get isArchived. |
9d50517c | 431 | * |
8eedc8cf | 432 | * @return bool |
9d50517c | 433 | */ |
905ae369 | 434 | public function isArchived() |
9d50517c | 435 | { |
905ae369 | 436 | return $this->isArchived; |
9d50517c NL |
437 | } |
438 | ||
189ef634 TC |
439 | /** |
440 | * @VirtualProperty | |
441 | * @SerializedName("is_archived") | |
442 | * @Groups({"entries_for_user", "export_all"}) | |
443 | */ | |
444 | public function is_Archived() | |
445 | { | |
446 | return (int) $this->isArchived(); | |
447 | } | |
448 | ||
163eae0b NL |
449 | public function toggleArchive() |
450 | { | |
7975395d | 451 | $this->updateArchived($this->isArchived() ^ 1); |
7df80cb3 | 452 | |
163eae0b NL |
453 | return $this; |
454 | } | |
455 | ||
9d50517c | 456 | /** |
4346a860 JB |
457 | * Set isStarred. |
458 | * | |
8eedc8cf | 459 | * @param bool $isStarred |
9d50517c | 460 | * |
be463487 | 461 | * @return Entry |
9d50517c | 462 | */ |
905ae369 | 463 | public function setStarred($isStarred) |
9d50517c | 464 | { |
905ae369 | 465 | $this->isStarred = $isStarred; |
9d50517c NL |
466 | |
467 | return $this; | |
468 | } | |
469 | ||
470 | /** | |
4346a860 | 471 | * Get isStarred. |
9d50517c | 472 | * |
8eedc8cf | 473 | * @return bool |
9d50517c | 474 | */ |
905ae369 | 475 | public function isStarred() |
9d50517c | 476 | { |
905ae369 | 477 | return $this->isStarred; |
9d50517c NL |
478 | } |
479 | ||
189ef634 TC |
480 | /** |
481 | * @VirtualProperty | |
482 | * @SerializedName("is_starred") | |
483 | * @Groups({"entries_for_user", "export_all"}) | |
484 | */ | |
485 | public function is_Starred() | |
486 | { | |
487 | return (int) $this->isStarred(); | |
488 | } | |
489 | ||
163eae0b NL |
490 | public function toggleStar() |
491 | { | |
905ae369 | 492 | $this->isStarred = $this->isStarred() ^ 1; |
163eae0b NL |
493 | |
494 | return $this; | |
495 | } | |
496 | ||
9d50517c | 497 | /** |
4346a860 JB |
498 | * Set content. |
499 | * | |
500 | * @param string $content | |
9d50517c | 501 | * |
be463487 | 502 | * @return Entry |
9d50517c NL |
503 | */ |
504 | public function setContent($content) | |
505 | { | |
506 | $this->content = $content; | |
507 | ||
508 | return $this; | |
509 | } | |
510 | ||
511 | /** | |
4346a860 | 512 | * Get content. |
9d50517c | 513 | * |
7df80cb3 | 514 | * @return string |
9d50517c NL |
515 | */ |
516 | public function getContent() | |
517 | { | |
518 | return $this->content; | |
519 | } | |
520 | ||
521 | /** | |
5f09650e | 522 | * @return User |
9d50517c | 523 | */ |
5f09650e | 524 | public function getUser() |
9d50517c | 525 | { |
5f09650e | 526 | return $this->user; |
9d50517c | 527 | } |
42a90646 | 528 | |
7d1fdab2 TC |
529 | /** |
530 | * @VirtualProperty | |
531 | * @SerializedName("user_name") | |
532 | */ | |
533 | public function getUserName() | |
534 | { | |
535 | return $this->user->getUserName(); | |
536 | } | |
537 | ||
538 | /** | |
539 | * @VirtualProperty | |
540 | * @SerializedName("user_email") | |
541 | */ | |
542 | public function getUserEmail() | |
543 | { | |
544 | return $this->user->getEmail(); | |
545 | } | |
546 | ||
547 | /** | |
548 | * @VirtualProperty | |
549 | * @SerializedName("user_id") | |
550 | */ | |
551 | public function getUserId() | |
552 | { | |
553 | return $this->user->getId(); | |
554 | } | |
555 | ||
34d15eb4 | 556 | /** |
6d65c0a8 JB |
557 | * Set created_at. |
558 | * Only used when importing data from an other service. | |
559 | * | |
8664069e | 560 | * @param \DateTime $createdAt |
6d65c0a8 JB |
561 | * |
562 | * @return Entry | |
563 | */ | |
564 | public function setCreatedAt(\DateTime $createdAt) | |
565 | { | |
566 | $this->createdAt = $createdAt; | |
567 | ||
568 | return $this; | |
569 | } | |
570 | ||
571 | /** | |
8664069e | 572 | * @return \DateTime |
34d15eb4 NL |
573 | */ |
574 | public function getCreatedAt() | |
575 | { | |
576 | return $this->createdAt; | |
577 | } | |
578 | ||
34d15eb4 | 579 | /** |
8664069e | 580 | * @return \DateTime |
34d15eb4 NL |
581 | */ |
582 | public function getUpdatedAt() | |
583 | { | |
584 | return $this->updatedAt; | |
585 | } | |
586 | ||
a991c46e F |
587 | /** |
588 | * @return \DateTime|null | |
589 | */ | |
590 | public function getStarredAt() | |
591 | { | |
592 | return $this->starredAt; | |
593 | } | |
594 | ||
595 | /** | |
596 | * @param \DateTime|null $starredAt | |
597 | * | |
598 | * @return Entry | |
599 | */ | |
600 | public function setStarredAt($starredAt = null) | |
601 | { | |
602 | $this->starredAt = $starredAt; | |
603 | ||
604 | return $this; | |
605 | } | |
606 | ||
607 | /** | |
608 | * update isStarred and starred_at fields. | |
609 | * | |
610 | * @param bool $isStarred | |
611 | * | |
612 | * @return Entry | |
613 | */ | |
614 | public function updateStar($isStarred = false) | |
615 | { | |
616 | $this->setStarred($isStarred); | |
617 | $this->setStarredAt(null); | |
618 | if ($this->isStarred()) { | |
619 | $this->setStarredAt(new \DateTime()); | |
620 | } | |
621 | ||
622 | return $this; | |
623 | } | |
624 | ||
34d15eb4 | 625 | /** |
4dc87223 | 626 | * @return ArrayCollection<Annotation> |
34d15eb4 | 627 | */ |
4dc87223 | 628 | public function getAnnotations() |
34d15eb4 | 629 | { |
4dc87223 | 630 | return $this->annotations; |
34d15eb4 NL |
631 | } |
632 | ||
633 | /** | |
4dc87223 | 634 | * @param Annotation $annotation |
34d15eb4 | 635 | */ |
4dc87223 | 636 | public function setAnnotation(Annotation $annotation) |
34d15eb4 | 637 | { |
4dc87223 | 638 | $this->annotations[] = $annotation; |
34d15eb4 NL |
639 | } |
640 | ||
641 | /** | |
642 | * @return string | |
643 | */ | |
644 | public function getMimetype() | |
645 | { | |
646 | return $this->mimetype; | |
647 | } | |
648 | ||
649 | /** | |
650 | * @param string $mimetype | |
651 | */ | |
652 | public function setMimetype($mimetype) | |
653 | { | |
654 | $this->mimetype = $mimetype; | |
655 | } | |
656 | ||
657 | /** | |
658 | * @return int | |
659 | */ | |
660 | public function getReadingTime() | |
661 | { | |
662 | return $this->readingTime; | |
663 | } | |
664 | ||
665 | /** | |
666 | * @param int $readingTime | |
667 | */ | |
668 | public function setReadingTime($readingTime) | |
669 | { | |
670 | $this->readingTime = $readingTime; | |
671 | } | |
672 | ||
673 | /** | |
674 | * @return string | |
675 | */ | |
676 | public function getDomainName() | |
677 | { | |
678 | return $this->domainName; | |
679 | } | |
680 | ||
681 | /** | |
682 | * @param string $domainName | |
683 | */ | |
684 | public function setDomainName($domainName) | |
685 | { | |
686 | $this->domainName = $domainName; | |
687 | } | |
688 | ||
0a018fe0 | 689 | /** |
4ec53ab7 | 690 | * @return ArrayCollection |
0a018fe0 NL |
691 | */ |
692 | public function getTags() | |
693 | { | |
694 | return $this->tags; | |
695 | } | |
696 | ||
b0458874 JB |
697 | /** |
698 | * @VirtualProperty | |
699 | * @SerializedName("tags") | |
700 | * @Groups({"entries_for_user", "export_all"}) | |
701 | */ | |
702 | public function getSerializedTags() | |
703 | { | |
704 | $data = []; | |
705 | foreach ($this->tags as $tag) { | |
706 | $data[] = $tag->getLabel(); | |
707 | } | |
708 | ||
709 | return $data; | |
710 | } | |
711 | ||
0a018fe0 NL |
712 | /** |
713 | * @param Tag $tag | |
714 | */ | |
715 | public function addTag(Tag $tag) | |
716 | { | |
625acf33 KG |
717 | if ($this->tags->contains($tag)) { |
718 | return; | |
719 | } | |
720 | ||
fc031e57 JB |
721 | // check if tag already exist but has not yet be persisted |
722 | // it seems that the previous condition with `contains()` doesn't check that case | |
723 | foreach ($this->tags as $existingTag) { | |
fc732227 | 724 | if ($existingTag->getLabel() === $tag->getLabel()) { |
fc031e57 JB |
725 | return; |
726 | } | |
727 | } | |
728 | ||
e42b13bc | 729 | $this->tags->add($tag); |
46bbd8d3 | 730 | $tag->addEntry($this); |
0a018fe0 | 731 | } |
092ca707 | 732 | |
a05b6115 JB |
733 | /** |
734 | * Remove the given tag from the entry (if the tag is associated). | |
735 | * | |
736 | * @param Tag $tag | |
737 | */ | |
092ca707 NL |
738 | public function removeTag(Tag $tag) |
739 | { | |
e42b13bc JB |
740 | if (!$this->tags->contains($tag)) { |
741 | return; | |
742 | } | |
743 | ||
092ca707 | 744 | $this->tags->removeElement($tag); |
e42b13bc | 745 | $tag->removeEntry($this); |
092ca707 | 746 | } |
fad31615 | 747 | |
a05b6115 JB |
748 | /** |
749 | * Remove all assigned tags from the entry. | |
750 | */ | |
751 | public function removeAllTags() | |
752 | { | |
753 | foreach ($this->tags as $tag) { | |
754 | $this->tags->removeElement($tag); | |
755 | $tag->removeEntry($this); | |
756 | } | |
757 | } | |
758 | ||
fad31615 | 759 | /** |
a1413a3d | 760 | * Set previewPicture. |
fad31615 JB |
761 | * |
762 | * @param string $previewPicture | |
763 | * | |
764 | * @return Entry | |
765 | */ | |
766 | public function setPreviewPicture($previewPicture) | |
767 | { | |
768 | $this->previewPicture = $previewPicture; | |
769 | ||
770 | return $this; | |
771 | } | |
772 | ||
773 | /** | |
a1413a3d | 774 | * Get previewPicture. |
fad31615 JB |
775 | * |
776 | * @return string | |
777 | */ | |
778 | public function getPreviewPicture() | |
779 | { | |
780 | return $this->previewPicture; | |
781 | } | |
98f0929f JB |
782 | |
783 | /** | |
784 | * Set language. | |
785 | * | |
786 | * @param string $language | |
787 | * | |
788 | * @return Entry | |
789 | */ | |
790 | public function setLanguage($language) | |
791 | { | |
792 | $this->language = $language; | |
793 | ||
794 | return $this; | |
795 | } | |
796 | ||
797 | /** | |
798 | * Get language. | |
799 | * | |
800 | * @return string | |
801 | */ | |
802 | public function getLanguage() | |
803 | { | |
804 | return $this->language; | |
805 | } | |
f3d0cb91 NL |
806 | |
807 | /** | |
78b3c31d | 808 | * @return string |
f3d0cb91 | 809 | */ |
7239082a | 810 | public function getUid() |
f3d0cb91 | 811 | { |
7239082a | 812 | return $this->uid; |
f3d0cb91 NL |
813 | } |
814 | ||
815 | /** | |
7239082a | 816 | * @param string $uid |
f3d0cb91 NL |
817 | * |
818 | * @return Entry | |
819 | */ | |
7239082a | 820 | public function setUid($uid) |
f3d0cb91 | 821 | { |
7239082a | 822 | $this->uid = $uid; |
f3d0cb91 NL |
823 | |
824 | return $this; | |
825 | } | |
826 | ||
7239082a | 827 | public function generateUid() |
f3d0cb91 | 828 | { |
7239082a | 829 | if (null === $this->uid) { |
a7e2218e | 830 | // @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter |
7239082a | 831 | $this->uid = uniqid('', true); |
f3d0cb91 NL |
832 | } |
833 | } | |
f1be7af4 | 834 | |
7239082a | 835 | public function cleanUid() |
f1be7af4 | 836 | { |
7239082a | 837 | $this->uid = null; |
f1be7af4 | 838 | } |
10b35097 | 839 | |
e8911f7c JB |
840 | /** |
841 | * Used in the entries filter so it's more explicit for the end user than the uid. | |
a9c6577f | 842 | * Also used in the API. |
e8911f7c | 843 | * |
1112e547 JB |
844 | * @VirtualProperty |
845 | * @SerializedName("is_public") | |
846 | * @Groups({"entries_for_user"}) | |
847 | * | |
e8911f7c JB |
848 | * @return bool |
849 | */ | |
850 | public function isPublic() | |
851 | { | |
852 | return null !== $this->uid; | |
853 | } | |
854 | ||
10b35097 | 855 | /** |
5fe65bae | 856 | * @return string |
10b35097 NL |
857 | */ |
858 | public function getHttpStatus() | |
859 | { | |
860 | return $this->httpStatus; | |
861 | } | |
862 | ||
863 | /** | |
5fe65bae | 864 | * @param string $httpStatus |
10b35097 NL |
865 | * |
866 | * @return Entry | |
867 | */ | |
868 | public function setHttpStatus($httpStatus) | |
869 | { | |
870 | $this->httpStatus = $httpStatus; | |
871 | ||
872 | return $this; | |
873 | } | |
5e9009ce NL |
874 | |
875 | /** | |
876 | * @return \Datetime | |
877 | */ | |
878 | public function getPublishedAt() | |
879 | { | |
880 | return $this->publishedAt; | |
881 | } | |
882 | ||
883 | /** | |
884 | * @param \Datetime $publishedAt | |
885 | * | |
886 | * @return Entry | |
887 | */ | |
888 | public function setPublishedAt(\Datetime $publishedAt) | |
889 | { | |
890 | $this->publishedAt = $publishedAt; | |
891 | ||
892 | return $this; | |
893 | } | |
7b0b3622 NL |
894 | |
895 | /** | |
dda6a6ad | 896 | * @return array |
7b0b3622 NL |
897 | */ |
898 | public function getPublishedBy() | |
899 | { | |
900 | return $this->publishedBy; | |
901 | } | |
902 | ||
903 | /** | |
1517d577 | 904 | * @param array $publishedBy |
7b0b3622 NL |
905 | * |
906 | * @return Entry | |
907 | */ | |
908 | public function setPublishedBy($publishedBy) | |
909 | { | |
910 | $this->publishedBy = $publishedBy; | |
911 | ||
912 | return $this; | |
913 | } | |
dda6a6ad NL |
914 | |
915 | /** | |
916 | * @return array | |
917 | */ | |
918 | public function getHeaders() | |
919 | { | |
920 | return $this->headers; | |
921 | } | |
922 | ||
923 | /** | |
1517d577 | 924 | * @param array $headers |
dda6a6ad NL |
925 | * |
926 | * @return Entry | |
927 | */ | |
928 | public function setHeaders($headers) | |
929 | { | |
930 | $this->headers = $headers; | |
931 | ||
932 | return $this; | |
933 | } | |
eae8138b | 934 | |
e0ef1a1c KD |
935 | /** |
936 | * Set origin url. | |
937 | * | |
938 | * @param string $originUrl | |
939 | * | |
940 | * @return Entry | |
941 | */ | |
942 | public function setOriginUrl($originUrl) | |
943 | { | |
944 | $this->originUrl = $originUrl; | |
945 | ||
946 | return $this; | |
947 | } | |
eae8138b | 948 | |
e0ef1a1c KD |
949 | /** |
950 | * Get origin url. | |
951 | * | |
952 | * @return string | |
953 | */ | |
954 | public function getOriginUrl() | |
955 | { | |
956 | return $this->originUrl; | |
957 | } | |
bfe02a0b TC |
958 | |
959 | /** | |
960 | * @return string | |
961 | */ | |
962 | public function getHashedUrl() | |
963 | { | |
964 | return $this->hashedUrl; | |
965 | } | |
966 | ||
967 | /** | |
968 | * @param mixed $hashedUrl | |
969 | * | |
970 | * @return Entry | |
971 | */ | |
972 | public function setHashedUrl($hashedUrl) | |
973 | { | |
974 | $this->hashedUrl = $hashedUrl; | |
975 | ||
976 | return $this; | |
977 | } | |
9d50517c | 978 | } |