From 092ca70725b0263390e45c46f93828c613eca3f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 26 Feb 2015 09:41:42 +0100 Subject: add relation between user and tags, tests are broken --- src/Wallabag/CoreBundle/Entity/Entry.php | 5 +++++ src/Wallabag/CoreBundle/Entity/Tag.php | 8 +++++++- src/Wallabag/CoreBundle/Entity/User.php | 30 ++++++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Entity') diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 229a6704..75aeae84 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -406,4 +406,9 @@ class Entry $this->tags[] = $tag; $tag->addEntry($this); } + + public function removeTag(Tag $tag) + { + $this->tags->removeElement($tag); + } } diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php index 5aed1fa0..29a5e4b5 100644 --- a/src/Wallabag/CoreBundle/Entity/Tag.php +++ b/src/Wallabag/CoreBundle/Entity/Tag.php @@ -41,8 +41,14 @@ class Tag */ private $entries; - public function __construct() + /** + * @ORM\ManyToOne(targetEntity="User", inversedBy="tags") + */ + private $user; + + public function __construct(User $user) { + $this->user = $user; $this->entries = new ArrayCollection(); } /** diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php index 5589c039..f05c8760 100644 --- a/src/Wallabag/CoreBundle/Entity/User.php +++ b/src/Wallabag/CoreBundle/Entity/User.php @@ -101,10 +101,17 @@ class User implements AdvancedUserInterface, \Serializable */ private $config; + /** + * @ORM\OneToMany(targetEntity="Tag", mappedBy="user", cascade={"remove"}) + */ + private $tags; + public function __construct() { - $this->salt = md5(uniqid(null, true)); - $this->entries = new ArrayCollection(); + $this->isActive = true; + $this->salt = md5(uniqid(null, true)); + $this->entries = new ArrayCollection(); + $this->tags = new ArrayCollection(); } /** @@ -278,6 +285,25 @@ class User implements AdvancedUserInterface, \Serializable return $this->entries; } + /** + * @param Entry $entry + * + * @return User + */ + public function addTag(Tag $tag) + { + $this->tags[] = $tag; + + return $this; + } + + /** + * @return ArrayCollection + */ + public function getTags() + { + return $this->tags; + } /** * @inheritDoc */ -- cgit v1.2.3