3 namespace Wallabag\GroupBundle\Entity
;
5 use Doctrine\Common\Collections\ArrayCollection
;
6 use FOS\UserBundle\Model\Group
as BaseGroup
;
7 use Doctrine\ORM\Mapping
as ORM
;
8 use Wallabag\UserBundle\Entity\User
;
11 * @ORM\Entity(repositoryClass="Wallabag\GroupBundle\Repository\GroupRepository")
12 * @ORM\Table(name="`group`")
14 class Group
extends BaseGroup
21 /** User can only preview presentations */
22 const ROLE_READ_ONLY
= 1;
24 /** User can create new presentations */
27 /** User can manage all group presentations */
28 const ROLE_MANAGE_ENTRIES
= 3;
30 /** User can manage users in the group */
31 const ROLE_MANAGE_USERS
= 5;
33 /** User can rename and delete the group */
34 const ROLE_ADMIN
= 10;
40 /** Any user can join the group */
41 const ACCESS_OPEN
= 1;
43 /** An user needs to request to join the group */
44 const ACCESS_REQUEST
= 2;
46 /** An user need the password to access the group */
47 const ACCESS_PASSWORD
= 3;
49 /** An user needs to be invited to join the group */
50 const ACCESS_INVITATION_ONLY
= 4;
52 /** An user needs to be invited to join the group, and the group is not publicly listed */
53 const ACCESS_HIDDEN
= 10;
57 * @ORM\Column(type="integer")
58 * @ORM\GeneratedValue(strategy="AUTO")
63 * @ORM\Column(type="integer", options={"default" : 1})
65 protected $acceptSystem;
68 * @ORM\Column(type="integer", options={"default" : 2})
70 protected $defaultRole;
73 * @ORM\Column(type="string", nullable=true)
76 protected $plainPassword;
79 * @ORM\ManyToMany(targetEntity="Wallabag\CoreBundle\Entity\Entry", mappedBy="groupShares", cascade={"persist"})
84 * @ORM\OneToMany(targetEntity="UserGroup", mappedBy="group", cascade={"persist"})
88 public function __construct($name = '', array $roles = [])
90 parent
::__construct($name, $roles);
91 $this->defaultRole
= self
::ROLE_READ_ONLY
;
92 $this->acceptSystem
= self
::ACCESS_REQUEST
;
96 * @return ArrayCollection
98 public function getUsers()
100 $userObj = new ArrayCollection();
101 foreach ($this->users
as $userGroup) {
102 /** @var UserGroup $userGroup */
103 $userObj->add($userGroup->getUser());
111 public function getDefaultRole()
113 return $this->defaultRole
;
119 public function getAcceptSystem()
121 return $this->acceptSystem
;
125 * @param int $acceptSystem
127 public function setAcceptSystem($acceptSystem)
129 $this->acceptSystem
= $acceptSystem;
135 public function getPassword()
137 return $this->password
?: '';
141 * @param string $password
143 public function setPassword($password)
145 $this->password
= $password;
151 public function getPlainPassword()
153 return $this->plainPassword
?: '';
157 * @param string $plainPassword
159 public function setPlainPassword($plainPassword)
161 $this->plainPassword
= $plainPassword;
165 * @param int $defaultRole
167 public function setDefaultRole($defaultRole)
169 $this->defaultRole
= $defaultRole;
172 public function __toString()
177 public function getRequests()
179 $requests = new ArrayCollection();
180 foreach ($this->users
as $user) /** @var UserGroup $user */
182 if (!$user->isAccepted()) {
183 $requests->add($user->getUser());
189 public function getInvited()
191 $invited = new ArrayCollection();
192 foreach ($this->users
as $userGroup) /** @var UserGroup $userGroup */
194 if ($userGroup->getInvitation()) {
195 $invited->add($userGroup);