Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Hybrid\UserBundle\Entity;
- use Symfony\Component\Security\Core\User\UserInterface;
- use Doctrine\Common\Collections\ArrayCollection;
- use Hybrid\UserBundle\Entity\Role;
- /**
- * User entity. Implements UserInterface.
- *
- * ... Personal details removed ...
- */
- class User implements UserInterface
- {
- /**
- * @var integer $id
- */
- private $id;
- /**
- * @var ArrayCollection
- */
- private $roles;
- /**
- * @var string $email
- */
- private $email;
- /**
- * @var string $password
- */
- private $password;
- /*
- * @var string $password
- */
- private $plainpw;
- /**
- * @var string $salt
- */
- private $salt;
- /**
- * @var date $dob
- */
- private $dob;
- /**
- * @var string $firstName
- */
- private $firstName;
- /**
- * @var string $lastName
- */
- private $lastName;
- /**
- * @var string $phoneNumber
- */
- private $phoneNumber;
- /**
- * @var datetime $createdAt
- */
- private $createdAt;
- /**
- * @var datetime $lastLogin
- */
- private $lastLogin;
- public function __construct()
- {
- $this->setCreatedAt(new \DateTime());
- $this->roles = new ArrayCollection();
- }
- /**
- * Get the user ID
- *
- * @return integer $id
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Add new role for user
- *
- * @param Role $roles
- */
- public function addRole(Role $role)
- {
- $this->roles->add($role);
- }
- /**
- * Get user roles
- *
- * The $collection-parameter is used to detect if plain array or collection
- * is returned. Symfony2 Security system needs an array, so when false is
- * passed (the default), plain array is returned.
- *
- * @param boolean $collection
- * @return array $roles
- */
- public function getRoles($collection = false)
- {
- if(!$collection === false) {
- return $this->roles;
- }
- return $this->roles->toArray();
- }
- /**
- * Set the user email address
- *
- * @param string $email
- */
- public function setEmail($email)
- {
- $this->email = (string) $email;
- }
- /**
- * Get the user email address
- *
- * @return string $email
- */
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * Set the user password
- *
- * @param string $password
- */
- public function setPassword($password)
- {
- $this->password = (string) $password;
- }
- /**
- * Get the user password
- *
- * @return string $password
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * Set plain password
- *
- * Plain password is used when changing password and when creating new user.
- * The plain password is sent to the user by email provided.
- *
- * @param string $plain
- */
- public function setPlainpw($plain)
- {
- $this->plainpw = $plain;
- }
- /**
- * Get plain password
- *
- * @return string
- */
- public function getPlainpw()
- {
- return $this->plainpw;
- }
- /**
- * Set salt
- *
- * @param string $salt
- */
- public function setSalt($salt)
- {
- $this->salt = $salt;
- }
- /**
- * Get salt
- *
- * @return string $salt
- */
- public function getSalt()
- {
- return $this->salt;
- }
- /**
- * Set dob (date of birth)
- *
- * @param date $dob
- */
- public function setDob($dob)
- {
- $this->dob = new \DateTime($dob);
- }
- /**
- * Get dob
- *
- * @return date $dob
- */
- public function getDob()
- {
- return $this->dob;
- }
- /**
- * Set first name of the user
- *
- * @param string $firstName
- */
- public function setFirstName($firstName)
- {
- $this->firstName = (string) $firstName;
- }
- /**
- * Get first name of the user
- *
- * @return string $firstName
- */
- public function getFirstName()
- {
- return $this->firstName;
- }
- /**
- * Set last name of the user
- *
- * @param string $lastName
- */
- public function setLastName($lastName)
- {
- $this->lastName = (string) $lastName;
- }
- /**
- * Get last name of the user
- *
- * @return string $lastName
- */
- public function getLastName()
- {
- return $this->lastName;
- }
- /**
- * Set phone number
- *
- * @param string $phoneNumber
- */
- public function setPhoneNumber($phoneNumber)
- {
- $this->phoneNumber = (string) $phoneNumber;
- }
- /**
- * Get phone number
- *
- * @return string $phoneNumber
- */
- public function getPhoneNumber()
- {
- return $this->phoneNumber;
- }
- /**
- * Set createdAt
- *
- * @param datetime $createdAt
- */
- public function setCreatedAt($createdAt)
- {
- $this->createdAt = $createdAt;
- }
- /**
- * Get createdAt
- *
- * @return datetime $createdAt
- */
- public function getCreatedAt()
- {
- return $this->createdAt;
- }
- /**
- * Set lastLogin
- *
- * @param datetime $lastLogin
- */
- public function setLastLogin($lastLogin)
- {
- $this->lastLogin = $lastLogin;
- }
- /**
- * Get lastLogin
- *
- * @return datetime $lastLogin
- */
- public function getLastLogin()
- {
- return $this->lastLogin;
- }
- /**
- * Implementing UserInterface
- */
- public function eraseCredentials()
- {
- $this->setPassword(null);
- $this->setPlainpw(null);
- }
- public function equals(UserInterface $user)
- {
- return (bool) md5($this->getUsername()) === md5($user->getUsername());
- }
- public function getUsername()
- {
- return $this->getEmail();
- }
- }
Add Comment
Please, Sign In to add comment