lib/boab/cms-bundle/src/Entity/User.php line 25

Open in your IDE?
  1. <?php
  2. namespace Boab\CmsBundle\Entity;
  3. use App\Entity\Billing\Account;
  4. use App\Entity\Scheduler;
  5. use Boab\CmsBundle\Contract\ThumbnailInterface;
  6. use Boab\CmsBundle\Contract\ThumbnailTrait;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Security\Core\User\EquatableInterface;
  12. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  13. use Symfony\Component\Security\Core\User\UserInterface as BaseUserInterface;
  14. /**
  15.  * User
  16.  *
  17.  * @ORM\Table(name="users")
  18.  * @ORM\InheritanceType("JOINED")
  19.  * @ORM\DiscriminatorColumn(name="user_type", type="string")*
  20.  * @ORM\Entity(repositoryClass="Boab\CmsBundle\Repository\UserRepository")
  21.  */
  22. abstract class User implements UserInterfaceEquatableInterfacePasswordAuthenticatedUserInterface\SerializableThumbnailInterface
  23. {
  24.     const ROLE_DEFAULT 'ROLE_USER';
  25.     CONST DATE_FORMAT 'Y-m-d H:i:s';
  26.     CONST STATUS_ENABLE 1;
  27.     CONST STATUS_DISABLE 0;
  28.     use ThumbnailTrait;
  29.    /**
  30.      * @var integer
  31.      *
  32.      * @ORM\Column(name="id", type="integer")
  33.      * @ORM\Id
  34.      * @ORM\GeneratedValue(strategy="AUTO")
  35.      */
  36.     protected $id;
  37.     /**
  38.      * @var string
  39.      * @Groups({"detail", "list"})
  40.      * @ORM\Column(name="username", type="string", length=100, precision=0, scale=0, nullable=false, unique=true)
  41.      */
  42.     protected $username;
  43.     /**
  44.      * @var string
  45.      * @Groups({"detail", "list"})
  46.      * @ORM\Column(name="firstname", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
  47.      */
  48.     protected $firstname;
  49.     /**
  50.      * @var string
  51.      * @Groups({"detail", "list"})
  52.      * @ORM\Column(name="lastname", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
  53.      */
  54.     protected $lastname;
  55.     /**
  56.      * @var string
  57.      * @Groups({"detail", "list"})
  58.      * @ORM\Column(name="gender", type="string", nullable=true, unique=false)
  59.      */
  60.     protected $gender;
  61.     /**
  62.      * @var integer
  63.      * @Groups({"detail"})
  64.      * @ORM\Column(name="dob", type="date", nullable=true)
  65.      */
  66.     protected $dob;
  67.     /**
  68.      * @var integer
  69.      * @Groups({"detail"})
  70.      * @ORM\Column(name="contact_number", type="string", length=30, precision=0, scale=0, nullable=true, unique=false)
  71.      */
  72.     protected $contactNumber;
  73.     /**
  74.      * @var string
  75.      * @Groups({"detail", "list"})
  76.      * @ORM\Column(name="email", type="string", length=100, precision=0, scale=0, nullable=false, unique=true)
  77.      */
  78.     protected $email;
  79.     /**
  80.      * @var string
  81.      * @Groups({"detail"})
  82.      * @ORM\Column(name="address", type="string", length=255, precision=0, scale=0, nullable=true, unique=false)
  83.      */
  84.     protected $address;
  85.     /**
  86.      * @var string
  87.      * @Groups({"detail"})
  88.      * @ORM\Column(name="city", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
  89.      */
  90.     protected $city;
  91.     /**
  92.      * @var string
  93.      * @Groups({"detail"})
  94.      * @ORM\Column(name="country", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
  95.      */
  96.     protected $country;
  97.     /**
  98.      * @var string
  99.      * @Groups({"detail"})
  100.      * @ORM\Column(name="postal_code", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
  101.      */
  102.     protected $postalCode;
  103.     /**
  104.      * @var array
  105.      * @Groups({"detail"})
  106.      * @ORM\Column(type="array", name="roles")
  107.      */
  108.     protected $roles = [];
  109.     /**
  110.      * @var string
  111.      *
  112.      * @ORM\Column(name="password", type="string", length=200, precision=0, scale=0, nullable=true)
  113.      */
  114.     protected $password;
  115.     /**
  116.      * @var string
  117.      *
  118.      * @ORM\Column(name="salt", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
  119.      */
  120.     protected $salt;
  121.     /**
  122.      * @var string
  123.      *
  124.      * @ORM\Column(name="account_status", type="string", length=100, precision=0, scale=0, nullable=true, unique=false)
  125.      */
  126.     protected $accountStatus;
  127.     /**
  128.      * @ORM\Column(name="is_activated", type="boolean", options={"default":"0"})
  129.      */
  130.     protected $isActivated;
  131.     /**
  132.      * @ORM\Column(name="is_verified", type="boolean", nullable=true, options={"default":"0"})
  133.      */
  134.     protected $isVerified;    
  135.     /**
  136.      * @ORM\OneToMany(targetEntity="Boab\CmsBundle\Entity\Content", mappedBy="user")
  137.      */
  138.     private $contents;
  139.     /**
  140.      * @var \DateTime
  141.      *
  142.      * @ORM\Column(name="created_at", type="datetime", nullable=true)
  143.      */
  144.     private $createdAt;
  145.     protected $plainPassword;
  146.     /**
  147.      * @ORM\Column(type="datetime", nullable=true)
  148.      */
  149.     private $updatedAt;
  150.     /**
  151.      * @var string
  152.      *
  153.      * @ORM\Column(name="bio", type="text", nullable=true)
  154.      */
  155.     protected $bio;
  156.     public function __construct()
  157.     {
  158.         $this->contents = new ArrayCollection();
  159.     }
  160.     /**
  161.      * Get id
  162.      *
  163.      * @return integer
  164.      */
  165.     public function getId()
  166.     {
  167.         return $this->id;
  168.     }
  169.     /**
  170.      * Set username
  171.      *
  172.      * @param string $username
  173.      * @return User
  174.      */
  175.     public function setUsername($username)
  176.     {
  177.         $this->username $username;
  178.         return $this;
  179.     }
  180.     /**
  181.      * Get username
  182.      *
  183.      * @return string
  184.      */
  185.     public function getUsername():string
  186.     {
  187.         return $this->username;
  188.     }
  189.     /**
  190.      * Set firstname
  191.      *
  192.      * @param string $firstname
  193.      * @return User
  194.      */
  195.     public function setFirstName($firstname)
  196.     {
  197.         $this->firstname $firstname;
  198.         return $this;
  199.     }
  200.     /**
  201.      * Get firstname
  202.      *
  203.      * @return string
  204.      */
  205.     public function getFirstName(): ?string
  206.     {
  207.         return $this->firstname;
  208.     }
  209.     /**
  210.      * Set lastname
  211.      *
  212.      * @param string $lastname
  213.      * @return User
  214.      */
  215.     public function setLastName($lastname)
  216.     {
  217.         $this->lastname $lastname;
  218.         return $this;
  219.     }
  220.     /**
  221.      * Get lastname
  222.      *
  223.      * @return string
  224.      */
  225.     public function getLastName(): ?string
  226.     {
  227.         return $this->lastname;
  228.     }
  229.     /**
  230.      * Set email
  231.      *
  232.      * @param string $email
  233.      * @return User
  234.      */
  235.     public function setEmail($email)
  236.     {
  237.         $this->email $email;
  238.         return $this;
  239.     }
  240.     /**
  241.      * Get email
  242.      *
  243.      * @return string
  244.      */
  245.     public function getEmail(): string
  246.     {
  247.         return $this->email;
  248.     }
  249.     /**
  250.      * Set contactNumber
  251.      *
  252.      * @param string $contactNumber
  253.      *
  254.      * @return UserAdmin
  255.      */
  256.     public function setContactNumber($contactNumber)
  257.     {
  258.         $this->contactNumber $contactNumber;
  259.         return $this;
  260.     }
  261.     /**
  262.      * Get contactNumber
  263.      *
  264.      * @return string
  265.      */
  266.     public function getContactNumber(): ?string
  267.     {
  268.         return $this->contactNumber;
  269.     }
  270.     public function addRole($role)
  271.     {
  272.         $role strtoupper($role);
  273.         if (!in_array($role$this->getRoles(), true)) {
  274.             $this->roles[] = $role;
  275.         }
  276.         return $this;
  277.     }
  278.     /**
  279.      * Set role
  280.      *
  281.      * @param string $role
  282.      * @return User
  283.      */
  284.     public function setRoles(array $roles)
  285.     {
  286.         $this->roles = array();
  287.         foreach ($roles as $role) {
  288.             $this->addRole($role);
  289.         }
  290.         return $this;
  291.     }
  292.     /**
  293.      * Get role
  294.      *
  295.      * @return array
  296.      */
  297.     public function getRoles():array
  298.     {
  299.         return array_unique(array_merge($this->roles, [self::ROLE_DEFAULT]));
  300.     }
  301.     public function hasRole($role):bool
  302.     {
  303.         return in_array(strtoupper($role), $this->getRoles(), true);
  304.     }
  305.     /**
  306.      * Set password
  307.      *
  308.      * @param string $password
  309.      * @return User
  310.      */
  311.     public function setPassword($password)
  312.     {
  313.         $this->password $password;
  314.         return $this;
  315.     }
  316.     /**
  317.      * Get password
  318.      *
  319.      * @return string
  320.      */
  321.     public function getPassword(): ?string
  322.     {
  323.         return $this->password;
  324.     }
  325.     /**
  326.      * Set salt
  327.      *
  328.      * @param string $salt
  329.      * @return User
  330.      */
  331.     public function setSalt($salt='')
  332.     {
  333.         $this->salt = ($salt !='')? $salt uniqid(mt_rand(), true);
  334.         return $this;
  335.     }
  336.     /**
  337.      * Get salt
  338.      *
  339.      * @return string
  340.      */
  341.     public function getSalt()
  342.     {
  343.         return $this->salt;
  344.     }
  345.     /**
  346.      * Set dob
  347.      *
  348.      * @param \DateTime $dob
  349.      *
  350.      * @return User
  351.      */
  352.     public function setDob($dob)
  353.     {
  354.         $this->dob $dob;
  355.         return $this;
  356.     }
  357.     /**
  358.      * Get dob
  359.      *
  360.      * @return \DateTime
  361.      */
  362.     public function getDob()
  363.     {
  364.         return $this->dob;
  365.     }
  366.     /**
  367.      * Set address
  368.      *
  369.      * @param string $address
  370.      *
  371.      * @return User
  372.      */
  373.     public function setAddress($address)
  374.     {
  375.         $this->address $address;
  376.         return $this;
  377.     }
  378.     /**
  379.      * Get address
  380.      *
  381.      * @return string
  382.      */
  383.     public function getAddress()
  384.     {
  385.         return $this->address;
  386.     }
  387.     /**
  388.      * Set city
  389.      *
  390.      * @param string $city
  391.      *
  392.      * @return Employee
  393.      */
  394.     public function setCity($city)
  395.     {
  396.         $this->city $city;
  397.         return $this;
  398.     }
  399.     /**
  400.      * Get city
  401.      *
  402.      * @return string
  403.      */
  404.     public function getCity()
  405.     {
  406.         return $this->city;
  407.     }
  408.     /**
  409.      * Set country
  410.      *
  411.      * @param string $country
  412.      *
  413.      * @return Employee
  414.      */
  415.     public function setCountry($country)
  416.     {
  417.         $this->country $country;
  418.         return $this;
  419.     }
  420.     /**
  421.      * Get country
  422.      *
  423.      * @return string
  424.      */
  425.     public function getCountry()
  426.     {
  427.         return $this->country;
  428.     }
  429.     /**
  430.      * Set isActivated
  431.      *
  432.      * @param boolean $isActivated
  433.      *
  434.      * @return User
  435.      */
  436.     public function setIsActivated(bool $isActivated): self
  437.     {
  438.         $this->isActivated $isActivated;
  439.         return $this;
  440.     }
  441.     /**
  442.      * Get isActivated
  443.      *
  444.      * @return boolean
  445.      */
  446.     public function getIsActivated()
  447.     {
  448.         return $this->isActivated;
  449.     }
  450.     /**
  451.      * Get isActivated
  452.      *
  453.      * @return boolean
  454.      */
  455.     public function isActivated()
  456.     {
  457.         return $this->isActivated;
  458.     }    
  459.     /**
  460.      * Set isVerified
  461.      *
  462.      * @param boolean $isVerified
  463.      *
  464.      * @return User
  465.      */
  466.     public function setIsVerified(bool $isVerified): self
  467.     {
  468.         $this->isVerified $isVerified;
  469.         return $this;
  470.     }
  471.     /**
  472.      * Get isVerified
  473.      *
  474.      * @return boolean
  475.      */
  476.     public function getIsVerified()
  477.     {
  478.         return $this->isVerified;
  479.     }
  480.     /**
  481.      * Get isActivated
  482.      *
  483.      * @return boolean
  484.      */
  485.     public function isVerified(): bool
  486.     {
  487.         return $this->isVerified;
  488.     }
  489.     public function getCreatedAt(): ?\DateTimeInterface
  490.     {
  491.         return $this->createdAt;
  492.     }
  493.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  494.     {
  495.         $this->createdAt $createdAt;
  496.         return $this;
  497.     }
  498.     public function isAccountNonExpired()
  499.     {
  500.         return true;
  501.     }
  502.     public function isAccountNonLocked()
  503.     {
  504.         return true;
  505.     }
  506.     public function isCredentialsNonExpired()
  507.     {
  508.         return true;
  509.     }
  510.     public function isEnabled()
  511.     {
  512.         return true;
  513.     }
  514.     public function eraseCredentials()
  515.     {
  516.     }
  517.     public function isEqualTo(BaseUserInterface $user):bool
  518.     {
  519.         if ($this->password !== $user->getPassword()) {
  520.             return false;
  521.         }
  522.         if ($this->username !== $user->getUsername()) {
  523.             return false;
  524.         }
  525.         return true;
  526.     }
  527.     /** @see \Serializable::serialize() */
  528.     public function serialize()
  529.     {
  530.         return serialize(array(
  531.             $this->id,
  532.             $this->username,
  533.             $this->password,
  534.         ));
  535.     }
  536.     /** @see \Serializable::unserialize() */
  537.     public function unserialize($serialized)
  538.     {
  539.         list ($this->id$this->username$this->password) = unserialize($serialized, ['allowed_classes' => false]);
  540.     }
  541.     /**
  542.      * Set gender.
  543.      *
  544.      * @param string|null $gender
  545.      *
  546.      * @return User
  547.      */
  548.     public function setGender($gender null)
  549.     {
  550.         $this->gender $gender;
  551.         return $this;
  552.     }
  553.     /**
  554.      * Get gender.
  555.      *
  556.      * @return string|null
  557.      */
  558.     public function getGender()
  559.     {
  560.         return $this->gender;
  561.     }
  562.     /**
  563.      * Set plainPassword.
  564.      *
  565.      * @param string|null $plainPassword
  566.      *
  567.      * @return User
  568.      */
  569.     public function setPlainPassword($plainPassword null)
  570.     {
  571.         $this->plainPassword $plainPassword;
  572.         return $this;
  573.     }
  574.     /**
  575.      * Get plainPassword.
  576.      *
  577.      * @return string|null
  578.      */
  579.     public function getPlainPassword()
  580.     {
  581.         return $this->plainPassword;
  582.     }
  583.     /**
  584.      * Add content.
  585.      *
  586.      * @param \Boab\CmsBundle\Entity\Content $content
  587.      *
  588.      * @return User
  589.      */
  590.     public function addContent(\Boab\CmsBundle\Entity\Content $content)
  591.     {
  592.         $this->contents[] = $content;
  593.         return $this;
  594.     }
  595.     /**
  596.      * Remove content.
  597.      *
  598.      * @param \Boab\CmsBundle\Entity\Content $content
  599.      *
  600.      * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
  601.      */
  602.     public function removeContent(\Boab\CmsBundle\Entity\Content $content)
  603.     {
  604.         return $this->contents->removeElement($content);
  605.     }
  606.     /**
  607.      * Get contents.
  608.      *
  609.      * @return \Doctrine\Common\Collections\Collection
  610.      */
  611.     public function getContents()
  612.     {
  613.         return $this->contents;
  614.     }
  615.     public function getUserIdentifier():string
  616.     {
  617.         return $this->email;
  618.     }
  619.     public function getPostalCode(): ?string
  620.     {
  621.         return $this->postalCode;
  622.     }
  623.     public function setPostalCode(?string $postalCode): self
  624.     {
  625.         $this->postalCode $postalCode;
  626.         return $this;
  627.     }
  628.     public function getAccountStatus(): ?string
  629.     {
  630.         return $this->accountStatus;
  631.     }
  632.     public function setAccountStatus(?string $accountStatus): self
  633.     {
  634.         $this->accountStatus $accountStatus;
  635.         return $this;
  636.     }
  637.     public function getUpdatedAt(): ?\DateTimeInterface
  638.     {
  639.         return $this->updatedAt;
  640.     }
  641.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  642.     {
  643.         $this->updatedAt $updatedAt;
  644.         return $this;
  645.     }
  646.     /**
  647.      * Set Bio
  648.      *
  649.      * @param  string $bio
  650.      * @return Page
  651.      */
  652.     public function setBio($bio)
  653.     {
  654.         $this->bio $bio;
  655.         return $this;
  656.     }
  657.     /**
  658.      * Get Bio
  659.      *
  660.      * @return string
  661.      */
  662.     public function getBio()
  663.     {
  664.         return $this->bio;
  665.     }
  666.     public function getFullName(): string
  667.     {
  668.         return $this->firstname .' '.$this->lastname;
  669.     }
  670.     abstract function getUserType(): string;
  671. }