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\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
21 * @ExclusionPolicy("all")
29 * @ORM\Column(name="id", type="integer")
31 * @ORM\GeneratedValue(strategy="AUTO")
39 * @ORM\Column(name="label", type="text")
45 * @Gedmo\Slug(fields={"label"})
46 * @ORM\Column(length=128, unique=true)
51 * @ORM\ManyToMany(targetEntity="Entry", mappedBy="tags", cascade={"persist"})
55 public function __construct()
57 $this->entries
= new ArrayCollection();
60 public function __toString()
70 public function getId()
78 * @param string $label
82 public function setLabel($label)
84 $this->label
= mb_convert_case($label, MB_CASE_LOWER
);
94 public function getLabel()
99 public function getSlug()
105 * @param Entry $entry
107 public function addEntry(Entry
$entry)
109 if ($this->entries
->contains($entry)) {
113 $this->entries
->add($entry);
114 $entry->addTag($this);
118 * @param Entry $entry
120 public function removeEntry(Entry
$entry)
122 if (!$this->entries
->contains($entry)) {
126 $this->entries
->removeElement($entry);
127 $entry->removeTag($this);
130 public function hasEntry($entry)
132 return $this->entries
->contains($entry);
136 * Get entries for this tag.
138 * @return ArrayCollection<Entry>
140 public function getEntries()
142 return $this->entries
;
145 public function getEntriesByUserId($userId)
147 $filteredEntries = new ArrayCollection();
148 foreach ($this->entries
as $entry) {
149 if ($entry->getUser()->getId() === $userId) {
150 $filteredEntries->add($entry);
154 return $filteredEntries;