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