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