<?php
namespace Boab\CmsBundle\Entity;
use Boab\CmsBundle\Contract\ThumbnailInterface;
use Boab\CmsBundle\Contract\ThumbnailTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface as BaseUserInterface;
/**
* User
*
* @ORM\Table(name="users")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="user_type", type="string")*
* @ORM\Entity(repositoryClass="Boab\CmsBundle\Repository\UserRepository")
*/
abstract class User implements UserInterface, EquatableInterface, PasswordAuthenticatedUserInterface, \Serializable, ThumbnailInterface
{
const ROLE_DEFAULT = 'ROLE_USER';
CONST DATE_FORMAT = 'Y-m-d H:i:s';
CONST STATUS_ENABLE = 1;
CONST STATUS_DISABLE = 0;
use ThumbnailTrait;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @Groups({"detail", "list"})
* @ORM\Column(name="username", type="string", length=100, precision=0, scale=0, nullable=false, unique=true)
*/
protected $username;
/**
* @var string
* @Groups({"detail", "list"})
* @ORM\Column(name="firstname", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
*/
protected $firstname;
/**
* @var string
* @Groups({"detail", "list"})
* @ORM\Column(name="lastname", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
*/
protected $lastname;
/**
* @var string
* @Groups({"detail", "list"})
* @ORM\Column(name="gender", type="string", nullable=true, unique=false)
*/
protected $gender;
/**
* @var integer
* @Groups({"detail"})
* @ORM\Column(name="dob", type="date", nullable=true)
*/
protected $dob;
/**
* @var integer
* @Groups({"detail"})
* @ORM\Column(name="contact_number", type="string", length=30, precision=0, scale=0, nullable=true, unique=false)
*/
protected $contactNumber;
/**
* @var string
* @Groups({"detail", "list"})
* @ORM\Column(name="email", type="string", length=100, precision=0, scale=0, nullable=false, unique=true)
*/
protected $email;
/**
* @var string
* @Groups({"detail"})
* @ORM\Column(name="address", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
*/
protected $address;
/**
* @var string
* @Groups({"detail"})
* @ORM\Column(name="city", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
*/
protected $city;
/**
* @var string
* @Groups({"detail"})
* @ORM\Column(name="country", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
*/
protected $country;
/**
* @var string
* @Groups({"detail"})
* @ORM\Column(name="postal_code", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
*/
protected $postalCode;
/**
* @var array
* @Groups({"detail"})
* @ORM\Column(type="array", name="roles")
*/
protected $roles = [];
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=200, precision=0, scale=0, nullable=true)
*/
protected $password;
/**
* @var string
*
* @ORM\Column(name="salt", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
*/
protected $salt;
/**
* @var string
*
* @ORM\Column(name="account_status", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
*/
protected $accountStatus;
/**
* @ORM\Column(name="is_activated", type="boolean", options={"default":"0"})
*/
protected $isActivated;
/**
* @ORM\OneToMany(targetEntity="Boab\CmsBundle\Entity\Content", mappedBy="user")
*/
private $contents;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=true)
*/
private $createdAt;
protected $plainPassword;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
public function __construct()
{
$this->contents = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* @param string $username
* @return User
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set firstname
*
* @param string $firstname
* @return User
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
/**
* Get firstname
*
* @return string
*/
public function getFirstname(): ?string
{
return $this->firstname;
}
/**
* Set lastname
*
* @param string $lastname
* @return User
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Get lastname
*
* @return string
*/
public function getLastname(): string
{
return $this->lastname;
}
/**
* Set email
*
* @param string $email
* @return User
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail(): string
{
return $this->email;
}
/**
* Set contactNumber
*
* @param string $contactNumber
*
* @return UserAdmin
*/
public function setContactNumber($contactNumber)
{
$this->contactNumber = $contactNumber;
return $this;
}
/**
* Get contactNumber
*
* @return string
*/
public function getContactNumber(): ?string
{
return $this->contactNumber;
}
public function addRole($role)
{
$role = strtoupper($role);
if (!in_array($role, $this->getRoles(), true)) {
$this->roles[] = $role;
}
return $this;
}
/**
* Set role
*
* @param string $role
* @return User
*/
public function setRoles(array $roles)
{
$this->roles = array();
foreach ($roles as $role) {
$this->addRole($role);
}
return $this;
}
/**
* Get role
*
* @return array
*/
public function getRoles()
{
return array_unique(array_merge($this->roles, [self::ROLE_DEFAULT]));
}
public function hasRole($role)
{
return in_array(strtoupper($role), $this->getRoles(), true);
}
/**
* Set password
*
* @param string $password
* @return User
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword(): ?string
{
return $this->password;
}
/**
* Set salt
*
* @param string $salt
* @return User
*/
public function setSalt($salt='')
{
$this->salt = ($salt !='')? $salt : uniqid(mt_rand(), true);
return $this;
}
/**
* Get salt
*
* @return string
*/
public function getSalt()
{
return $this->salt;
}
/**
* Set dob
*
* @param \DateTime $dob
*
* @return User
*/
public function setDob($dob)
{
$this->dob = $dob;
return $this;
}
/**
* Get dob
*
* @return \DateTime
*/
public function getDob()
{
return $this->dob;
}
/**
* Set address
*
* @param string $address
*
* @return User
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set city
*
* @param string $city
*
* @return Employee
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set country
*
* @param string $country
*
* @return Employee
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* Set isActivated
*
* @param boolean $isActivated
*
* @return User
*/
public function setIsActivated($isActivated)
{
$this->isActivated = $isActivated;
return $this;
}
/**
* Get isActivated
*
* @return boolean
*/
public function getIsActivated()
{
return $this->isActivated;
}
/**
* Get isActivated
*
* @return boolean
*/
public function isActivated()
{
return $this->isActivated;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function isAccountNonExpired()
{
return true;
}
public function isAccountNonLocked()
{
return true;
}
public function isCredentialsNonExpired()
{
return true;
}
public function isEnabled()
{
return true;
}
public function eraseCredentials()
{
}
public function isEqualTo(BaseUserInterface $user):bool
{
if ($this->password !== $user->getPassword()) {
return false;
}
if ($this->username !== $user->getUsername()) {
return false;
}
return true;
}
/** @see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
$this->id,
$this->username,
$this->password,
));
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
list ($this->id, $this->username, $this->password) = unserialize($serialized, ['allowed_classes' => false]);
}
/**
* Set gender.
*
* @param string|null $gender
*
* @return User
*/
public function setGender($gender = null)
{
$this->gender = $gender;
return $this;
}
/**
* Get gender.
*
* @return string|null
*/
public function getGender()
{
return $this->gender;
}
/**
* Set plainPassword.
*
* @param string|null $plainPassword
*
* @return User
*/
public function setPlainPassword($plainPassword = null)
{
$this->plainPassword = $plainPassword;
return $this;
}
/**
* Get plainPassword.
*
* @return string|null
*/
public function getPlainPassword()
{
return $this->plainPassword;
}
/**
* Add content.
*
* @param \Boab\CmsBundle\Entity\Content $content
*
* @return User
*/
public function addContent(\Boab\CmsBundle\Entity\Content $content)
{
$this->contents[] = $content;
return $this;
}
/**
* Remove content.
*
* @param \Boab\CmsBundle\Entity\Content $content
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeContent(\Boab\CmsBundle\Entity\Content $content)
{
return $this->contents->removeElement($content);
}
/**
* Get contents.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getContents()
{
return $this->contents;
}
public function getUserIdentifier():string
{
return $this->email;
}
public function getPostalCode(): ?string
{
return $this->postalCode;
}
public function setPostalCode(?string $postalCode): self
{
$this->postalCode = $postalCode;
return $this;
}
public function getAccountStatus(): ?string
{
return $this->accountStatus;
}
public function setAccountStatus(?string $accountStatus): self
{
$this->accountStatus = $accountStatus;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
}