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