Passed
Push — master ( ad5dd8...3078de )
by Julito
08:55
created

Usergroup::getDefaultIllustration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Entity;
6
7
use ApiPlatform\Core\Annotation\ApiResource;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\ORM\Mapping as ORM;
10
use Gedmo\Timestampable\Traits\TimestampableEntity;
11
use Symfony\Component\Validator\Constraints as Assert;
12
13
/**
14
 * @ApiResource(
15
 *     attributes={"security"="is_granted('ROLE_ADMIN')"},
16
 *     normalizationContext={"groups"={"usergroup:read"}}
17
 * )
18
 *
19
 * @ORM\Table(name="usergroup")
20
 * @ORM\Entity
21
 */
22
class Usergroup extends AbstractResource implements ResourceInterface, ResourceIllustrationInterface
23
{
24
    use TimestampableEntity;
25
26
    /**
27
     * @var int
28
     *
29
     * @ORM\Column(name="id", type="integer", nullable=false)
30
     * @ORM\Id
31
     * @ORM\GeneratedValue
32
     */
33
    protected $id;
34
35
    /**
36
     * @Assert\NotBlank()
37
     *
38
     * @ORM\Column(name="name", type="string", length=255, nullable=false, unique=false)
39
     */
40
    protected string $name;
41
42
    /**
43
     * @ORM\Column(name="description", type="text", nullable=true)
44
     */
45
    protected ?string $description;
46
47
    /**
48
     * @var int
49
     *
50
     * @ORM\Column(name="group_type", type="integer", nullable=false)
51
     */
52
    protected $groupType;
53
54
    /**
55
     * @var string
56
     *
57
     * @ORM\Column(name="picture", type="string", length=255, nullable=true)
58
     */
59
    protected ?string $picture;
60
61
    /**
62
     * @ORM\Column(name="url", type="string", length=255, nullable=true)
63
     */
64
    protected ?string $url;
65
66
    /**
67
     * @var string
68
     *
69
     * @ORM\Column(name="visibility", type="string", length=255, nullable=false)
70
     */
71
    protected $visibility;
72
73
    /**
74
     * @var string
75
     *
76
     * @ORM\Column(name="author_id", type="integer", nullable=true)
77
     */
78
    protected $authorId;
79
80
    /**
81
     * @var int
82
     *
83
     * @ORM\Column(name="allow_members_leave_group", type="integer")
84
     */
85
    protected $allowMembersToLeaveGroup;
86
87
    /**
88
     * @var UsergroupRelUser[]
89
     * @ORM\OneToMany(targetEntity="UsergroupRelUser", mappedBy="usergroup", cascade={"persist"}, orphanRemoval=true)
90
     */
91
    protected $users;
92
93
    public function __construct()
94
    {
95
        $this->users = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type Chamilo\CoreBundle\Entity\UsergroupRelUser[] of property $users.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
96
    }
97
98
    public function __toString(): string
99
    {
100
        return $this->getName();
101
    }
102
103
    /**
104
     * @return UsergroupRelUser[]
105
     */
106
    public function getUsers()
107
    {
108
        return $this->users;
109
    }
110
111
    /**
112
     * @param $users
113
     */
114
    public function setUsers($users)
115
    {
116
        $this->users = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type Chamilo\CoreBundle\Entity\UsergroupRelUser[] of property $users.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
117
118
        foreach ($users as $user) {
119
            $this->addUsers($user);
120
        }
121
    }
122
123
    public function addUsers(UsergroupRelUser $user)
124
    {
125
        $user->setUsergroup($this);
126
        $this->users[] = $user;
127
    }
128
129
    /**
130
     * Remove $user.
131
     */
132
    public function removeUsers(UsergroupRelUser $user)
133
    {
134
        foreach ($this->users as $key => $value) {
135
            if ($value->getId() == $user->getId()) {
136
                unset($this->users[$key]);
137
            }
138
        }
139
    }
140
141
    /**
142
     * Get id.
143
     *
144
     * @return int
145
     */
146
    public function getId()
147
    {
148
        return $this->id;
149
    }
150
151
    /**
152
     * Set name.
153
     */
154
    public function setName(string $name): self
155
    {
156
        $this->name = $name;
157
158
        return $this;
159
    }
160
161
    /**
162
     * Get name.
163
     *
164
     * @return string
165
     */
166
    public function getName()
167
    {
168
        return $this->name;
169
    }
170
171
    /**
172
     * Set description.
173
     *
174
     * @param string $description
175
     */
176
    public function setDescription($description): self
177
    {
178
        $this->description = $description;
179
180
        return $this;
181
    }
182
183
    /**
184
     * Get description.
185
     *
186
     * @return string
187
     */
188
    public function getDescription()
189
    {
190
        return $this->description;
191
    }
192
193
    /**
194
     * @return int
195
     */
196
    public function getGroupType()
197
    {
198
        return $this->groupType;
199
    }
200
201
    /**
202
     * @param int $groupType
203
     *
204
     * @return Usergroup
205
     */
206
    public function setGroupType($groupType)
207
    {
208
        $this->groupType = $groupType;
209
210
        return $this;
211
    }
212
213
    public function getPicture(): ?string
214
    {
215
        return $this->picture;
216
    }
217
218
    public function getDefaultIllustration($size): string
219
    {
220
        $size = empty($size) ? 32 : (int) $size;
221
222
        return "/img/icons/$size/group_na.png";
223
    }
224
225
    public function getResourceIdentifier(): int
226
    {
227
        return $this->getId();
228
    }
229
230
    public function getResourceName(): string
231
    {
232
        return $this->getName();
233
    }
234
235
    public function setResourceName(string $name): self
236
    {
237
        return $this->setName($name);
238
    }
239
}
240