diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-02-06 15:18:54 +0100 |
---|---|---|
committer | Jeremy <jeremy.benoist@gmail.com> | 2015-02-08 23:13:40 +0100 |
commit | 5f09650eef7bea52b7c54c074c0f873f96e53c86 (patch) | |
tree | 1445f0f07ee0cc04b57e0228f3fded0bdfcf3c94 /src/Wallabag | |
parent | 8af35ad932177e0363412a868afc128b406e3322 (diff) | |
download | wallabag-5f09650eef7bea52b7c54c074c0f873f96e53c86.tar.gz wallabag-5f09650eef7bea52b7c54c074c0f873f96e53c86.tar.zst wallabag-5f09650eef7bea52b7c54c074c0f873f96e53c86.zip |
add a real relation between user and entry
Diffstat (limited to 'src/Wallabag')
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Entry.php | 41 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/User.php | 29 |
2 files changed, 44 insertions, 26 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index a00762ca..937213b4 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -84,13 +84,6 @@ class Entry | |||
84 | /** | 84 | /** |
85 | * @var string | 85 | * @var string |
86 | * | 86 | * |
87 | * @ORM\Column(name="user_id", type="decimal", precision=10, scale=0, nullable=true) | ||
88 | */ | ||
89 | private $userId; | ||
90 | |||
91 | /** | ||
92 | * @var string | ||
93 | * | ||
94 | * @ORM\Column(name="comments", type="text", nullable=true) | 87 | * @ORM\Column(name="comments", type="text", nullable=true) |
95 | */ | 88 | */ |
96 | private $comments; | 89 | private $comments; |
@@ -124,6 +117,19 @@ class Entry | |||
124 | private $isPublic; | 117 | private $isPublic; |
125 | 118 | ||
126 | /** | 119 | /** |
120 | * @ORM\ManyToOne(targetEntity="User", inversedBy="entries") | ||
121 | */ | ||
122 | private $user; | ||
123 | |||
124 | /* | ||
125 | * @param User $user | ||
126 | */ | ||
127 | public function __construct(User $user) | ||
128 | { | ||
129 | $this->user = $user; | ||
130 | } | ||
131 | |||
132 | /** | ||
127 | * Get id | 133 | * Get id |
128 | * | 134 | * |
129 | * @return integer | 135 | * @return integer |
@@ -263,26 +269,11 @@ class Entry | |||
263 | } | 269 | } |
264 | 270 | ||
265 | /** | 271 | /** |
266 | * Set userId | 272 | * @return User |
267 | * | ||
268 | * @param string $userId | ||
269 | * @return Entry | ||
270 | */ | ||
271 | public function setUserId($userId) | ||
272 | { | ||
273 | $this->userId = $userId; | ||
274 | |||
275 | return $this; | ||
276 | } | ||
277 | |||
278 | /** | ||
279 | * Get userId | ||
280 | * | ||
281 | * @return string | ||
282 | */ | 273 | */ |
283 | public function getUserId() | 274 | public function getUser() |
284 | { | 275 | { |
285 | return $this->userId; | 276 | return $this->user; |
286 | } | 277 | } |
287 | 278 | ||
288 | /** | 279 | /** |
diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php index 6abfd3ae..cfbd57f8 100644 --- a/src/Wallabag/CoreBundle/Entity/User.php +++ b/src/Wallabag/CoreBundle/Entity/User.php | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Entity; | 3 | namespace Wallabag\CoreBundle\Entity; |
4 | 4 | ||
5 | use Doctrine\Common\Collections\ArrayCollection; | ||
5 | use Doctrine\ORM\Mapping as ORM; | 6 | use Doctrine\ORM\Mapping as ORM; |
6 | use Symfony\Component\Security\Core\User\UserInterface; | 7 | use Symfony\Component\Security\Core\User\UserInterface; |
7 | use Symfony\Component\Security\Core\User\AdvancedUserInterface; | 8 | use Symfony\Component\Security\Core\User\AdvancedUserInterface; |
@@ -78,10 +79,16 @@ class User implements AdvancedUserInterface, \Serializable | |||
78 | */ | 79 | */ |
79 | private $updatedAt; | 80 | private $updatedAt; |
80 | 81 | ||
82 | /** | ||
83 | * @ORM\OneToMany(targetEntity="Entry", mappedBy="user", cascade={"remove"}) | ||
84 | */ | ||
85 | private $entries; | ||
86 | |||
81 | public function __construct() | 87 | public function __construct() |
82 | { | 88 | { |
83 | $this->isActive = true; | 89 | $this->isActive = true; |
84 | $this->salt = md5(uniqid(null, true)); | 90 | $this->salt = md5(uniqid(null, true)); |
91 | $this->entries = new ArrayCollection(); | ||
85 | } | 92 | } |
86 | 93 | ||
87 | /** | 94 | /** |
@@ -232,6 +239,26 @@ class User implements AdvancedUserInterface, \Serializable | |||
232 | } | 239 | } |
233 | 240 | ||
234 | /** | 241 | /** |
242 | * @param Entry $entry | ||
243 | * | ||
244 | * @return User | ||
245 | */ | ||
246 | public function addEntry(Entry $entry) | ||
247 | { | ||
248 | $this->entries[] = $entry; | ||
249 | |||
250 | return $this; | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * @return ArrayCollection<Entry> | ||
255 | */ | ||
256 | public function getEntries() | ||
257 | { | ||
258 | return $this->entries; | ||
259 | } | ||
260 | |||
261 | /** | ||
235 | * @inheritDoc | 262 | * @inheritDoc |
236 | */ | 263 | */ |
237 | public function eraseCredentials() | 264 | public function eraseCredentials() |