]>
Commit | Line | Data |
---|---|---|
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 | use Wallabag\CoreBundle\Tools\Utils; | |
11 | ||
12 | /** | |
13 | * Entry. | |
14 | * | |
15 | * @XmlRoot("entry") | |
16 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") | |
17 | * @ORM\Table | |
18 | * @ORM\HasLifecycleCallbacks() | |
19 | * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") | |
20 | */ | |
21 | class Entry | |
22 | { | |
23 | /** @Serializer\XmlAttribute */ | |
24 | /** | |
25 | * @var int | |
26 | * | |
27 | * @ORM\Column(name="id", type="integer") | |
28 | * @ORM\Id | |
29 | * @ORM\GeneratedValue(strategy="AUTO") | |
30 | */ | |
31 | private $id; | |
32 | ||
33 | /** | |
34 | * @var string | |
35 | * | |
36 | * @ORM\Column(name="title", type="text", nullable=true) | |
37 | */ | |
38 | private $title; | |
39 | ||
40 | /** | |
41 | * @var string | |
42 | * | |
43 | * @Assert\NotBlank() | |
44 | * @ORM\Column(name="url", type="text", nullable=true) | |
45 | */ | |
46 | private $url; | |
47 | ||
48 | /** | |
49 | * @var bool | |
50 | * | |
51 | * @ORM\Column(name="is_archived", type="boolean") | |
52 | */ | |
53 | private $isArchived = false; | |
54 | ||
55 | /** | |
56 | * @var bool | |
57 | * | |
58 | * @ORM\Column(name="is_starred", type="boolean") | |
59 | */ | |
60 | private $isStarred = false; | |
61 | ||
62 | /** | |
63 | * @var string | |
64 | * | |
65 | * @ORM\Column(name="content", type="text", nullable=true) | |
66 | */ | |
67 | private $content; | |
68 | ||
69 | /** | |
70 | * @var date | |
71 | * | |
72 | * @ORM\Column(name="created_at", type="datetime") | |
73 | */ | |
74 | private $createdAt; | |
75 | ||
76 | /** | |
77 | * @var date | |
78 | * | |
79 | * @ORM\Column(name="updated_at", type="datetime") | |
80 | */ | |
81 | private $updatedAt; | |
82 | ||
83 | /** | |
84 | * @var string | |
85 | * | |
86 | * @ORM\Column(name="comments", type="text", nullable=true) | |
87 | */ | |
88 | private $comments; | |
89 | ||
90 | /** | |
91 | * @var string | |
92 | * | |
93 | * @ORM\Column(name="mimetype", type="text", nullable=true) | |
94 | */ | |
95 | private $mimetype; | |
96 | ||
97 | /** | |
98 | * @var string | |
99 | * | |
100 | * @ORM\Column(name="language", type="text", nullable=true) | |
101 | */ | |
102 | private $language; | |
103 | ||
104 | /** | |
105 | * @var int | |
106 | * | |
107 | * @ORM\Column(name="reading_time", type="integer", nullable=true) | |
108 | */ | |
109 | private $readingTime; | |
110 | ||
111 | /** | |
112 | * @var string | |
113 | * | |
114 | * @ORM\Column(name="domain_name", type="text", nullable=true) | |
115 | */ | |
116 | private $domainName; | |
117 | ||
118 | /** | |
119 | * @var string | |
120 | * | |
121 | * @ORM\Column(name="preview_picture", type="text", nullable=true) | |
122 | */ | |
123 | private $previewPicture; | |
124 | ||
125 | /** | |
126 | * @var bool | |
127 | * | |
128 | * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false}) | |
129 | */ | |
130 | private $isPublic; | |
131 | ||
132 | /** | |
133 | * @ORM\ManyToOne(targetEntity="User", inversedBy="entries") | |
134 | */ | |
135 | private $user; | |
136 | ||
137 | /** | |
138 | * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) | |
139 | * @ORM\JoinTable | |
140 | */ | |
141 | private $tags; | |
142 | ||
143 | /* | |
144 | * @param User $user | |
145 | */ | |
146 | public function __construct(User $user) | |
147 | { | |
148 | $this->user = $user; | |
149 | $this->tags = new ArrayCollection(); | |
150 | } | |
151 | ||
152 | /** | |
153 | * Get id. | |
154 | * | |
155 | * @return int | |
156 | */ | |
157 | public function getId() | |
158 | { | |
159 | return $this->id; | |
160 | } | |
161 | ||
162 | /** | |
163 | * Set title. | |
164 | * | |
165 | * @param string $title | |
166 | * | |
167 | * @return Entry | |
168 | */ | |
169 | public function setTitle($title) | |
170 | { | |
171 | $this->title = $title; | |
172 | ||
173 | return $this; | |
174 | } | |
175 | ||
176 | /** | |
177 | * Get title. | |
178 | * | |
179 | * @return string | |
180 | */ | |
181 | public function getTitle() | |
182 | { | |
183 | return $this->title; | |
184 | } | |
185 | ||
186 | /** | |
187 | * Set url. | |
188 | * | |
189 | * @param string $url | |
190 | * | |
191 | * @return Entry | |
192 | */ | |
193 | public function setUrl($url) | |
194 | { | |
195 | $this->url = $url; | |
196 | ||
197 | return $this; | |
198 | } | |
199 | ||
200 | /** | |
201 | * Get url. | |
202 | * | |
203 | * @return string | |
204 | */ | |
205 | public function getUrl() | |
206 | { | |
207 | return $this->url; | |
208 | } | |
209 | ||
210 | /** | |
211 | * Set isArchived. | |
212 | * | |
213 | * @param string $isArchived | |
214 | * | |
215 | * @return Entry | |
216 | */ | |
217 | public function setArchived($isArchived) | |
218 | { | |
219 | $this->isArchived = $isArchived; | |
220 | ||
221 | return $this; | |
222 | } | |
223 | ||
224 | /** | |
225 | * Get isArchived. | |
226 | * | |
227 | * @return string | |
228 | */ | |
229 | public function isArchived() | |
230 | { | |
231 | return $this->isArchived; | |
232 | } | |
233 | ||
234 | public function toggleArchive() | |
235 | { | |
236 | $this->isArchived = $this->isArchived() ^ 1; | |
237 | ||
238 | return $this; | |
239 | } | |
240 | ||
241 | /** | |
242 | * Set isStarred. | |
243 | * | |
244 | * @param string $isStarred | |
245 | * | |
246 | * @return Entry | |
247 | */ | |
248 | public function setStarred($isStarred) | |
249 | { | |
250 | $this->isStarred = $isStarred; | |
251 | ||
252 | return $this; | |
253 | } | |
254 | ||
255 | /** | |
256 | * Get isStarred. | |
257 | * | |
258 | * @return string | |
259 | */ | |
260 | public function isStarred() | |
261 | { | |
262 | return $this->isStarred; | |
263 | } | |
264 | ||
265 | public function toggleStar() | |
266 | { | |
267 | $this->isStarred = $this->isStarred() ^ 1; | |
268 | ||
269 | return $this; | |
270 | } | |
271 | ||
272 | /** | |
273 | * Set content. | |
274 | * | |
275 | * @param string $content | |
276 | * | |
277 | * @return Entry | |
278 | */ | |
279 | public function setContent($content) | |
280 | { | |
281 | $this->content = $content; | |
282 | $this->readingTime = Utils::getReadingTime($content); | |
283 | $this->domainName = parse_url($this->url, PHP_URL_HOST); | |
284 | ||
285 | return $this; | |
286 | } | |
287 | ||
288 | /** | |
289 | * Get content. | |
290 | * | |
291 | * @return string | |
292 | */ | |
293 | public function getContent() | |
294 | { | |
295 | return $this->content; | |
296 | } | |
297 | ||
298 | /** | |
299 | * @return User | |
300 | */ | |
301 | public function getUser() | |
302 | { | |
303 | return $this->user; | |
304 | } | |
305 | ||
306 | /** | |
307 | * @return string | |
308 | */ | |
309 | public function getCreatedAt() | |
310 | { | |
311 | return $this->createdAt; | |
312 | } | |
313 | ||
314 | /** | |
315 | * @return string | |
316 | */ | |
317 | public function getUpdatedAt() | |
318 | { | |
319 | return $this->updatedAt; | |
320 | } | |
321 | ||
322 | /** | |
323 | * @ORM\PrePersist | |
324 | * @ORM\PreUpdate | |
325 | */ | |
326 | public function timestamps() | |
327 | { | |
328 | if (is_null($this->createdAt)) { | |
329 | $this->createdAt = new \DateTime(); | |
330 | } | |
331 | ||
332 | $this->updatedAt = new \DateTime(); | |
333 | } | |
334 | ||
335 | /** | |
336 | * @return string | |
337 | */ | |
338 | public function getComments() | |
339 | { | |
340 | return $this->comments; | |
341 | } | |
342 | ||
343 | /** | |
344 | * @param string $comments | |
345 | */ | |
346 | public function setComments($comments) | |
347 | { | |
348 | $this->comments = $comments; | |
349 | } | |
350 | ||
351 | /** | |
352 | * @return string | |
353 | */ | |
354 | public function getMimetype() | |
355 | { | |
356 | return $this->mimetype; | |
357 | } | |
358 | ||
359 | /** | |
360 | * @param string $mimetype | |
361 | */ | |
362 | public function setMimetype($mimetype) | |
363 | { | |
364 | $this->mimetype = $mimetype; | |
365 | } | |
366 | ||
367 | /** | |
368 | * @return int | |
369 | */ | |
370 | public function getReadingTime() | |
371 | { | |
372 | return $this->readingTime; | |
373 | } | |
374 | ||
375 | /** | |
376 | * @param int $readingTime | |
377 | */ | |
378 | public function setReadingTime($readingTime) | |
379 | { | |
380 | $this->readingTime = $readingTime; | |
381 | } | |
382 | ||
383 | /** | |
384 | * @return string | |
385 | */ | |
386 | public function getDomainName() | |
387 | { | |
388 | return $this->domainName; | |
389 | } | |
390 | ||
391 | /** | |
392 | * @param string $domainName | |
393 | */ | |
394 | public function setDomainName($domainName) | |
395 | { | |
396 | $this->domainName = $domainName; | |
397 | } | |
398 | ||
399 | /** | |
400 | * @return bool | |
401 | */ | |
402 | public function isPublic() | |
403 | { | |
404 | return $this->isPublic; | |
405 | } | |
406 | ||
407 | /** | |
408 | * @param bool $isPublic | |
409 | */ | |
410 | public function setIsPublic($isPublic) | |
411 | { | |
412 | $this->isPublic = $isPublic; | |
413 | } | |
414 | ||
415 | /** | |
416 | * @return ArrayCollection<Tag> | |
417 | */ | |
418 | public function getTags() | |
419 | { | |
420 | return $this->tags; | |
421 | } | |
422 | ||
423 | /** | |
424 | * @param Tag $tag | |
425 | */ | |
426 | public function addTag(Tag $tag) | |
427 | { | |
428 | $this->tags[] = $tag; | |
429 | $tag->addEntry($this); | |
430 | } | |
431 | ||
432 | public function removeTag(Tag $tag) | |
433 | { | |
434 | $this->tags->removeElement($tag); | |
435 | } | |
436 | ||
437 | /** | |
438 | * Set previewPicture. | |
439 | * | |
440 | * @param string $previewPicture | |
441 | * | |
442 | * @return Entry | |
443 | */ | |
444 | public function setPreviewPicture($previewPicture) | |
445 | { | |
446 | $this->previewPicture = $previewPicture; | |
447 | ||
448 | return $this; | |
449 | } | |
450 | ||
451 | /** | |
452 | * Get previewPicture. | |
453 | * | |
454 | * @return string | |
455 | */ | |
456 | public function getPreviewPicture() | |
457 | { | |
458 | return $this->previewPicture; | |
459 | } | |
460 | ||
461 | /** | |
462 | * Set language. | |
463 | * | |
464 | * @param string $language | |
465 | * | |
466 | * @return Entry | |
467 | */ | |
468 | public function setLanguage($language) | |
469 | { | |
470 | $this->language = $language; | |
471 | ||
472 | return $this; | |
473 | } | |
474 | ||
475 | /** | |
476 | * Get language. | |
477 | * | |
478 | * @return string | |
479 | */ | |
480 | public function getLanguage() | |
481 | { | |
482 | return $this->language; | |
483 | } | |
484 | } |