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