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