src/Entity/User.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  6. use Doctrine\Common\Collections\{
  7.     //ArrayCollection,
  8.     Collection
  9. };
  10. use Doctrine\ORM\Mapping as ORM;
  11. use App\Repository\UserRepository;
  12. /**
  13.  * User
  14.  *
  15.  * @ORM\Table(name="user", uniqueConstraints={@ORM\UniqueConstraint(name="UNIQ_8D93D649F85E0677", columns={"username"})}, indexes={@ORM\Index(name="IDX_8D93D64983ACDD40", columns={"role_id"})})
  16.  * @ORM\Entity(repositoryClass=UserRepository::class)
  17.  */
  18. class User implements UserInterfacePasswordAuthenticatedUserInterface
  19. {
  20.     /**
  21.      * @var int
  22.      *
  23.      * @ORM\Column(name="id", type="smallint", nullable=false)
  24.      * @ORM\Id
  25.      * @ORM\GeneratedValue(strategy="IDENTITY")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @var string
  30.      *
  31.      * @ORM\Column(name="username", type="string", length=40, nullable=false)
  32.      */
  33.     private $username;
  34.     /**
  35.      * @var string
  36.      *
  37.      * @ORM\Column(name="password", type="string", length=250, nullable=false)
  38.      */
  39.     private $password;
  40.     /**
  41.      * @var string|null
  42.      *
  43.      * @ORM\Column(name="lastname", type="string", length=30, nullable=true, options={"default"="NULL"})
  44.      */
  45.     private $lastname;
  46.     /**
  47.      * @var string|null
  48.      *
  49.      * @ORM\Column(name="firstname", type="string", length=30, nullable=true, options={"default"="NULL"})
  50.      */
  51.     private $firstname;
  52.     /**
  53.      * @var string|null
  54.      *
  55.      * @ORM\Column(name="email", type="string", length=80, nullable=true, options={"default"="NULL"})
  56.      */
  57.     private $email;
  58.     /**
  59.      * @var bool
  60.      *
  61.      * @ORM\Column(name="is_active", type="boolean", nullable=false)
  62.      */
  63.     private $isActive true;
  64.     /**
  65.      * @var \Role
  66.      *
  67.      * @ORM\ManyToOne(targetEntity="Role")
  68.      * @ORM\JoinColumns({
  69.      *   @ORM\JoinColumn(name="role_id", referencedColumnName="id")
  70.      * })
  71.      */
  72.     private $role;
  73.     /**
  74.      * @var Collection
  75.      *
  76.      * @ORM\ManyToMany(targetEntity="Campaign", inversedBy="userid")
  77.      * @ORM\JoinTable(name="compaign_user",
  78.      *   joinColumns={
  79.      *     @ORM\JoinColumn(name="userID", referencedColumnName="id")
  80.      *   },
  81.      *   inverseJoinColumns={
  82.      *     @ORM\JoinColumn(name="compaignID", referencedColumnName="id")
  83.      *   }
  84.      * )
  85.      */
  86.     private $compaignid;
  87.     private $plainPassword;
  88.     /**
  89.      * Constructor
  90.      */
  91.     public function __construct()
  92.     {
  93.         $this->compaignid = new \Doctrine\Common\Collections\ArrayCollection();
  94.         //$this->isActive = true;
  95.     }
  96.     public function getId(): ?int
  97.     {
  98.         return $this->id;
  99.     }
  100.     public function getUsername(): ?string
  101.     {
  102.         return $this->username;
  103.     }
  104.     public function setUsername(string $username): self
  105.     {
  106.         $this->username $username;
  107.         return $this;
  108.     }
  109.     public function getLastname(): ?string
  110.     {
  111.         return $this->lastname;
  112.     }
  113.     public function setLastname(?string $lastname): self
  114.     {
  115.         $this->lastname $lastname;
  116.         return $this;
  117.     }
  118.     public function getFirstname(): ?string
  119.     {
  120.         return $this->firstname;
  121.     }
  122.     public function setFirstname(?string $firstname): self
  123.     {
  124.         $this->firstname $firstname;
  125.         return $this;
  126.     }
  127.     public function getEmail(): ?string
  128.     {
  129.         return $this->email;
  130.     }
  131.     public function setEmail(?string $email): self
  132.     {
  133.         $this->email $email;
  134.         return $this;
  135.     }
  136.     public function isIsActive(): bool
  137.     {
  138.         return $this->isActive;
  139.     }
  140.     public function setIsActive(bool $isActive): self
  141.     {
  142.         $this->isActive $isActive;
  143.         return $this;
  144.     }
  145.     public function getRole(): ?Role
  146.     {
  147.         return $this->role;
  148.     }
  149.     public function setRole(?Role $role): self
  150.     {
  151.         $this->role $role;
  152.         return $this;
  153.     }
  154.     /**
  155.      * @return Collection<int, Campaign>
  156.      */
  157.     public function getCompaignid(): Collection
  158.     {
  159.         return $this->compaignid;
  160.     }
  161.     public function addCompaignid(Campaign $compaignid): self
  162.     {
  163.         if (!$this->compaignid->contains($compaignid)) {
  164.             $this->compaignid[] = $compaignid;
  165.         }
  166.         return $this;
  167.     }
  168.     public function removeCompaignid(Campaign $compaignid): self
  169.     {
  170.         $this->compaignid->removeElement($compaignid);
  171.         return $this;
  172.     }
  173.     /**
  174.      * @see UserInterface
  175.      */
  176.     public function getUserIdentifier(): string
  177.     {
  178.         return (string) $this->username;
  179.     }
  180.     /**
  181.      * @see UserInterface
  182.      */
  183.     public function getRoles(): array
  184.     {
  185.         $roles[] = $this->role->getRole();
  186.         $roles[] = 'ROLE_USER';
  187.         return array_unique($roles);
  188.     }
  189.     public function setRoles(array $roles): self
  190.     {
  191.         $this->role $role;
  192.         return $this;
  193.     }
  194.     /**
  195.      * @see PasswordAuthenticatedUserInterface
  196.      */
  197.     public function getPassword(): ?string
  198.     {
  199.         return $this->password;
  200.     }
  201.     public function setPassword(?string $password): self
  202.     {
  203.         if (null !== $password) {
  204.             $this->password $password;
  205.         }
  206.         return $this;
  207.     }
  208.     /**
  209.      * @see UserInterface
  210.      */
  211.     public function eraseCredentials()
  212.     {
  213.         // If you store any temporary, sensitive data on the user, clear it here
  214.         // $this->plainPassword = null;
  215.     }
  216.     public function getPlainPassword(): ?string
  217.     {
  218.         return $this->plainPassword;
  219.     }
  220.     
  221.     public function setPlainPassword(?string $plainPassword): self
  222.     {
  223.         $this->plainPassword $plainPassword;
  224.     
  225.         return $this;
  226.     }
  227.     public function __toString() {
  228.         return sprintf('%s %s'$this->lastname$this->firstname);
  229.     }
  230. }