entries = new ArrayCollection(); } public function __toString() { return $this->label; } /** * Get id. * * @return int */ public function getId() { return $this->id; } /** * Set label. * * @param string $label * * @return Tag */ public function setLabel($label) { $this->label = mb_convert_case($label, \MB_CASE_LOWER); return $this; } /** * Get label. * * @return string */ public function getLabel() { return $this->label; } public function getSlug() { return $this->slug; } public function addEntry(Entry $entry) { if ($this->entries->contains($entry)) { return; } $this->entries->add($entry); $entry->addTag($this); } public function removeEntry(Entry $entry) { if (!$this->entries->contains($entry)) { return; } $this->entries->removeElement($entry); $entry->removeTag($this); } public function hasEntry($entry) { return $this->entries->contains($entry); } /** * Get entries for this tag. * * @return ArrayCollection */ public function getEntries() { return $this->entries; } public function getEntriesByUserId($userId) { $filteredEntries = new ArrayCollection(); foreach ($this->entries as $entry) { if ($entry->getUser()->getId() === $userId) { $filteredEntries->add($entry); } } return $filteredEntries; } }