X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=src%2FWallabag%2FCoreBundle%2FEntity%2FTag.php;h=4b480ff1cdc4f2c4ebc2b7e4bf4b558edb95eb9a;hb=5ecdfcd041767c9e3244a92bb0a6cc3c3f80fea3;hp=4ed588be867be0a3b38227dce42b863999721bee;hpb=3c65dfb735c7ccdee3d8ea420fe295439d53bb13;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php index 4ed588be..4b480ff1 100644 --- a/src/Wallabag/CoreBundle/Entity/Tag.php +++ b/src/Wallabag/CoreBundle/Entity/Tag.php @@ -2,12 +2,12 @@ namespace Wallabag\CoreBundle\Entity; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; -use JMS\Serializer\Annotation\XmlRoot; use JMS\Serializer\Annotation\ExclusionPolicy; use JMS\Serializer\Annotation\Expose; -use Doctrine\Common\Collections\ArrayCollection; use Gedmo\Mapping\Annotation as Gedmo; +use JMS\Serializer\Annotation\XmlRoot; /** * Tag. @@ -38,6 +38,7 @@ class Tag private $label; /** + * @Expose * @Gedmo\Slug(fields={"label"}) * @ORM\Column(length=128, unique=true) */ @@ -48,14 +49,8 @@ class Tag */ private $entries; - /** - * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="tags") - */ - private $user; - - public function __construct(\Wallabag\UserBundle\Entity\User $user) + public function __construct() { - $this->user = $user; $this->entries = new ArrayCollection(); } @@ -103,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) @@ -114,10 +130,24 @@ class Tag } /** - * @return User + * Get entries for this tag. + * + * @return ArrayCollection */ - public function getUser() + public function getEntries() + { + return $this->entries; + } + + public function getEntriesByUserId($userId) { - return $this->user; + $filteredEntries = new ArrayCollection(); + foreach ($this->entries as $entry) { + if ($entry->getUser()->getId() === $userId) { + $filteredEntries->add($entry); + } + } + + return $filteredEntries; } }