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