Group::removeUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php 
2
namespace Vivait\AuthBundle\Entity;
3
4
use Symfony\Component\Security\Core\Role\RoleInterface;
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
8
/**
9
 * @ORM\Table(name="Groups")
10
 * @ORM\Entity()
11
 */
12
class Group implements RoleInterface, \Serializable
13
{
14
    /**
15
		 * @ORM\Column(name="id", type="guid")
16
		 * @ORM\Id
17
		 * @ORM\GeneratedValue(strategy="UUID")
18
     */
19
    private $id;
20
21
    /**
22
     * @ORM\Column(name="name", type="string", length=30)
23
     */
24
    private $name;
25
26
    /**
27
     * @ORM\Column(name="role", type="string", length=20, unique=true)
28
     */
29
    private $role;
30
31
    /**
32
     * @ORM\ManyToMany(targetEntity="Vivait\AuthBundle\Entity\User", mappedBy="groups")
33
     */
34
    private $users;
35
36
		/**
37
		 * @ORM\ManyToMany(targetEntity="Vivait\AuthBundle\Entity\Tenant", mappedBy="groups")
38
		 */
39
		private $tenants;
40
41
		/**
42
		 * @ORM\Column(name="tenant_group", type="boolean")
43
		 */
44
		private $tenant_group;
45
46
		public function __construct() {
47
			$this->users   = new ArrayCollection();
48
			$this->tenants = new ArrayCollection();
49
		}
50
51
    // ... getters and setters for each property
52
53
    /**
54
     * @see RoleInterface
55
     */
56
    public function getRole()
57
    {
58
        return $this->role;
59
    }
60
61
    /**
62
     * Get id
63
     *
64
     * @return integer 
65
     */
66
    public function getId()
67
    {
68
        return $this->id;
69
    }
70
71
    /**
72
     * Set name
73
     *
74
     * @param string $name
75
     * @return Group
76
     */
77
    public function setName($name)
78
    {
79
        $this->name = $name;
80
    
81
        return $this;
82
    }
83
84
    /**
85
     * Get name
86
     *
87
     * @return string 
88
     */
89
    public function getName()
90
    {
91
        return $this->name;
92
    }
93
94
    /**
95
     * Set role
96
     *
97
     * @param string $role
98
     * @return Group
99
     */
100
    public function setRole($role)
101
    {
102
        $this->role = $role;
103
    
104
        return $this;
105
    }
106
107
    /**
108
     * Add users
109
     *
110
     * @param User $users
111
     * @return Group
112
     */
113
    public function addUser(User $users)
114
    {
115
        $this->users[] = $users;
116
		$users->addGroup($this);														#REQUIRED WITH BY_REFERENCE IN CONTROLLER FORM TO UPDATE ON INVERSE SIDE
117
        return $this;
118
    }
119
120
    /**
121
     * Remove users
122
     *
123
     * @param User $users
124
     */
125
    public function removeUser(User $users)
126
    {
127
        $this->users->removeElement($users);
128
			$users->removeGroup($this);														#REQUIRED WITH BY_REFERENCE IN CONTROLLER FORM TO UPDATE ON INVERSE SIDE
129
    }
130
131
    /**
132
     * Get users
133
     *
134
     * @return ArrayCollection|User[]
135
     */
136
    public function getUsers()
137
    {
138
        return $this->users;
139
    }
140
141
    /**
142
     * @see \Serializable::serialize()
143
     */
144
    public function serialize() {
145
        return serialize(array(
146
            $this->id,
147
            $this->name,
148
            $this->role
149
        ));
150
    }
151
152
    /**
153
     * @see \Serializable::unserialize()
154
     */
155
    public function unserialize($serialized) {
156
        list (
157
            $this->id,
158
            $this->name,
159
            $this->role
160
            ) = unserialize($serialized);
161
    }
162
    
163
    /**
164
		 * Set tenant_group
165
		 * @param boolean $tenantGroup
166
		 * @return Group
167
		 */
168
		public function setTenantGroup($tenantGroup) {
169
			$this->tenant_group = $tenantGroup;
170
171
			return $this;
172
		}
173
174
		/**
175
		 * Get tenant_group
176
		 * @return boolean
177
		 */
178
		public function getTenantGroup() {
179
			return $this->tenant_group;
180
		}
181
182
		/**
183
		 * Add tenants
184
		 * @param Tenant $tenants
185
		 * @return Group
186
		 */
187
		public function addTenant(Tenant $tenants) {
188
			$this->tenants[] = $tenants;
189
            $tenants->addGroup($this);
190
			return $this;
191
		}
192
193
		/**
194
		 * Remove tenants
195
		 * @param Tenant $tenants
196
		 */
197
		public function removeTenant(Tenant $tenants) {
198
			$this->tenants->removeElement($tenants);
199
			$tenants->removeGroup($this);
200
		}
201
202
		/**
203
		 * Get tenants
204
		 * @return Tenant[]|ArrayCollection
205
		 */
206
		public function getTenants() {
207
			return $this->tenants;
208
		}
209
}