CoreUser::getDevices()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace KI\UserBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use JMS\Serializer\Annotation as JMS;
7
use Symfony\Component\Validator\Constraints as Assert;
8
9
/**
10
 * La classe User est divisée en deux (autre partie dans User)
11
 * Ici sont stockées les infos primaires dont on a besoin 100% du temps.
12
 * @JMS\ExclusionPolicy("all")
13
 */
14
class CoreUser extends \FOS\UserBundle\Model\User
15
{
16
    /**
17
     * @ORM\Id
18
     * @ORM\Column(type="integer")
19
     * @ORM\GeneratedValue(strategy="AUTO")
20
     */
21
    protected $id;
22
23
    /**
24
     * Image de profil
25
     * @ORM\OneToOne(targetEntity="KI\CoreBundle\Entity\Image", cascade={"persist", "remove"})
26
     * @Assert\Valid()
27
     */
28
    protected $image;
29
30
    /**
31
     * Prénom
32
     * @ORM\Column(name="firstName", type="string")
33
     * @JMS\Expose
34
     * @Assert\NotBlank()
35
     */
36
    protected $firstName;
37
38
    /**
39
     * Nom
40
     * @ORM\Column(name="lastName", type="string")
41
     * @JMS\Expose
42
     * @Assert\NotBlank()
43
     */
44
    protected $lastName;
45
46
    /**
47
     * Surnom/pseudo
48
     * @ORM\Column(name="nickname", type="string", nullable=true)
49
     */
50
    protected $nickname;
51
52
    /**
53
     * Groupes de permissions FOSUserBundle
54
     * @ORM\ManyToMany(targetEntity="KI\UserBundle\Entity\Group", inversedBy="users")
55
     * @ORM\JoinTable(name="fos_user_user_group",
56
     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
57
     *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
58
     * )
59
     */
60
    protected $groups;
61
62
    /**
63
     * Date de dernière connexion (timestamp)
64
     * @ORM\Column(name="lastConnect", type="integer", nullable=true)
65
     * @Assert\Type("integer")
66
     */
67
    protected $lastConnect;
68
69
    /**
70
     * Appareils mobiles enregistrés pour recevoir des notifications Push
71
     * @ORM\OneToMany(targetEntity="KI\UserBundle\Entity\Device", mappedBy="owner")
72
     */
73
    protected $devices;
74
75
    /**
76
     * Clubs auquels l'utilisateur n'est PAS abonné
77
     * @ORM\ManyToMany(targetEntity="KI\UserBundle\Entity\Club")
78
     */
79
    protected $clubsNotFollowed;
80
81
    /**
82
     * Tableau contenant les préférences utilisateurs. Les valeurs possibles des clés de ce tableau ainsi que
83
     * leur valeurs par défaut sont définies dans $preferencesArray
84
     * @ORM\Column(name="preferences", type="array", nullable=true)
85
     * @Assert\Type("array")
86
     */
87
    protected $preferences = [];
88
89
    /**
90
     * Token faible permettant de créer des urls personnalisées pour l'user
91
     * @ORM\Column(name="token", type="string", nullable=true)
92
     * @Assert\Type("string")
93
     */
94
    protected $token;
95
96
    /**
97
     * Méthode d'authentification
98
     * @ORM\Column(name="login_method", type="string")
99
     * @Assert\Type("string")
100
     */
101
    protected $loginMethod;
102
103
    protected $preferencesArray = [
104
        'notif_followed_event' => true,
105
        'notif_followed_news'  => true,
106
        'notif_news_perso'     => true,
107
        'notif_comments'       => true,
108
        'notif_shotgun_freed'  => true,
109
        'notif_ponthub'        => false,
110
        'notif_fixs'           => true,
111
        'notif_followed_annal' => true,
112
        //'notif_achievement'    => true,
113
        //'notif_next_level'     => true
114
    ];
115
116
    /**
117
     * @JMS\VirtualProperty()
118
     */
119
    public function imageUrl()
120
    {
121
        if ($this->image !== null) {
122
            if (file_exists($this->image->getAbsolutePath()))
123
                return $this->image->getWebPath();
124
        }
125
        return 'uploads/others/default-user.png';
126
    }
127
128
    /**
129
     * @JMS\VirtualProperty()
130
     */
131
    public function nick()
132
    {
133
        return $this->nickname !== null ? $this->nickname : $this->getName();
134
    }
135
136
    // On définit des alias pour le slug
137
    public function getSlug() { return $this->getUsername(); }
138
    public function setSlug($slug) { return $this->setUsername($slug); }
139
    public function getName() { return $this->getFirstName().' '.$this->getLastName(); }
140
141
142
143
144
    //===== GENERATED AUTOMATICALLY =====//
145
146
    /**
147
     * Constructor
148
     */
149
    public function __construct()
150
    {
151
        $this->devices = new \Doctrine\Common\Collections\ArrayCollection();
152
        $this->clubsNotFollowed = new \Doctrine\Common\Collections\ArrayCollection();
153
        parent::__construct();
154
    }
155
156
    /**
157
     * Get id
158
     *
159
     * @return integer
160
     */
161
    public function getId()
162
    {
163
        return $this->id;
164
    }
165
166
    /**
167
     * Set firstName
168
     *
169
     * @param string $firstName
170
     * @return User
171
     */
172
    public function setFirstName($firstName)
173
    {
174
        $this->firstName = $firstName;
175
176
        return $this;
177
    }
178
179
    /**
180
     * Get firstName
181
     *
182
     * @return string
183
     */
184
    public function getFirstName()
185
    {
186
        return $this->firstName;
187
    }
188
189
    /**
190
     * Set lastName
191
     *
192
     * @param string $lastName
193
     * @return User
194
     */
195
    public function setLastName($lastName)
196
    {
197
        $this->lastName = $lastName;
198
199
        return $this;
200
    }
201
202
    /**
203
     * Get lastName
204
     *
205
     * @return string
206
     */
207
    public function getLastName()
208
    {
209
        return $this->lastName;
210
    }
211
212
    /**
213
     * Set nickname
214
     *
215
     * @param string $nickname
216
     * @return User
217
     */
218
    public function setNickname($nickname)
219
    {
220
        $this->nickname = $nickname;
221
222
        return $this;
223
    }
224
225
    /**
226
     * Add group
227
     *
228
     * @param \KI\UserBundle\Entity\User $group
229
     * @return Comment
230
     */
231
    public function addGroupUser(\KI\UserBundle\Entity\Group $group)
232
    {
233
        $this->addGroup($group);
234
        $group->addUser($this);
0 ignored issues
show
Compatibility introduced by
$this of type object<KI\UserBundle\Entity\CoreUser> is not a sub-type of object<KI\UserBundle\Entity\User>. It seems like you assume a child class of the class KI\UserBundle\Entity\CoreUser to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
235
236
        return $this;
237
    }
238
239
    /**
240
     * Remove group
241
     *
242
     * @param \KI\UserBundle\Entity\User $group
243
     */
244
    public function removeGroupUser(\KI\UserBundle\Entity\Group $group)
245
    {
246
        $this->removeGroup($group);
247
        $group->removeUser($this);
0 ignored issues
show
Compatibility introduced by
$this of type object<KI\UserBundle\Entity\CoreUser> is not a sub-type of object<KI\UserBundle\Entity\User>. It seems like you assume a child class of the class KI\UserBundle\Entity\CoreUser to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
248
    }
249
250
    /**
251
     * Get lastConnect
252
     *
253
     * @return integer
254
     */
255
    public function getLastConnect()
256
    {
257
        return $this->lastConnect;
258
    }
259
260
    /**
261
     * Set lastConnect
262
     *
263
     * @param integer $lastConnect
264
     * @return User
265
     */
266
    public function setLastConnect($lastConnect)
267
    {
268
        $this->lastConnect = $lastConnect;
269
270
        return $this;
271
    }
272
273
    /**
274
     * Get nickname
275
     *
276
     * @return string
277
     */
278
    public function getNickname()
279
    {
280
        return $this->nickname;
281
    }
282
283
    /**
284
     * Set image
285
     *
286
     * @param \KI\CoreBundle\Entity\Image $image
287
     * @return User
288
     */
289
    public function setImage(\KI\CoreBundle\Entity\Image $image = null)
290
    {
291
        $this->image = $image;
292
293
        return $this;
294
    }
295
296
    /**
297
     * Get image
298
     *
299
     * @return \KI\CoreBundle\Entity\Image
300
     */
301
    public function getImage()
302
    {
303
        return $this->image;
304
    }
305
306
    /**
307
     * Add devices
308
     *
309
     * @param \KI\UserBundle\Entity\Device $devices
310
     * @return User
311
     */
312
    public function addDevice(\KI\UserBundle\Entity\Device $devices)
313
    {
314
        $this->devices[] = $devices;
315
316
        return $this;
317
    }
318
319
    /**
320
     * Remove devices
321
     *
322
     * @param \KI\UserBundle\Entity\Device $devices
323
     */
324
    public function removeDevice(\KI\UserBundle\Entity\Device $devices)
325
    {
326
        $this->devices->removeElement($devices);
327
    }
328
329
    /**
330
     * Get devices
331
     *
332
     * @return \Doctrine\Common\Collections\Collection
333
     */
334
    public function getDevices()
335
    {
336
        return $this->devices;
337
    }
338
339
    /**
340
     * Add Club Not Followed
341
     *
342
     * @param \KI\UserBundle\Entity\Club $club
343
     * @return User
344
     */
345
    public function addClubNotFollowed(\KI\UserBundle\Entity\Club $club)
346
    {
347
        $this->clubsNotFollowed[] = $club;
348
349
        return $this;
350
    }
351
352
    /**
353
     * Remove Club Not Followed
354
     *
355
     * @param \KI\UserBundle\Entity\Club $club
356
     */
357
    public function removeClubNotFollowed(\KI\UserBundle\Entity\Club $club)
358
    {
359
        $this->clubsNotFollowed->removeElement($club);
360
    }
361
362
    /**
363
     * Get Clubs Not Followed
364
     *
365
     * @return \Doctrine\Common\Collections\Collection
366
     */
367
    public function getClubsNotFollowed()
368
    {
369
        return $this->clubsNotFollowed;
370
    }
371
372
    /**
373
     * Add Preference
374
     *
375
     * @param string $key
376
     * @param string $value
377
     * @return bool
378
     */
379 View Code Duplication
    public function addPreference($key, $value)
380
    {
381
        if (array_key_exists($key, $this->preferencesArray)) {
382
            $this->preferences[$key] = $value;
383
            return true;
384
        }
385
386
        return false;
387
    }
388
389
    /**
390
     * Remove Preference
391
     *
392
     * @param string $key
393
     * @return bool
394
     */
395 View Code Duplication
    public function removePreference($key)
396
    {
397
        if (array_key_exists($key, $this->preferencesArray)) {
398
            unset($this->preferences[$key]);
399
            return true;
400
        }
401
        return false;
402
    }
403
404
    /**
405
     * Get Preferences Array
406
     *
407
     * @return array
408
     */
409
    public function getPreferences()
410
    {
411
        return array_merge($this->preferencesArray, $this->preferences);
412
    }
413
414
    /**
415
     * Set token
416
     *
417
     * @param string $token
418
     * @return User
419
     */
420
    public function setToken($token)
421
    {
422
        $this->token = $token;
423
424
        return $this;
425
    }
426
427
    /**
428
     * Get token
429
     *
430
     * @return string
431
     */
432
    public function getToken()
433
    {
434
        return $this->token;
435
    }
436
437
    /**
438
     * @return string
439
     */
440
    public function getLoginMethod()
441
    {
442
        return $this->loginMethod;
443
    }
444
445
    /**
446
     * @param string $loginMethod
447
     * @return User
448
     */
449
    public function setLoginMethod($loginMethod)
450
    {
451
        $this->loginMethod = $loginMethod;
452
453
        return $this;
454
    }
455
456
457
}
458