diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-11-05 09:08:18 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2017-06-23 09:23:49 +0200 |
commit | 56c81a2f433eaba98f8cf0bfdd3672bc517ae266 (patch) | |
tree | 804d9f8bc459ac6d67d41d75e56774c272f22216 /src | |
parent | 36f30fa31e0d2373f5c39851ea9138493fbde341 (diff) | |
download | wallabag-56c81a2f433eaba98f8cf0bfdd3672bc517ae266.tar.gz wallabag-56c81a2f433eaba98f8cf0bfdd3672bc517ae266.tar.zst wallabag-56c81a2f433eaba98f8cf0bfdd3672bc517ae266.zip |
First draft to manage relation between User and Group
Diffstat (limited to 'src')
-rw-r--r-- | src/Wallabag/GroupBundle/Entity/Group.php | 37 | ||||
-rw-r--r-- | src/Wallabag/GroupBundle/Form/GroupType.php | 7 | ||||
-rw-r--r-- | src/Wallabag/GroupBundle/Resources/views/Manage/edit.html.twig | 8 | ||||
-rw-r--r-- | src/Wallabag/UserBundle/Entity/User.php | 12 |
4 files changed, 63 insertions, 1 deletions
diff --git a/src/Wallabag/GroupBundle/Entity/Group.php b/src/Wallabag/GroupBundle/Entity/Group.php index 57dc16d1..e889f74e 100644 --- a/src/Wallabag/GroupBundle/Entity/Group.php +++ b/src/Wallabag/GroupBundle/Entity/Group.php | |||
@@ -4,6 +4,7 @@ namespace Wallabag\GroupBundle\Entity; | |||
4 | 4 | ||
5 | use FOS\UserBundle\Model\Group as BaseGroup; | 5 | use FOS\UserBundle\Model\Group as BaseGroup; |
6 | use Doctrine\ORM\Mapping as ORM; | 6 | use Doctrine\ORM\Mapping as ORM; |
7 | use Wallabag\UserBundle\Entity\User; | ||
7 | 8 | ||
8 | /** | 9 | /** |
9 | * @ORM\Entity | 10 | * @ORM\Entity |
@@ -17,4 +18,40 @@ class Group extends BaseGroup | |||
17 | * @ORM\GeneratedValue(strategy="AUTO") | 18 | * @ORM\GeneratedValue(strategy="AUTO") |
18 | */ | 19 | */ |
19 | protected $id; | 20 | protected $id; |
21 | |||
22 | /** | ||
23 | * @ORM\ManyToMany(targetEntity="Wallabag\UserBundle\Entity\User", mappedBy="groups", cascade={"persist"}) | ||
24 | */ | ||
25 | protected $users; | ||
26 | |||
27 | public function getUsers() | ||
28 | { | ||
29 | return $this->users ?: $this->users = new ArrayCollection(); | ||
30 | } | ||
31 | |||
32 | public function addUser(User $user) | ||
33 | { | ||
34 | if (!$this->getUsers()->contains($user)) { | ||
35 | $this->getUsers()->add($user); | ||
36 | } | ||
37 | |||
38 | return $this; | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * {@inheritdoc} | ||
43 | */ | ||
44 | public function removeUser(User $user) | ||
45 | { | ||
46 | if ($this->getUsers()->contains($user)) { | ||
47 | $this->getUsers()->removeElement($user); | ||
48 | } | ||
49 | |||
50 | return $this; | ||
51 | } | ||
52 | |||
53 | public function __toString() | ||
54 | { | ||
55 | return $this->getName(); | ||
56 | } | ||
20 | } | 57 | } |
diff --git a/src/Wallabag/GroupBundle/Form/GroupType.php b/src/Wallabag/GroupBundle/Form/GroupType.php index c2ad764b..749c15e9 100644 --- a/src/Wallabag/GroupBundle/Form/GroupType.php +++ b/src/Wallabag/GroupBundle/Form/GroupType.php | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\GroupBundle\Form; | 3 | namespace Wallabag\GroupBundle\Form; |
4 | 4 | ||
5 | use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||
5 | use Symfony\Component\Form\AbstractType; | 6 | use Symfony\Component\Form\AbstractType; |
6 | use Symfony\Component\Form\FormBuilderInterface; | 7 | use Symfony\Component\Form\FormBuilderInterface; |
7 | use Symfony\Component\OptionsResolver\OptionsResolver; | 8 | use Symfony\Component\OptionsResolver\OptionsResolver; |
@@ -21,6 +22,12 @@ class GroupType extends AbstractType | |||
21 | 'required' => false, | 22 | 'required' => false, |
22 | 'label' => 'group.form.name_label', | 23 | 'label' => 'group.form.name_label', |
23 | ]) | 24 | ]) |
25 | ->add('users', EntityType::class, array( | ||
26 | 'class' => 'WallabagUserBundle:User', | ||
27 | 'choice_label' => 'username', | ||
28 | 'multiple' => true, | ||
29 | 'expanded' => true, | ||
30 | )) | ||
24 | ->add('save', SubmitType::class, [ | 31 | ->add('save', SubmitType::class, [ |
25 | 'label' => 'group.form.save', | 32 | 'label' => 'group.form.save', |
26 | ]) | 33 | ]) |
diff --git a/src/Wallabag/GroupBundle/Resources/views/Manage/edit.html.twig b/src/Wallabag/GroupBundle/Resources/views/Manage/edit.html.twig index 7de68c35..791a7a18 100644 --- a/src/Wallabag/GroupBundle/Resources/views/Manage/edit.html.twig +++ b/src/Wallabag/GroupBundle/Resources/views/Manage/edit.html.twig | |||
@@ -23,6 +23,14 @@ | |||
23 | </div> | 23 | </div> |
24 | </div> | 24 | </div> |
25 | 25 | ||
26 | <div class="row"> | ||
27 | <div class="input-field col s12"> | ||
28 | {{ form_label(edit_form.users) }} | ||
29 | {{ form_errors(edit_form.users) }} | ||
30 | {{ form_widget(edit_form.users) }} | ||
31 | </div> | ||
32 | </div> | ||
33 | |||
26 | <br/> | 34 | <br/> |
27 | 35 | ||
28 | {{ form_widget(edit_form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} | 36 | {{ form_widget(edit_form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} |
diff --git a/src/Wallabag/UserBundle/Entity/User.php b/src/Wallabag/UserBundle/Entity/User.php index 7da0d1d5..dc10f1c4 100644 --- a/src/Wallabag/UserBundle/Entity/User.php +++ b/src/Wallabag/UserBundle/Entity/User.php | |||
@@ -98,7 +98,7 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
98 | private $authCode; | 98 | private $authCode; |
99 | 99 | ||
100 | /** | 100 | /** |
101 | * @ORM\ManyToMany(targetEntity="Wallabag\GroupBundle\Entity\Group") | 101 | * @ORM\ManyToMany(targetEntity="Wallabag\GroupBundle\Entity\Group", inversedBy="users") |
102 | * @ORM\JoinTable(name="user_group", | 102 | * @ORM\JoinTable(name="user_group", |
103 | * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, | 103 | * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, |
104 | * inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")} | 104 | * inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")} |
@@ -319,5 +319,15 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf | |||
319 | if (!empty($this->clients)) { | 319 | if (!empty($this->clients)) { |
320 | return $this->clients->first(); | 320 | return $this->clients->first(); |
321 | } | 321 | } |
322 | |||
323 | } | ||
324 | |||
325 | /** | ||
326 | * @param string $name | ||
327 | * @return bool | ||
328 | */ | ||
329 | public function hasGroup($name = '') | ||
330 | { | ||
331 | return in_array($name, $this->getGroupNames()); | ||
322 | } | 332 | } |
323 | } | 333 | } |