]>
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(name="entry") | |
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", "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 | ||
131 | /* | |
132 | * @param User $user | |
133 | */ | |
134 | public function __construct(User $user) | |
135 | { | |
136 | $this->user = $user; | |
137 | $this->tags = new ArrayCollection(); | |
138 | } | |
139 | ||
140 | /** | |
141 | * Get id | |
142 | * | |
143 | * @return integer | |
144 | */ | |
145 | public function getId() | |
146 | { | |
147 | return $this->id; | |
148 | } | |
149 | ||
150 | /** | |
151 | * Set title | |
152 | * | |
153 | * @param string $title | |
154 | * @return Entry | |
155 | */ | |
156 | public function setTitle($title) | |
157 | { | |
158 | $this->title = $title; | |
159 | ||
160 | return $this; | |
161 | } | |
162 | ||
163 | /** | |
164 | * Get title | |
165 | * | |
166 | * @return string | |
167 | */ | |
168 | public function getTitle() | |
169 | { | |
170 | return $this->title; | |
171 | } | |
172 | ||
173 | /** | |
174 | * Set url | |
175 | * | |
176 | * @param string $url | |
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 | * @return Entry | |
201 | */ | |
202 | public function setArchived($isArchived) | |
203 | { | |
204 | $this->isArchived = $isArchived; | |
205 | ||
206 | return $this; | |
207 | } | |
208 | ||
209 | /** | |
210 | * Get isArchived | |
211 | * | |
212 | * @return string | |
213 | */ | |
214 | public function isArchived() | |
215 | { | |
216 | return $this->isArchived; | |
217 | } | |
218 | ||
219 | public function toggleArchive() | |
220 | { | |
221 | $this->isArchived = $this->isArchived() ^ 1; | |
222 | ||
223 | return $this; | |
224 | } | |
225 | ||
226 | /** | |
227 | * Set isStarred | |
228 | * | |
229 | * @param string $isStarred | |
230 | * @return Entry | |
231 | */ | |
232 | public function setStarred($isStarred) | |
233 | { | |
234 | $this->isStarred = $isStarred; | |
235 | ||
236 | return $this; | |
237 | } | |
238 | ||
239 | /** | |
240 | * Get isStarred | |
241 | * | |
242 | * @return string | |
243 | */ | |
244 | public function isStarred() | |
245 | { | |
246 | return $this->isStarred; | |
247 | } | |
248 | ||
249 | public function toggleStar() | |
250 | { | |
251 | $this->isStarred = $this->isStarred() ^ 1; | |
252 | ||
253 | return $this; | |
254 | } | |
255 | ||
256 | /** | |
257 | * Set content | |
258 | * | |
259 | * @param string $content | |
260 | * @return Entry | |
261 | */ | |
262 | public function setContent($content) | |
263 | { | |
264 | $this->content = $content; | |
265 | ||
266 | return $this; | |
267 | } | |
268 | ||
269 | /** | |
270 | * Get content | |
271 | * | |
272 | * @return string | |
273 | */ | |
274 | public function getContent() | |
275 | { | |
276 | return $this->content; | |
277 | } | |
278 | ||
279 | /** | |
280 | * @return User | |
281 | */ | |
282 | public function getUser() | |
283 | { | |
284 | return $this->user; | |
285 | } | |
286 | ||
287 | /** | |
288 | * @return string | |
289 | */ | |
290 | public function getCreatedAt() | |
291 | { | |
292 | return $this->createdAt; | |
293 | } | |
294 | ||
295 | /** | |
296 | * @return string | |
297 | */ | |
298 | public function getUpdatedAt() | |
299 | { | |
300 | return $this->updatedAt; | |
301 | } | |
302 | ||
303 | /** | |
304 | * @ORM\PrePersist | |
305 | * @ORM\PreUpdate | |
306 | */ | |
307 | public function timestamps() | |
308 | { | |
309 | if (is_null($this->createdAt)) { | |
310 | $this->createdAt = new \DateTime(); | |
311 | } | |
312 | ||
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 | */ | |
383 | public function isPublic() | |
384 | { | |
385 | return $this->isPublic; | |
386 | } | |
387 | ||
388 | /** | |
389 | * @param boolean $isPublic | |
390 | */ | |
391 | public function setPublic($isPublic) | |
392 | { | |
393 | $this->isPublic = $isPublic; | |
394 | } | |
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 | } | |
411 | } |