]>
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; |
b84a8055 | 7 | use Symfony\Component\Validator\Constraints as Assert; |
0f006880 NL |
8 | use Hateoas\Configuration\Annotation as Hateoas; |
9 | use JMS\Serializer\Annotation\XmlRoot; | |
26864574 | 10 | use Wallabag\CoreBundle\Helper\Tools; |
9d50517c NL |
11 | |
12 | /** | |
4346a860 | 13 | * Entry. |
9d50517c | 14 | * |
0f006880 | 15 | * @XmlRoot("entry") |
be463487 | 16 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") |
164bd801 | 17 | * @ORM\Table |
34d15eb4 | 18 | * @ORM\HasLifecycleCallbacks() |
0f006880 | 19 | * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") |
9d50517c | 20 | */ |
be463487 | 21 | class Entry |
9d50517c | 22 | { |
0f006880 | 23 | /** @Serializer\XmlAttribute */ |
9d50517c | 24 | /** |
4346a860 | 25 | * @var int |
9d50517c | 26 | * |
be463487 | 27 | * @ORM\Column(name="id", type="integer") |
9d50517c | 28 | * @ORM\Id |
34d15eb4 | 29 | * @ORM\GeneratedValue(strategy="AUTO") |
9d50517c | 30 | */ |
be463487 | 31 | private $id; |
9d50517c NL |
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 | * | |
b84a8055 | 43 | * @Assert\NotBlank() |
9d50517c NL |
44 | * @ORM\Column(name="url", type="text", nullable=true) |
45 | */ | |
46 | private $url; | |
47 | ||
48 | /** | |
4346a860 | 49 | * @var bool |
9d50517c | 50 | * |
be463487 | 51 | * @ORM\Column(name="is_archived", type="boolean") |
9d50517c | 52 | */ |
905ae369 | 53 | private $isArchived = false; |
9d50517c NL |
54 | |
55 | /** | |
4346a860 | 56 | * @var bool |
9d50517c | 57 | * |
be463487 | 58 | * @ORM\Column(name="is_starred", type="boolean") |
9d50517c | 59 | */ |
905ae369 | 60 | private $isStarred = false; |
9d50517c | 61 | |
9d50517c NL |
62 | /** |
63 | * @var string | |
64 | * | |
eacaf7f8 | 65 | * @ORM\Column(name="content", type="text", nullable=true) |
9d50517c | 66 | */ |
eacaf7f8 | 67 | private $content; |
9d50517c | 68 | |
34d15eb4 NL |
69 | /** |
70 | * @var date | |
71 | * | |
be463487 | 72 | * @ORM\Column(name="created_at", type="datetime") |
34d15eb4 NL |
73 | */ |
74 | private $createdAt; | |
75 | ||
76 | /** | |
77 | * @var date | |
78 | * | |
be463487 | 79 | * @ORM\Column(name="updated_at", type="datetime") |
34d15eb4 NL |
80 | */ |
81 | private $updatedAt; | |
82 | ||
34d15eb4 NL |
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 | /** | |
4346a860 | 98 | * @var int |
34d15eb4 | 99 | * |
26864574 | 100 | * @ORM\Column(name="reading_time", type="integer", nullable=true) |
34d15eb4 NL |
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 | /** | |
4346a860 | 112 | * @var bool |
34d15eb4 NL |
113 | * |
114 | * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false}) | |
115 | */ | |
116 | private $isPublic; | |
117 | ||
5f09650e NL |
118 | /** |
119 | * @ORM\ManyToOne(targetEntity="User", inversedBy="entries") | |
120 | */ | |
121 | private $user; | |
122 | ||
0a018fe0 | 123 | /** |
46bbd8d3 | 124 | * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) |
164bd801 | 125 | * @ORM\JoinTable |
0a018fe0 NL |
126 | */ |
127 | private $tags; | |
128 | ||
5f09650e NL |
129 | /* |
130 | * @param User $user | |
131 | */ | |
132 | public function __construct(User $user) | |
133 | { | |
134 | $this->user = $user; | |
0a018fe0 | 135 | $this->tags = new ArrayCollection(); |
5f09650e NL |
136 | } |
137 | ||
9d50517c | 138 | /** |
4346a860 | 139 | * Get id. |
9d50517c | 140 | * |
4346a860 | 141 | * @return int |
9d50517c NL |
142 | */ |
143 | public function getId() | |
144 | { | |
145 | return $this->id; | |
146 | } | |
147 | ||
148 | /** | |
4346a860 JB |
149 | * Set title. |
150 | * | |
151 | * @param string $title | |
9d50517c | 152 | * |
be463487 | 153 | * @return Entry |
9d50517c NL |
154 | */ |
155 | public function setTitle($title) | |
156 | { | |
157 | $this->title = $title; | |
158 | ||
159 | return $this; | |
160 | } | |
161 | ||
162 | /** | |
4346a860 | 163 | * Get title. |
9d50517c | 164 | * |
7df80cb3 | 165 | * @return string |
9d50517c NL |
166 | */ |
167 | public function getTitle() | |
168 | { | |
169 | return $this->title; | |
170 | } | |
171 | ||
172 | /** | |
4346a860 JB |
173 | * Set url. |
174 | * | |
175 | * @param string $url | |
9d50517c | 176 | * |
be463487 | 177 | * @return Entry |
9d50517c NL |
178 | */ |
179 | public function setUrl($url) | |
180 | { | |
181 | $this->url = $url; | |
182 | ||
183 | return $this; | |
184 | } | |
185 | ||
186 | /** | |
4346a860 | 187 | * Get url. |
9d50517c | 188 | * |
7df80cb3 | 189 | * @return string |
9d50517c NL |
190 | */ |
191 | public function getUrl() | |
192 | { | |
193 | return $this->url; | |
194 | } | |
195 | ||
196 | /** | |
4346a860 JB |
197 | * Set isArchived. |
198 | * | |
199 | * @param string $isArchived | |
9d50517c | 200 | * |
be463487 | 201 | * @return Entry |
9d50517c | 202 | */ |
905ae369 | 203 | public function setArchived($isArchived) |
9d50517c | 204 | { |
905ae369 | 205 | $this->isArchived = $isArchived; |
9d50517c NL |
206 | |
207 | return $this; | |
208 | } | |
209 | ||
210 | /** | |
4346a860 | 211 | * Get isArchived. |
9d50517c | 212 | * |
7df80cb3 | 213 | * @return string |
9d50517c | 214 | */ |
905ae369 | 215 | public function isArchived() |
9d50517c | 216 | { |
905ae369 | 217 | return $this->isArchived; |
9d50517c NL |
218 | } |
219 | ||
163eae0b NL |
220 | public function toggleArchive() |
221 | { | |
905ae369 | 222 | $this->isArchived = $this->isArchived() ^ 1; |
7df80cb3 | 223 | |
163eae0b NL |
224 | return $this; |
225 | } | |
226 | ||
9d50517c | 227 | /** |
4346a860 JB |
228 | * Set isStarred. |
229 | * | |
230 | * @param string $isStarred | |
9d50517c | 231 | * |
be463487 | 232 | * @return Entry |
9d50517c | 233 | */ |
905ae369 | 234 | public function setStarred($isStarred) |
9d50517c | 235 | { |
905ae369 | 236 | $this->isStarred = $isStarred; |
9d50517c NL |
237 | |
238 | return $this; | |
239 | } | |
240 | ||
241 | /** | |
4346a860 | 242 | * Get isStarred. |
9d50517c | 243 | * |
7df80cb3 | 244 | * @return string |
9d50517c | 245 | */ |
905ae369 | 246 | public function isStarred() |
9d50517c | 247 | { |
905ae369 | 248 | return $this->isStarred; |
9d50517c NL |
249 | } |
250 | ||
163eae0b NL |
251 | public function toggleStar() |
252 | { | |
905ae369 | 253 | $this->isStarred = $this->isStarred() ^ 1; |
163eae0b NL |
254 | |
255 | return $this; | |
256 | } | |
257 | ||
9d50517c | 258 | /** |
4346a860 JB |
259 | * Set content. |
260 | * | |
261 | * @param string $content | |
9d50517c | 262 | * |
be463487 | 263 | * @return Entry |
9d50517c NL |
264 | */ |
265 | public function setContent($content) | |
266 | { | |
267 | $this->content = $content; | |
26864574 | 268 | $this->readingTime = Tools::getReadingTime($content); |
9d50517c NL |
269 | |
270 | return $this; | |
271 | } | |
272 | ||
273 | /** | |
4346a860 | 274 | * Get content. |
9d50517c | 275 | * |
7df80cb3 | 276 | * @return string |
9d50517c NL |
277 | */ |
278 | public function getContent() | |
279 | { | |
280 | return $this->content; | |
281 | } | |
282 | ||
283 | /** | |
5f09650e | 284 | * @return User |
9d50517c | 285 | */ |
5f09650e | 286 | public function getUser() |
9d50517c | 287 | { |
5f09650e | 288 | return $this->user; |
9d50517c | 289 | } |
42a90646 | 290 | |
34d15eb4 | 291 | /** |
2f69eb4a | 292 | * @return string |
34d15eb4 NL |
293 | */ |
294 | public function getCreatedAt() | |
295 | { | |
296 | return $this->createdAt; | |
297 | } | |
298 | ||
34d15eb4 NL |
299 | /** |
300 | * @return string | |
301 | */ | |
302 | public function getUpdatedAt() | |
303 | { | |
304 | return $this->updatedAt; | |
305 | } | |
306 | ||
307 | /** | |
be463487 | 308 | * @ORM\PrePersist |
34d15eb4 NL |
309 | * @ORM\PreUpdate |
310 | */ | |
be463487 | 311 | public function timestamps() |
34d15eb4 | 312 | { |
be463487 NL |
313 | if (is_null($this->createdAt)) { |
314 | $this->createdAt = new \DateTime(); | |
315 | } | |
316 | ||
34d15eb4 NL |
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 | /** | |
4346a860 | 385 | * @return bool |
34d15eb4 | 386 | */ |
2c093b03 | 387 | public function isPublic() |
34d15eb4 NL |
388 | { |
389 | return $this->isPublic; | |
390 | } | |
391 | ||
392 | /** | |
4346a860 | 393 | * @param bool $isPublic |
34d15eb4 | 394 | */ |
82d6d9cb | 395 | public function setIsPublic($isPublic) |
34d15eb4 NL |
396 | { |
397 | $this->isPublic = $isPublic; | |
398 | } | |
0a018fe0 NL |
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; | |
46bbd8d3 | 414 | $tag->addEntry($this); |
0a018fe0 | 415 | } |
092ca707 NL |
416 | |
417 | public function removeTag(Tag $tag) | |
418 | { | |
419 | $this->tags->removeElement($tag); | |
420 | } | |
9d50517c | 421 | } |