3 namespace Wallabag\CoreBundle\Entity
;
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 use Wallabag\CoreBundle\Tools\Utils
;
16 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
18 * @ORM\HasLifecycleCallbacks()
19 * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
23 /** @Serializer\XmlAttribute */
27 * @ORM\Column(name="id", type="integer")
29 * @ORM\GeneratedValue(strategy="AUTO")
36 * @ORM\Column(name="title", type="text", nullable=true)
44 * @ORM\Column(name="url", type="text", nullable=true)
51 * @ORM\Column(name="is_archived", type="boolean")
53 private $isArchived = false;
58 * @ORM\Column(name="is_starred", type="boolean")
60 private $isStarred = false;
65 * @ORM\Column(name="content", type="text", nullable=true)
72 * @ORM\Column(name="created_at", type="datetime")
79 * @ORM\Column(name="updated_at", type="datetime")
86 * @ORM\Column(name="comments", type="text", nullable=true)
93 * @ORM\Column(name="mimetype", type="text", nullable=true)
100 * @ORM\Column(name="reading_time", type="integer", nullable=true)
102 private $readingTime;
107 * @ORM\Column(name="domain_name", type="text", nullable=true)
114 * @ORM\Column(name="preview_picture", type="text", nullable=true)
116 private $previewPicture;
121 * @ORM\Column(name="is_public", type="boolean", nullable=true, options={"default" = false})
126 * @ORM\ManyToOne(targetEntity="User", inversedBy="entries")
131 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
139 public function __construct(User
$user)
142 $this->tags
= new ArrayCollection();
150 public function getId()
158 * @param string $title
162 public function setTitle($title)
164 $this->title
= $title;
174 public function getTitle()
186 public function setUrl($url)
198 public function getUrl()
206 * @param string $isArchived
210 public function setArchived($isArchived)
212 $this->isArchived
= $isArchived;
222 public function isArchived()
224 return $this->isArchived
;
227 public function toggleArchive()
229 $this->isArchived
= $this->isArchived() ^
1;
237 * @param string $isStarred
241 public function setStarred($isStarred)
243 $this->isStarred
= $isStarred;
253 public function isStarred()
255 return $this->isStarred
;
258 public function toggleStar()
260 $this->isStarred
= $this->isStarred() ^
1;
268 * @param string $content
272 public function setContent($content)
274 $this->content
= $content;
275 $this->readingTime
= Utils
::getReadingTime($content);
276 $this->domainName
= parse_url($this->url
, PHP_URL_HOST
);
286 public function getContent()
288 return $this->content
;
294 public function getUser()
302 public function getCreatedAt()
304 return $this->createdAt
;
310 public function getUpdatedAt()
312 return $this->updatedAt
;
319 public function timestamps()
321 if (is_null($this->createdAt
)) {
322 $this->createdAt
= new \
DateTime();
325 $this->updatedAt
= new \
DateTime();
331 public function getComments()
333 return $this->comments
;
337 * @param string $comments
339 public function setComments($comments)
341 $this->comments
= $comments;
347 public function getMimetype()
349 return $this->mimetype
;
353 * @param string $mimetype
355 public function setMimetype($mimetype)
357 $this->mimetype
= $mimetype;
363 public function getReadingTime()
365 return $this->readingTime
;
369 * @param int $readingTime
371 public function setReadingTime($readingTime)
373 $this->readingTime
= $readingTime;
379 public function getDomainName()
381 return $this->domainName
;
385 * @param string $domainName
387 public function setDomainName($domainName)
389 $this->domainName
= $domainName;
395 public function isPublic()
397 return $this->isPublic
;
401 * @param bool $isPublic
403 public function setIsPublic($isPublic)
405 $this->isPublic
= $isPublic;
409 * @return ArrayCollection<Tag>
411 public function getTags()
419 public function addTag(Tag
$tag)
421 $this->tags
[] = $tag;
422 $tag->addEntry($this);
425 public function removeTag(Tag
$tag)
427 $this->tags
->removeElement($tag);
433 * @param string $previewPicture
437 public function setPreviewPicture($previewPicture)
439 $this->previewPicture
= $previewPicture;
449 public function getPreviewPicture()
451 return $this->previewPicture
;