X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FEntity%2FTag.php;h=c19023af5bffdd8af1175840bea9b15a522a5251;hb=2490f61dca635026a3eb9b5e9b6978b1981b1172;hp=f6c42f5d72eb65f02f7152b9870214218702bf4e;hpb=12c697562e11bed4d2c2af0521a67219dd62ee63;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php index f6c42f5d..c19023af 100644 --- a/src/Wallabag/CoreBundle/Entity/Tag.php +++ b/src/Wallabag/CoreBundle/Entity/Tag.php @@ -4,9 +4,9 @@ namespace Wallabag\CoreBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; +use Gedmo\Mapping\Annotation as Gedmo; use JMS\Serializer\Annotation\ExclusionPolicy; use JMS\Serializer\Annotation\Expose; -use Gedmo\Mapping\Annotation as Gedmo; use JMS\Serializer\Annotation\XmlRoot; /** @@ -98,9 +98,30 @@ class Tag return $this->slug; } + /** + * @param Entry $entry + */ public function addEntry(Entry $entry) { - $this->entries[] = $entry; + if ($this->entries->contains($entry)) { + return; + } + + $this->entries->add($entry); + $entry->addTag($this); + } + + /** + * @param Entry $entry + */ + public function removeEntry(Entry $entry) + { + if (!$this->entries->contains($entry)) { + return; + } + + $this->entries->removeElement($entry); + $entry->removeTag($this); } public function hasEntry($entry) @@ -118,7 +139,7 @@ class Tag return $this->entries; } - public function getEntriesByUser($userId) + public function getEntriesByUserId($userId) { $filteredEntries = new ArrayCollection(); foreach ($this->entries as $entry) {