Completed
Push — master ( e79cb7...4be90b )
by Laurent
04:11
created

User::isEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Entité User.
4
 *
5
 * PHP Version 5
6
 *
7
 * @author     Quétier Laurent <[email protected]>
8
 * @copyright  2014 Dev-Int GLSR
9
 * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
10
 *
11
 * @version    since 1.0.0
12
 *
13
 * @link       https://github.com/Dev-Int/glsr
14
 */
15
namespace AppBundle\Entity;
16
 
17
use FOS\UserBundle\Model\User as BaseUser;
18
use Doctrine\ORM\Mapping as ORM;
19
use Doctrine\Common\Collections\ArrayCollection;
20
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
21
 
22
/**
23
 * Entité User.
24
 *
25
 * @category   Entity
26
 *
27
 * @ORM\Entity(repositoryClass="AppBundle\Entity\UserRepository")
28
 * @ORM\Table(name="fos_user")
29
 * @UniqueEntity(fields="usernameCanonical", errorPath="username",
30
 *     message="fos_user.username.already_used", groups={"Default", "Registration", "Profile"})
31
 * @UniqueEntity(fields="emailCanonical", errorPath="email",
32
 *     message="fos_user.email.already_used", groups={"Default", "Registration", "Profile"})
33
 */
34
class User extends BaseUser
35
{
36
    /**
37
     * @ORM\Id
38
     * @ORM\Column(type="integer")
39
     * @ORM\GeneratedValue(strategy="AUTO")
40
     */
41
    protected $id;
42
 
43
    /**
44
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Group", inversedBy="users")
45
     * @ORM\JoinTable(name="fos_user_user_group",
46
     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
47
     *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
48
     * )
49
     */
50
    protected $groups;
51
 
52
    /**
53
     * @ORM\Column(type="integer", length=6, options={"default":0})
54
     */
55
    protected $loginCount = 0;
56
 
57
    /**
58
     * @var \DateTime
59
     *
60
     * @ORM\Column(type="datetime", nullable=true)
61
     */
62
    protected $firstLogin;
63
 
64
    public function __construct()
65
    {
66
        parent::__construct();
67
        $this->groups = new ArrayCollection();
68
    }
69
 
70
    /**
71
     * Set loginCount
72
     *
73
     * @param integer $loginCount
74
     *
75
     * @return User
76
     */
77
    public function setLoginCount($loginCount)
78
    {
79
        $this->loginCount = $loginCount;
80
        return $this;
81
    }
82
 
83
    /**
84
     * Get loginCount
85
     *
86
     * @return integer
87
     */
88
    public function getLoginCount()
89
    {
90
        return $this->loginCount;
91
    }
92
 
93
    /**
94
     * Set firstLogin
95
     *
96
     * @param \DateTime $firstLogin
97
     *
98
     * @return User
99
     */
100
    public function setFirstLogin($firstLogin)
101
    {
102
        $this->firstLogin = $firstLogin;
103
        return $this;
104
    }
105
 
106
    /**
107
     * Get firstLogin
108
     *
109
     * @return \DateTime
110
     */
111
    public function getFirstLogin()
112
    {
113
        return $this->firstLogin;
114
    }
115
 
116
    public function isEnabled()
117
    {
118
        return $this->enabled;
119
    }
120
 
121
    public function setSalt($salt)
122
    {
123
        $this->salt = $salt;
124
    }
125
 
126
    public function setPassword($password)
127
    {
128
        if ($password !== null) {
129
            $this->password = $password;
130
        }
131
        return $this;
132
    }
133
 
134
    public function setGroups(ArrayCollection $groups = null)
135
    {
136
        if ($groups !== null) {
137
            $this->groups = $groups;
138
        }
139
    }
140
 
141
    public function setRoles(array $roles = array())
142
    {
143
        $this->roles = array();
144
        foreach ($roles as $role) {
145
            $this->addRole($role);
146
        }
147
        return $this;
148
    }
149
 
150
    public function hasGroup($name = '')
151
    {
152
        return in_array($name, $this->getGroupNames());
153
    }
154
}
155