]>
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 int | |
99 | * | |
100 | * @ORM\Column(name="reading_time", type="integer", nullable=true) | |
101 | */ | |
102 | private $readingTime; | |
103 | ||
104 | /** | |
105 | * @var string | |
106 | * | |
107 | * @ORM\Column(name="domain_name", type="text", nullable=true) | |
108 | */ | |
109 | private $domainName; | |
110 | ||
111 | /** | |
112 | * @var string | |
113 | * | |
114 | * @ORM\Column(name="preview_picture", type="text", nullable=true) | |
115 | */ | |
116 | private $previewPicture; | |
117 | ||
118 | /** | |
119 | * @var bool | |
120 | * | |
121 | * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false}) | |
122 | */ | |
123 | private $isPublic; | |
124 | ||
125 | /** | |
126 | * @ORM\ManyToOne(targetEntity="User", inversedBy="entries") | |
127 | */ | |
128 | private $user; | |
129 | ||
130 | /** | |
131 | * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) | |
132 | * @ORM\JoinTable | |
133 | */ | |
134 | private $tags; | |
135 | ||
136 | /* | |
137 | * @param User $user | |
138 | */ | |
139 | public function __construct(User $user) | |
140 | { | |
141 | $this->user = $user; | |
142 | $this->tags = new ArrayCollection(); | |
143 | } | |
144 | ||
145 | /** | |
146 | * Get id. | |
147 | * | |
148 | * @return int | |
149 | */ | |
150 | public function getId() | |
151 | { | |
152 | return $this->id; | |
153 | } | |
154 | ||
155 | /** | |
156 | * Set title. | |
157 | * | |
158 | * @param string $title | |
159 | * | |
160 | * @return Entry | |
161 | */ | |
162 | public function setTitle($title) | |
163 | { | |
164 | $this->title = $title; | |
165 | ||
166 | return $this; | |
167 | } | |
168 | ||
169 | /** | |
170 | * Get title. | |
171 | * | |
172 | * @return string | |
173 | */ | |
174 | public function getTitle() | |
175 | { | |
176 | return $this->title; | |
177 | } | |
178 | ||
179 | /** | |
180 | * Set url. | |
181 | * | |
182 | * @param string $url | |
183 | * | |
184 | * @return Entry | |
185 | */ | |
186 | public function setUrl($url) | |
187 | { | |
188 | $this->url = $url; | |
189 | ||
190 | return $this; | |
191 | } | |
192 | ||
193 | /** | |
194 | * Get url. | |
195 | * | |
196 | * @return string | |
197 | */ | |
198 | public function getUrl() | |
199 | { | |
200 | return $this->url; | |
201 | } | |
202 | ||
203 | /** | |
204 | * Set isArchived. | |
205 | * | |
206 | * @param string $isArchived | |
207 | * | |
208 | * @return Entry | |
209 | */ | |
210 | public function setArchived($isArchived) | |
211 | { | |
212 | $this->isArchived = $isArchived; | |
213 | ||
214 | return $this; | |
215 | } | |
216 | ||
217 | /** | |
218 | * Get isArchived. | |
219 | * | |
220 | * @return string | |
221 | */ | |
222 | public function isArchived() | |
223 | { | |
224 | return $this->isArchived; | |
225 | } | |
226 | ||
227 | public function toggleArchive() | |
228 | { | |
229 | $this->isArchived = $this->isArchived() ^ 1; | |
230 | ||
231 | return $this; | |
232 | } | |
233 | ||
234 | /** | |
235 | * Set isStarred. | |
236 | * | |
237 | * @param string $isStarred | |
238 | * | |
239 | * @return Entry | |
240 | */ | |
241 | public function setStarred($isStarred) | |
242 | { | |
243 | $this->isStarred = $isStarred; | |
244 | ||
245 | return $this; | |
246 | } | |
247 | ||
248 | /** | |
249 | * Get isStarred. | |
250 | * | |
251 | * @return string | |
252 | */ | |
253 | public function isStarred() | |
254 | { | |
255 | return $this->isStarred; | |
256 | } | |
257 | ||
258 | public function toggleStar() | |
259 | { | |
260 | $this->isStarred = $this->isStarred() ^ 1; | |
261 | ||
262 | return $this; | |
263 | } | |
264 | ||
265 | /** | |
266 | * Set content. | |
267 | * | |
268 | * @param string $content | |
269 | * | |
270 | * @return Entry | |
271 | */ | |
272 | public function setContent($content) | |
273 | { | |
274 | $this->content = $content; | |
275 | $this->readingTime = Utils::getReadingTime($content); | |
276 | $this->domainName = parse_url($this->url, PHP_URL_HOST); | |
277 | ||
278 | return $this; | |
279 | } | |
280 | ||
281 | /** | |
282 | * Get content. | |
283 | * | |
284 | * @return string | |
285 | */ | |
286 | public function getContent() | |
287 | { | |
288 | return $this->content; | |
289 | } | |
290 | ||
291 | /** | |
292 | * @return User | |
293 | */ | |
294 | public function getUser() | |
295 | { | |
296 | return $this->user; | |
297 | } | |
298 | ||
299 | /** | |
300 | * @return string | |
301 | */ | |
302 | public function getCreatedAt() | |
303 | { | |
304 | return $this->createdAt; | |
305 | } | |
306 | ||
307 | /** | |
308 | * @return string | |
309 | */ | |
310 | public function getUpdatedAt() | |
311 | { | |
312 | return $this->updatedAt; | |
313 | } | |
314 | ||
315 | /** | |
316 | * @ORM\PrePersist | |
317 | * @ORM\PreUpdate | |
318 | */ | |
319 | public function timestamps() | |
320 | { | |
321 | if (is_null($this->createdAt)) { | |
322 | $this->createdAt = new \DateTime(); | |
323 | } | |
324 | ||
325 | $this->updatedAt = new \DateTime(); | |
326 | } | |
327 | ||
328 | /** | |
329 | * @return string | |
330 | */ | |
331 | public function getComments() | |
332 | { | |
333 | return $this->comments; | |
334 | } | |
335 | ||
336 | /** | |
337 | * @param string $comments | |
338 | */ | |
339 | public function setComments($comments) | |
340 | { | |
341 | $this->comments = $comments; | |
342 | } | |
343 | ||
344 | /** | |
345 | * @return string | |
346 | */ | |
347 | public function getMimetype() | |
348 | { | |
349 | return $this->mimetype; | |
350 | } | |
351 | ||
352 | /** | |
353 | * @param string $mimetype | |
354 | */ | |
355 | public function setMimetype($mimetype) | |
356 | { | |
357 | $this->mimetype = $mimetype; | |
358 | } | |
359 | ||
360 | /** | |
361 | * @return int | |
362 | */ | |
363 | public function getReadingTime() | |
364 | { | |
365 | return $this->readingTime; | |
366 | } | |
367 | ||
368 | /** | |
369 | * @param int $readingTime | |
370 | */ | |
371 | public function setReadingTime($readingTime) | |
372 | { | |
373 | $this->readingTime = $readingTime; | |
374 | } | |
375 | ||
376 | /** | |
377 | * @return string | |
378 | */ | |
379 | public function getDomainName() | |
380 | { | |
381 | return $this->domainName; | |
382 | } | |
383 | ||
384 | /** | |
385 | * @param string $domainName | |
386 | */ | |
387 | public function setDomainName($domainName) | |
388 | { | |
389 | $this->domainName = $domainName; | |
390 | } | |
391 | ||
392 | /** | |
393 | * @return bool | |
394 | */ | |
395 | public function isPublic() | |
396 | { | |
397 | return $this->isPublic; | |
398 | } | |
399 | ||
400 | /** | |
401 | * @param bool $isPublic | |
402 | */ | |
403 | public function setIsPublic($isPublic) | |
404 | { | |
405 | $this->isPublic = $isPublic; | |
406 | } | |
407 | ||
408 | /** | |
409 | * @return ArrayCollection<Tag> | |
410 | */ | |
411 | public function getTags() | |
412 | { | |
413 | return $this->tags; | |
414 | } | |
415 | ||
416 | /** | |
417 | * @param Tag $tag | |
418 | */ | |
419 | public function addTag(Tag $tag) | |
420 | { | |
421 | $this->tags[] = $tag; | |
422 | $tag->addEntry($this); | |
423 | } | |
424 | ||
425 | public function removeTag(Tag $tag) | |
426 | { | |
427 | $this->tags->removeElement($tag); | |
428 | } | |
429 | ||
430 | /** | |
431 | * Set previewPicture. | |
432 | * | |
433 | * @param string $previewPicture | |
434 | * | |
435 | * @return Entry | |
436 | */ | |
437 | public function setPreviewPicture($previewPicture) | |
438 | { | |
439 | $this->previewPicture = $previewPicture; | |
440 | ||
441 | return $this; | |
442 | } | |
443 | ||
444 | /** | |
445 | * Get previewPicture. | |
446 | * | |
447 | * @return string | |
448 | */ | |
449 | public function getPreviewPicture() | |
450 | { | |
451 | return $this->previewPicture; | |
452 | } | |
453 | } |