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()
108 * @param Entry $entry
110 public function addEntry(Entry
$entry)
112 if ($this->entries
->contains($entry)) {
116 $this->entries
->add($entry);
117 $entry->addTag($this);
121 * @param Entry $entry
123 public function removeEntry(Entry
$entry)
125 if (!$this->entries
->contains($entry)) {
129 $this->entries
->removeElement($entry);
130 $entry->removeTag($this);
133 public function hasEntry($entry)
135 return $this->entries
->contains($entry);
139 * Get entries for this tag.
141 * @return ArrayCollection<Entry>
143 public function getEntries()
145 return $this->entries
;
148 public function getEntriesByUserId($userId)
150 $filteredEntries = new ArrayCollection();
151 foreach ($this->entries
as $entry) {
152 if ($entry->getUser()->getId() === $userId) {
153 $filteredEntries->add($entry);
157 return $filteredEntries;