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