1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-06-27 16:36:00 +00:00
wallabag/src/Entity/Entry.php

955 lines
19 KiB
PHP
Raw Normal View History

2015-01-22 17:18:56 +01:00
<?php
2024-02-19 01:30:12 +01:00
namespace Wallabag\Entity;
2015-01-22 17:18:56 +01:00
2015-02-20 20:29:33 +01:00
use Doctrine\Common\Collections\ArrayCollection;
2015-01-22 17:18:56 +01:00
use Doctrine\ORM\Mapping as ORM;
use Hateoas\Configuration\Annotation as Hateoas;
2016-03-13 20:17:52 +01:00
use JMS\Serializer\Annotation\Exclude;
2017-07-01 09:52:38 +02:00
use JMS\Serializer\Annotation\Groups;
2016-03-13 20:17:52 +01:00
use JMS\Serializer\Annotation\SerializedName;
2017-07-01 09:52:38 +02:00
use JMS\Serializer\Annotation\VirtualProperty;
use JMS\Serializer\Annotation\XmlRoot;
use Symfony\Component\Validator\Constraints as Assert;
2024-02-19 01:30:12 +01:00
use Wallabag\Helper\EntityTimestampsTrait;
use Wallabag\Helper\UrlHasher;
2025-04-05 12:55:51 +02:00
use Wallabag\Repository\EntryRepository;
2015-01-22 17:18:56 +01:00
/**
2015-05-30 13:52:26 +02:00
* Entry.
2015-01-22 17:18:56 +01:00
*
* @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
2015-01-22 17:18:56 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Table(name: '`entry`')]
#[ORM\Index(columns: ['created_at'])]
#[ORM\Index(columns: ['uid'])]
#[ORM\Index(columns: ['user_id', 'hashed_url'])]
#[ORM\Index(columns: ['user_id', 'hashed_given_url'])]
#[ORM\Index(columns: ['language', 'user_id'])]
#[ORM\Index(columns: ['user_id', 'is_archived', 'archived_at'])]
#[ORM\Index(columns: ['user_id', 'created_at'])]
#[ORM\Index(columns: ['user_id', 'is_starred', 'starred_at'])]
#[ORM\Entity(repositoryClass: EntryRepository::class)]
#[ORM\HasLifecycleCallbacks]
2025-04-05 15:12:30 +02:00
#[XmlRoot('entry')]
2015-02-06 07:45:32 +01:00
class Entry
2015-01-22 17:18:56 +01:00
{
use EntityTimestampsTrait;
/** @Serializer\XmlAttribute */
2015-01-22 17:18:56 +01:00
/**
2015-05-30 13:52:26 +02:00
* @var int
2015-01-22 17:18:56 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2015-02-06 07:45:32 +01:00
private $id;
2015-01-22 17:18:56 +01:00
2016-04-10 17:33:15 +02:00
/**
2023-08-08 02:27:21 +01:00
* @var string|null
2016-04-10 17:33:15 +02:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'uid', type: 'string', length: 23, nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2016-12-29 10:09:44 +01:00
private $uid;
2016-04-10 17:33:15 +02:00
2015-01-22 17:18:56 +01:00
/**
2023-11-16 09:36:47 +01:00
* @var string|null
2015-01-22 17:18:56 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'title', type: 'text', nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2015-01-22 17:18:56 +01:00
private $title;
/**
* Define the url fetched by wallabag (the final url after potential redirections).
*
2023-11-16 09:36:47 +01:00
* @var string|null
2015-01-22 17:18:56 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'url', type: 'text', nullable: true)]
2025-04-05 15:06:57 +02:00
#[Assert\NotBlank]
#[Assert\Url(message: "The url '{{ value }}' is not a valid url")]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2015-01-22 17:18:56 +01:00
private $url;
/**
2023-11-16 09:36:47 +01:00
* @var string|null
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'hashed_url', type: 'string', length: 40, nullable: true)]
private $hashedUrl;
/**
* From where user retrieved/found the url (an other article, a twitter, or the given_url if non are provided).
*
2023-11-16 09:36:47 +01:00
* @var string|null
2015-01-22 17:18:56 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'origin_url', type: 'text', nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
private $originUrl;
2015-01-22 17:18:56 +01:00
/**
* Define the url entered by the user (without redirections).
*
2023-11-16 09:36:47 +01:00
* @var string|null
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'given_url', type: 'text', nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
private $givenUrl;
/**
2023-11-16 09:36:47 +01:00
* @var string|null
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'hashed_given_url', type: 'string', length: 40, nullable: true)]
private $hashedGivenUrl;
2015-01-22 17:18:56 +01:00
/**
2015-05-30 13:52:26 +02:00
* @var bool
2015-01-22 17:18:56 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'is_archived', type: 'boolean')]
2025-04-05 15:12:30 +02:00
#[Exclude]
#[Groups(['entries_for_user', 'export_all'])]
2015-02-05 22:33:36 +01:00
private $isArchived = false;
2015-01-22 17:18:56 +01:00
/**
2023-11-16 09:36:47 +01:00
* @var \DateTimeInterface|null
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'archived_at', type: 'datetime', nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2024-01-01 19:11:01 +01:00
private $archivedAt;
2015-01-22 17:18:56 +01:00
/**
2015-05-30 13:52:26 +02:00
* @var bool
2015-01-22 17:18:56 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'is_starred', type: 'boolean')]
2025-04-05 15:12:30 +02:00
#[Exclude]
#[Groups(['entries_for_user', 'export_all'])]
2015-02-05 22:33:36 +01:00
private $isStarred = false;
2015-01-22 17:18:56 +01:00
/**
2023-11-16 09:36:47 +01:00
* @var string|null
2015-01-22 17:18:56 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'content', type: 'text', nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
private $content;
2015-01-22 17:18:56 +01:00
2015-02-04 22:25:44 +01:00
/**
2023-08-08 02:27:21 +01:00
* @var \DateTimeInterface
2015-02-04 22:25:44 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'created_at', type: 'datetime')]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2015-02-04 22:25:44 +01:00
private $createdAt;
/**
2023-08-08 02:27:21 +01:00
* @var \DateTimeInterface
2015-02-04 22:25:44 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'updated_at', type: 'datetime')]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2015-02-04 22:25:44 +01:00
private $updatedAt;
2017-04-05 22:22:16 +02:00
/**
2023-11-16 09:36:47 +01:00
* @var \DateTimeInterface|null
2017-04-05 22:22:16 +02:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'published_at', type: 'datetime', nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2017-04-05 22:22:16 +02:00
private $publishedAt;
2017-04-06 09:36:20 +02:00
/**
2023-11-16 09:36:47 +01:00
* @var array|null
2017-04-06 09:36:20 +02:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'published_by', type: 'array', nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2017-04-06 09:36:20 +02:00
private $publishedBy;
/**
2023-11-16 09:36:47 +01:00
* @var \DateTimeInterface|null
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'starred_at', type: 'datetime', nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2024-01-01 19:11:01 +01:00
private $starredAt;
2025-04-05 12:55:51 +02:00
#[ORM\JoinTable]
#[ORM\OneToMany(targetEntity: Annotation::class, mappedBy: 'entry', cascade: ['persist', 'remove'])]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
private $annotations;
2015-02-04 22:25:44 +01:00
/**
2023-11-16 09:36:47 +01:00
* @var string|null
2015-02-04 22:25:44 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'mimetype', type: 'text', nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2015-02-04 22:25:44 +01:00
private $mimetype;
2015-09-20 22:37:27 +02:00
/**
2023-11-16 09:36:47 +01:00
* @var string|null
2015-09-20 22:37:27 +02:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'language', type: 'string', length: 20, nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2015-09-20 22:37:27 +02:00
private $language;
2015-02-04 22:25:44 +01:00
/**
2015-05-30 13:52:26 +02:00
* @var int
2015-02-04 22:25:44 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'reading_time', type: 'integer', nullable: false)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
private $readingTime = 0;
2015-02-04 22:25:44 +01:00
/**
2023-11-16 09:36:47 +01:00
* @var string|null
2015-02-04 22:25:44 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'domain_name', type: 'text', nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2015-02-04 22:25:44 +01:00
private $domainName;
2015-08-24 12:27:17 +02:00
/**
2023-11-16 09:36:47 +01:00
* @var string|null
2015-08-24 12:27:17 +02:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'preview_picture', type: 'text', nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2015-08-24 12:27:17 +02:00
private $previewPicture;
2016-11-18 15:09:21 +01:00
/**
2023-11-16 09:36:47 +01:00
* @var string|null
2016-11-18 15:09:21 +01:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'http_status', type: 'string', length: 3, nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2016-11-18 15:09:21 +01:00
private $httpStatus;
2017-05-11 14:18:21 +02:00
/**
2023-11-16 09:36:47 +01:00
* @var array|null
2017-05-11 14:18:21 +02:00
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'headers', type: 'array', nullable: true)]
2025-04-05 15:12:30 +02:00
#[Groups(['entries_for_user', 'export_all'])]
2017-05-11 14:18:21 +02:00
private $headers;
/**
* @var bool
*/
2025-04-05 12:55:51 +02:00
#[ORM\Column(name: 'is_not_parsed', type: 'boolean', options: ['default' => false])]
2025-04-05 15:12:30 +02:00
#[Exclude]
#[Groups(['entries_for_user', 'export_all'])]
private $isNotParsed = false;
2025-04-05 12:55:51 +02:00
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'entries')]
2025-04-05 15:12:30 +02:00
#[Exclude]
#[Groups(['export_all'])]
private $user;
2025-04-05 12:55:51 +02:00
#[ORM\JoinTable(name: 'entry_tag')]
#[ORM\JoinColumn(name: 'entry_id', referencedColumnName: 'id', onDelete: 'cascade')]
#[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id', onDelete: 'cascade')]
#[ORM\ManyToMany(targetEntity: Tag::class, inversedBy: 'entries', cascade: ['persist'])]
2015-02-20 20:29:33 +01:00
private $tags;
/*
* @param User $user
*/
public function __construct(User $user)
{
$this->user = $user;
2015-02-20 20:29:33 +01:00
$this->tags = new ArrayCollection();
}
2015-01-22 17:18:56 +01:00
/**
2015-05-30 13:52:26 +02:00
* Get id.
2015-01-22 17:18:56 +01:00
*
2015-05-30 13:52:26 +02:00
* @return int
2015-01-22 17:18:56 +01:00
*/
public function getId()
{
return $this->id;
}
/**
2015-05-30 13:52:26 +02:00
* Set title.
*
* @param string $title
2015-01-22 17:18:56 +01:00
*
2015-02-06 07:45:32 +01:00
* @return Entry
2015-01-22 17:18:56 +01:00
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
2015-05-30 13:52:26 +02:00
* Get title.
2015-01-22 17:18:56 +01:00
*
2015-01-31 19:09:34 +01:00
* @return string
2015-01-22 17:18:56 +01:00
*/
public function getTitle()
{
return $this->title;
}
/**
2015-05-30 13:52:26 +02:00
* Set url.
*
* @param string $url
2015-01-22 17:18:56 +01:00
*
2015-02-06 07:45:32 +01:00
* @return Entry
2015-01-22 17:18:56 +01:00
*/
public function setUrl($url)
{
$this->url = $url;
$this->hashedUrl = UrlHasher::hashUrl($url);
2015-01-22 17:18:56 +01:00
return $this;
}
/**
2015-05-30 13:52:26 +02:00
* Get url.
2015-01-22 17:18:56 +01:00
*
2015-01-31 19:09:34 +01:00
* @return string
2015-01-22 17:18:56 +01:00
*/
public function getUrl()
{
return $this->url;
}
/**
2015-05-30 13:52:26 +02:00
* Set isArchived.
*
* @param bool $isArchived
2015-01-22 17:18:56 +01:00
*
2015-02-06 07:45:32 +01:00
* @return Entry
2015-01-22 17:18:56 +01:00
*/
2015-02-05 22:33:36 +01:00
public function setArchived($isArchived)
2015-01-22 17:18:56 +01:00
{
2015-02-05 22:33:36 +01:00
$this->isArchived = $isArchived;
2015-01-22 17:18:56 +01:00
return $this;
}
/**
* update isArchived and archive_at fields.
*
* @param bool $isArchived
*
* @return Entry
*/
public function updateArchived($isArchived = false)
{
$this->setArchived($isArchived);
$this->setArchivedAt(null);
if ($this->isArchived()) {
$this->setArchivedAt(new \DateTime());
}
return $this;
}
/**
2023-08-08 02:27:21 +01:00
* @return \DateTimeInterface|null
*/
public function getArchivedAt()
{
return $this->archivedAt;
}
/**
2023-08-08 02:27:21 +01:00
* @param \DateTimeInterface|null $archivedAt
*
* @return Entry
*/
public function setArchivedAt($archivedAt = null)
{
$this->archivedAt = $archivedAt;
return $this;
}
2015-01-22 17:18:56 +01:00
/**
2015-05-30 13:52:26 +02:00
* Get isArchived.
2015-01-22 17:18:56 +01:00
*
* @return bool
2015-01-22 17:18:56 +01:00
*/
2015-02-05 22:33:36 +01:00
public function isArchived()
2015-01-22 17:18:56 +01:00
{
2015-02-05 22:33:36 +01:00
return $this->isArchived;
2015-01-22 17:18:56 +01:00
}
2025-04-05 15:12:30 +02:00
#[VirtualProperty]
#[SerializedName('is_archived')]
#[Groups(['entries_for_user', 'export_all'])]
public function is_Archived()
{
return (int) $this->isArchived();
}
2015-01-23 12:45:24 +01:00
public function toggleArchive()
{
$this->updateArchived($this->isArchived() ^ 1);
2015-01-31 19:09:34 +01:00
2015-01-23 12:45:24 +01:00
return $this;
}
2015-01-22 17:18:56 +01:00
/**
2015-05-30 13:52:26 +02:00
* Set isStarred.
*
* @param bool $isStarred
2015-01-22 17:18:56 +01:00
*
2015-02-06 07:45:32 +01:00
* @return Entry
2015-01-22 17:18:56 +01:00
*/
2015-02-05 22:33:36 +01:00
public function setStarred($isStarred)
2015-01-22 17:18:56 +01:00
{
2015-02-05 22:33:36 +01:00
$this->isStarred = $isStarred;
2015-01-22 17:18:56 +01:00
return $this;
}
/**
2015-05-30 13:52:26 +02:00
* Get isStarred.
2015-01-22 17:18:56 +01:00
*
* @return bool
2015-01-22 17:18:56 +01:00
*/
2015-02-05 22:33:36 +01:00
public function isStarred()
2015-01-22 17:18:56 +01:00
{
2015-02-05 22:33:36 +01:00
return $this->isStarred;
2015-01-22 17:18:56 +01:00
}
2025-04-05 15:12:30 +02:00
#[VirtualProperty]
#[SerializedName('is_starred')]
#[Groups(['entries_for_user', 'export_all'])]
public function is_Starred()
{
return (int) $this->isStarred();
}
2015-01-23 12:45:24 +01:00
public function toggleStar()
{
2023-08-08 02:27:21 +01:00
$this->isStarred = !$this->isStarred();
2015-01-23 12:45:24 +01:00
return $this;
}
2015-01-22 17:18:56 +01:00
/**
2015-05-30 13:52:26 +02:00
* Set content.
*
* @param string $content
2015-01-22 17:18:56 +01:00
*
2015-02-06 07:45:32 +01:00
* @return Entry
2015-01-22 17:18:56 +01:00
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
2015-05-30 13:52:26 +02:00
* Get content.
2015-01-22 17:18:56 +01:00
*
2015-01-31 19:09:34 +01:00
* @return string
2015-01-22 17:18:56 +01:00
*/
public function getContent()
{
return $this->content;
}
/**
* @return User
2015-01-22 17:18:56 +01:00
*/
public function getUser()
2015-01-22 17:18:56 +01:00
{
return $this->user;
2015-01-22 17:18:56 +01:00
}
2015-02-04 17:54:23 +01:00
2025-04-05 15:12:30 +02:00
#[VirtualProperty]
#[SerializedName('user_name')]
2016-03-13 20:17:52 +01:00
public function getUserName()
{
return $this->user->getUserName();
}
2025-04-05 15:12:30 +02:00
#[VirtualProperty]
#[SerializedName('user_email')]
2016-03-13 20:17:52 +01:00
public function getUserEmail()
{
return $this->user->getEmail();
}
2025-04-05 15:12:30 +02:00
#[VirtualProperty]
#[SerializedName('user_id')]
2016-03-13 20:17:52 +01:00
public function getUserId()
{
return $this->user->getId();
}
2015-02-04 22:25:44 +01:00
/**
* Set created_at.
* Only used when importing data from an other service.
*
* @return Entry
*/
public function setCreatedAt(\DateTimeInterface $createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
2023-08-08 02:27:21 +01:00
* @return \DateTimeInterface
2015-02-04 22:25:44 +01:00
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
2023-08-08 02:27:21 +01:00
* @return \DateTimeInterface
2015-02-04 22:25:44 +01:00
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
2023-08-08 02:27:21 +01:00
* @return \DateTimeInterface|null
*/
public function getStarredAt()
{
return $this->starredAt;
}
/**
2023-08-08 02:27:21 +01:00
* @param \DateTimeInterface|null $starredAt
*
* @return Entry
*/
public function setStarredAt($starredAt = null)
{
$this->starredAt = $starredAt;
return $this;
}
/**
* update isStarred and starred_at fields.
*
* @param bool $isStarred
*
* @return Entry
*/
public function updateStar($isStarred = false)
{
$this->setStarred($isStarred);
$this->setStarredAt(null);
if ($this->isStarred()) {
$this->setStarredAt(new \DateTime());
}
return $this;
}
2015-02-04 22:25:44 +01:00
/**
* @return ArrayCollection<Annotation>
2015-02-04 22:25:44 +01:00
*/
public function getAnnotations()
2015-02-04 22:25:44 +01:00
{
return $this->annotations;
2015-02-04 22:25:44 +01:00
}
public function setAnnotation(Annotation $annotation)
2015-02-04 22:25:44 +01:00
{
$this->annotations[] = $annotation;
2015-02-04 22:25:44 +01:00
}
/**
* @return string
*/
public function getMimetype()
{
return $this->mimetype;
}
/**
* @param string $mimetype
*/
public function setMimetype($mimetype)
{
$this->mimetype = $mimetype;
}
/**
* @return int
*/
public function getReadingTime()
{
return $this->readingTime;
}
/**
* @param int $readingTime
*/
public function setReadingTime($readingTime)
{
$this->readingTime = $readingTime;
}
/**
* @return string
*/
public function getDomainName()
{
return $this->domainName;
}
/**
* @param string $domainName
*/
public function setDomainName($domainName)
{
$this->domainName = $domainName;
}
2015-02-20 20:29:33 +01:00
/**
2017-05-30 13:01:25 +02:00
* @return ArrayCollection
2015-02-20 20:29:33 +01:00
*/
public function getTags()
{
return $this->tags;
}
/**
* Only used during tests.
*/
public function getTagsLabel(): array
{
$tags = [];
foreach ($this->tags as $tag) {
$tags[] = $tag->getLabel();
}
return $tags;
}
2025-04-05 15:12:30 +02:00
#[VirtualProperty]
#[SerializedName('tags')]
#[Groups(['entries_for_user', 'export_all'])]
public function getSerializedTags()
{
$data = [];
foreach ($this->tags as $tag) {
$data[] = $tag->getLabel();
}
return $data;
}
2015-02-20 20:29:33 +01:00
public function addTag(Tag $tag)
{
if ($this->tags->contains($tag)) {
return;
}
// check if tag already exist but has not yet be persisted
// it seems that the previous condition with `contains()` doesn't check that case
foreach ($this->tags as $existingTag) {
2015-12-29 14:50:52 +01:00
if ($existingTag->getLabel() === $tag->getLabel()) {
return;
}
}
$this->tags->add($tag);
2015-02-20 20:29:33 +01:00
}
/**
* Remove the given tag from the entry (if the tag is associated).
*/
public function removeTag(Tag $tag)
{
if (!$this->tags->contains($tag)) {
return;
}
$this->tags->removeElement($tag);
$tag->removeEntry($this);
}
2015-08-24 12:27:17 +02:00
/**
* Remove all assigned tags from the entry.
*/
public function removeAllTags()
{
foreach ($this->tags as $tag) {
$this->tags->removeElement($tag);
$tag->removeEntry($this);
}
}
2015-08-24 12:27:17 +02:00
/**
2015-08-24 12:35:02 +02:00
* Set previewPicture.
2015-08-24 12:27:17 +02:00
*
* @param string $previewPicture
*
* @return Entry
*/
public function setPreviewPicture($previewPicture)
{
$this->previewPicture = $previewPicture;
return $this;
}
/**
2015-08-24 12:35:02 +02:00
* Get previewPicture.
2015-08-24 12:27:17 +02:00
*
* @return string
*/
public function getPreviewPicture()
{
return $this->previewPicture;
}
2015-09-20 22:37:27 +02:00
/**
* Set language.
*
* @param string $language
*
* @return Entry
*/
public function setLanguage($language)
{
$this->language = $language;
return $this;
}
/**
* Get language.
*
* @return string
*/
public function getLanguage()
{
return $this->language;
}
2016-04-10 17:33:15 +02:00
2019-01-11 21:09:49 +01:00
/**
* Format the entry language to a valid html lang attribute.
*/
public function getHTMLLanguage()
{
$parsedLocale = \Locale::parseLocale($this->getLanguage());
$lang = '';
$lang .= $parsedLocale['language'] ?? '';
$lang .= isset($parsedLocale['region']) ? '-' . $parsedLocale['region'] : '';
return $lang;
}
2016-04-10 17:33:15 +02:00
/**
2019-05-29 12:00:23 +02:00
* @return string|null
2016-04-10 17:33:15 +02:00
*/
2016-12-29 10:09:44 +01:00
public function getUid()
2016-04-10 17:33:15 +02:00
{
2016-12-29 10:09:44 +01:00
return $this->uid;
2016-04-10 17:33:15 +02:00
}
/**
2016-12-29 10:09:44 +01:00
* @param string $uid
2016-04-10 17:33:15 +02:00
*
* @return Entry
*/
2016-12-29 10:09:44 +01:00
public function setUid($uid)
2016-04-10 17:33:15 +02:00
{
2016-12-29 10:09:44 +01:00
$this->uid = $uid;
2016-04-10 17:33:15 +02:00
return $this;
}
2016-12-29 10:09:44 +01:00
public function generateUid()
2016-04-10 17:33:15 +02:00
{
2016-12-29 10:09:44 +01:00
if (null === $this->uid) {
2016-04-15 13:42:13 +02:00
// @see http://blog.kevingomez.fr/til/2015/07/26/why-is-uniqid-slow/ for true parameter
2016-12-29 10:09:44 +01:00
$this->uid = uniqid('', true);
2016-04-10 17:33:15 +02:00
}
}
2016-08-23 16:49:12 +02:00
2016-12-29 10:09:44 +01:00
public function cleanUid()
2016-08-23 16:49:12 +02:00
{
2016-12-29 10:09:44 +01:00
$this->uid = null;
2016-08-23 16:49:12 +02:00
}
2016-11-18 15:09:21 +01:00
2017-06-10 15:00:52 +02:00
/**
* Used in the entries filter so it's more explicit for the end user than the uid.
2017-06-10 15:37:25 +02:00
* Also used in the API.
2017-06-10 15:00:52 +02:00
*
* @return bool
*/
2025-04-05 15:12:30 +02:00
#[VirtualProperty]
#[SerializedName('is_public')]
#[Groups(['entries_for_user'])]
2017-06-10 15:00:52 +02:00
public function isPublic()
{
return null !== $this->uid;
}
2016-11-18 15:09:21 +01:00
/**
2017-05-30 11:39:15 +02:00
* @return string
2016-11-18 15:09:21 +01:00
*/
public function getHttpStatus()
{
return $this->httpStatus;
}
/**
2017-05-30 11:39:15 +02:00
* @param string $httpStatus
2016-11-18 15:09:21 +01:00
*
* @return Entry
*/
public function setHttpStatus($httpStatus)
{
$this->httpStatus = $httpStatus;
return $this;
}
2017-04-05 22:22:16 +02:00
/**
2023-08-08 02:27:21 +01:00
* @return \DateTimeInterface
2017-04-05 22:22:16 +02:00
*/
public function getPublishedAt()
{
return $this->publishedAt;
}
/**
* @return Entry
*/
2023-08-08 02:27:21 +01:00
public function setPublishedAt(\DateTimeInterface $publishedAt)
2017-04-05 22:22:16 +02:00
{
$this->publishedAt = $publishedAt;
return $this;
}
2017-04-06 09:36:20 +02:00
/**
2017-05-11 14:18:21 +02:00
* @return array
2017-04-06 09:36:20 +02:00
*/
public function getPublishedBy()
{
return $this->publishedBy;
}
/**
* @param array $publishedBy
2017-04-06 09:36:20 +02:00
*
* @return Entry
*/
public function setPublishedBy($publishedBy)
{
$this->publishedBy = $publishedBy;
return $this;
}
2017-05-11 14:18:21 +02:00
/**
* @return array
*/
public function getHeaders()
{
return $this->headers;
}
/**
* @param array $headers
2017-05-11 14:18:21 +02:00
*
* @return Entry
*/
public function setHeaders($headers)
{
$this->headers = $headers;
return $this;
}
/**
* Set origin url.
*
* @param string $originUrl
*
* @return Entry
*/
public function setOriginUrl($originUrl)
{
$this->originUrl = $originUrl;
return $this;
}
/**
* Get origin url.
*
* @return string
*/
public function getOriginUrl()
{
return $this->originUrl;
}
/**
2019-06-05 10:54:43 +02:00
* Set given url.
*
* @param string $givenUrl
*
* @return Entry
*/
public function setGivenUrl($givenUrl)
{
$this->givenUrl = $givenUrl;
$this->hashedGivenUrl = UrlHasher::hashUrl($givenUrl);
return $this;
}
/**
2019-06-05 10:54:43 +02:00
* Get given url.
*
* @return string
*/
public function getGivenUrl()
{
return $this->givenUrl;
}
/**
* @return string
*/
public function getHashedUrl()
{
return $this->hashedUrl;
}
/**
* @return Entry
*/
public function setHashedUrl($hashedUrl)
{
$this->hashedUrl = $hashedUrl;
return $this;
}
/**
* Set isNotParsed.
*
* @return Entry
*/
2024-03-10 17:30:29 +01:00
public function setNotParsed(bool $isNotParsed)
{
$this->isNotParsed = $isNotParsed;
return $this;
}
/**
* Get isNotParsed.
*/
2024-03-10 17:30:29 +01:00
public function isNotParsed(): bool
{
return $this->isNotParsed;
}
2015-01-22 17:18:56 +01:00
}