]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Entity/Entry.php
Merge pull request #1167 from wallabag/v2-api-bundle
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Entity / Entry.php
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 int
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 bool
49 *
50 * @ORM\Column(name="is_archived", type="boolean")
51 */
52 private $isArchived = false;
53
54 /**
55 * @var bool
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 int
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 bool
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 int
141 */
142 public function getId()
143 {
144 return $this->id;
145 }
146
147 /**
148 * Set title.
149 *
150 * @param string $title
151 *
152 * @return Entry
153 */
154 public function setTitle($title)
155 {
156 $this->title = $title;
157
158 return $this;
159 }
160
161 /**
162 * Get title.
163 *
164 * @return string
165 */
166 public function getTitle()
167 {
168 return $this->title;
169 }
170
171 /**
172 * Set url.
173 *
174 * @param string $url
175 *
176 * @return Entry
177 */
178 public function setUrl($url)
179 {
180 $this->url = $url;
181
182 return $this;
183 }
184
185 /**
186 * Get url.
187 *
188 * @return string
189 */
190 public function getUrl()
191 {
192 return $this->url;
193 }
194
195 /**
196 * Set isArchived.
197 *
198 * @param string $isArchived
199 *
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 *
231 * @return Entry
232 */
233 public function setStarred($isStarred)
234 {
235 $this->isStarred = $isStarred;
236
237 return $this;
238 }
239
240 /**
241 * Get isStarred.
242 *
243 * @return string
244 */
245 public function isStarred()
246 {
247 return $this->isStarred;
248 }
249
250 public function toggleStar()
251 {
252 $this->isStarred = $this->isStarred() ^ 1;
253
254 return $this;
255 }
256
257 /**
258 * Set content.
259 *
260 * @param string $content
261 *
262 * @return Entry
263 */
264 public function setContent($content)
265 {
266 $this->content = $content;
267
268 return $this;
269 }
270
271 /**
272 * Get content.
273 *
274 * @return string
275 */
276 public function getContent()
277 {
278 return $this->content;
279 }
280
281 /**
282 * @return User
283 */
284 public function getUser()
285 {
286 return $this->user;
287 }
288
289 /**
290 * @return string
291 */
292 public function getCreatedAt()
293 {
294 return $this->createdAt;
295 }
296
297 /**
298 * @return string
299 */
300 public function getUpdatedAt()
301 {
302 return $this->updatedAt;
303 }
304
305 /**
306 * @ORM\PrePersist
307 * @ORM\PreUpdate
308 */
309 public function timestamps()
310 {
311 if (is_null($this->createdAt)) {
312 $this->createdAt = new \DateTime();
313 }
314
315 $this->updatedAt = new \DateTime();
316 }
317
318 /**
319 * @return string
320 */
321 public function getComments()
322 {
323 return $this->comments;
324 }
325
326 /**
327 * @param string $comments
328 */
329 public function setComments($comments)
330 {
331 $this->comments = $comments;
332 }
333
334 /**
335 * @return string
336 */
337 public function getMimetype()
338 {
339 return $this->mimetype;
340 }
341
342 /**
343 * @param string $mimetype
344 */
345 public function setMimetype($mimetype)
346 {
347 $this->mimetype = $mimetype;
348 }
349
350 /**
351 * @return int
352 */
353 public function getReadingTime()
354 {
355 return $this->readingTime;
356 }
357
358 /**
359 * @param int $readingTime
360 */
361 public function setReadingTime($readingTime)
362 {
363 $this->readingTime = $readingTime;
364 }
365
366 /**
367 * @return string
368 */
369 public function getDomainName()
370 {
371 return $this->domainName;
372 }
373
374 /**
375 * @param string $domainName
376 */
377 public function setDomainName($domainName)
378 {
379 $this->domainName = $domainName;
380 }
381
382 /**
383 * @return bool
384 */
385 public function isPublic()
386 {
387 return $this->isPublic;
388 }
389
390 /**
391 * @param bool $isPublic
392 */
393 public function setPublic($isPublic)
394 {
395 $this->isPublic = $isPublic;
396 }
397
398 /**
399 * @return ArrayCollection<Tag>
400 */
401 public function getTags()
402 {
403 return $this->tags;
404 }
405
406 /**
407 * @param Tag $tag
408 */
409 public function addTag(Tag $tag)
410 {
411 $this->tags[] = $tag;
412 $tag->addEntry($this);
413 }
414
415 public function removeTag(Tag $tag)
416 {
417 $this->tags->removeElement($tag);
418 }
419 }