3 namespace Wallabag\CoreBundle\Entity
;
5 use Doctrine\Common\Collections\ArrayCollection
;
6 use Doctrine\ORM\Mapping
as ORM
;
7 use JMS\Serializer\Annotation\ExclusionPolicy
;
8 use JMS\Serializer\Annotation\Expose
;
9 use Gedmo\Mapping\Annotation
as Gedmo
;
10 use JMS\Serializer\Annotation\XmlRoot
;
16 * @ORM\Table(name="`tag`")
17 * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
18 * @ExclusionPolicy("all")
26 * @ORM\Column(name="id", type="integer")
28 * @ORM\GeneratedValue(strategy="AUTO")
36 * @ORM\Column(name="label", type="text")
42 * @Gedmo\Slug(fields={"label"})
43 * @ORM\Column(length=128, unique=true)
48 * @ORM\ManyToMany(targetEntity="Entry", mappedBy="tags", cascade={"persist"})
52 public function __construct()
54 $this->entries
= new ArrayCollection();
57 public function __toString()
67 public function getId()
75 * @param string $label
79 public function setLabel($label)
81 $this->label
= $label;
91 public function getLabel()
96 public function getSlug()
102 * @param Entry $entry
104 public function addEntry(Entry
$entry)
106 if ($this->entries
->contains($entry)) {
110 $this->entries
->add($entry);
111 $entry->addTag($this);
115 * @param Entry $entry
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;