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\Helper\Tools
;
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="is_public", type="boolean", nullable=true, options={"default" = false})
119 * @ORM\ManyToOne(targetEntity="User", inversedBy="entries")
124 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
132 public function __construct(User
$user)
135 $this->tags
= new ArrayCollection();
143 public function getId()
151 * @param string $title
155 public function setTitle($title)
157 $this->title
= $title;
167 public function getTitle()
179 public function setUrl($url)
191 public function getUrl()
199 * @param string $isArchived
203 public function setArchived($isArchived)
205 $this->isArchived
= $isArchived;
215 public function isArchived()
217 return $this->isArchived
;
220 public function toggleArchive()
222 $this->isArchived
= $this->isArchived() ^
1;
230 * @param string $isStarred
234 public function setStarred($isStarred)
236 $this->isStarred
= $isStarred;
246 public function isStarred()
248 return $this->isStarred
;
251 public function toggleStar()
253 $this->isStarred
= $this->isStarred() ^
1;
261 * @param string $content
265 public function setContent($content)
267 $this->content
= $content;
268 $this->readingTime
= Tools
::getReadingTime($content);
269 $this->domainName
= parse_url($this->url
, PHP_URL_HOST
);
279 public function getContent()
281 return $this->content
;
287 public function getUser()
295 public function getCreatedAt()
297 return $this->createdAt
;
303 public function getUpdatedAt()
305 return $this->updatedAt
;
312 public function timestamps()
314 if (is_null($this->createdAt
)) {
315 $this->createdAt
= new \
DateTime();
318 $this->updatedAt
= new \
DateTime();
324 public function getComments()
326 return $this->comments
;
330 * @param string $comments
332 public function setComments($comments)
334 $this->comments
= $comments;
340 public function getMimetype()
342 return $this->mimetype
;
346 * @param string $mimetype
348 public function setMimetype($mimetype)
350 $this->mimetype
= $mimetype;
356 public function getReadingTime()
358 return $this->readingTime
;
362 * @param int $readingTime
364 public function setReadingTime($readingTime)
366 $this->readingTime
= $readingTime;
372 public function getDomainName()
374 return $this->domainName
;
378 * @param string $domainName
380 public function setDomainName($domainName)
382 $this->domainName
= $domainName;
388 public function isPublic()
390 return $this->isPublic
;
394 * @param bool $isPublic
396 public function setIsPublic($isPublic)
398 $this->isPublic
= $isPublic;
402 * @return ArrayCollection<Tag>
404 public function getTags()
412 public function addTag(Tag
$tag)
414 $this->tags
[] = $tag;
415 $tag->addEntry($this);
418 public function removeTag(Tag
$tag)
420 $this->tags
->removeElement($tag);