3 namespace Wallabag\CoreBundle\Entity
;
5 use Doctrine\Common\Collections\ArrayCollection
;
6 use Doctrine\ORM\Mapping
as ORM
;
7 use Gedmo\Mapping\Annotation
as Gedmo
;
8 use JMS\Serializer\Annotation\ExclusionPolicy
;
9 use JMS\Serializer\Annotation\Expose
;
10 use JMS\Serializer\Annotation\XmlRoot
;
18 * options={"collate"="utf8mb4_bin", "charset"="utf8mb4"},
20 * @ORM\Index(name="tag_label", columns={"label"}, options={"lengths"={255}}),
23 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
24 * @ExclusionPolicy("all")
32 * @ORM\Column(name="id", type="integer")
34 * @ORM\GeneratedValue(strategy="AUTO")
42 * @ORM\Column(name="label", type="text")
48 * @Gedmo\Slug(fields={"label"})
49 * @ORM\Column(length=128, unique=true)
54 * @ORM\ManyToMany(targetEntity="Entry", mappedBy="tags", cascade={"persist"})
58 public function __construct()
60 $this->entries
= new ArrayCollection();
63 public function __toString()
73 public function getId()
81 * @param string $label
85 public function setLabel($label)
87 $this->label
= mb_convert_case($label, MB_CASE_LOWER
);
97 public function getLabel()
102 public function getSlug()
107 public function addEntry(Entry
$entry)
109 if ($this->entries
->contains($entry)) {
113 $this->entries
->add($entry);
114 $entry->addTag($this);
117 public function removeEntry(Entry
$entry)
119 if (!$this->entries
->contains($entry)) {
123 $this->entries
->removeElement($entry);
124 $entry->removeTag($this);
127 public function hasEntry($entry)
129 return $this->entries
->contains($entry);
133 * Get entries for this tag.
135 * @return ArrayCollection<Entry>
137 public function getEntries()
139 return $this->entries
;
142 public function getEntriesByUserId($userId)
144 $filteredEntries = new ArrayCollection();
145 foreach ($this->entries
as $entry) {
146 if ($entry->getUser()->getId() === $userId) {
147 $filteredEntries->add($entry);
151 return $filteredEntries;