src/Entity/User.php line 19

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\Mapping\JoinTable;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. use \Symfony\Component\HttpFoundation\File\File;
  12. /**
  13.  * @ORM\Entity(repositoryClass=UserRepository::class)
  14.  * @Vich\Uploadable
  15.  */
  16. class User implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\Column(type="string", length=180, unique=true)
  26.      */
  27.     private $email;
  28.     /**
  29.      * @ORM\Column(type="json")
  30.      */
  31.     private $roles = [];
  32.     /**
  33.      * @var string The hashed password
  34.      * @ORM\Column(type="string")
  35.      */
  36.     private $password;
  37.     /**
  38.      * @ORM\Column(type="string", length=255, nullable=true)
  39.      */
  40.     private $firstName;
  41.     /**
  42.      * @ORM\Column(type="string", length=255, nullable=true)
  43.      */
  44.     private $lastName;
  45.     /**
  46.      * @ORM\Column(type="string", length=255, nullable=true)
  47.      * @var string
  48.      */
  49.     private $image;
  50.     /**
  51.      * @Vich\UploadableField(mapping="teams_image", fileNameProperty="image")
  52.      * @var File
  53.      */
  54.     private $imageFile;
  55.     /**
  56.      * @ORM\ManyToMany(targetEntity=Project::class, inversedBy="users")
  57.      * @JoinTable(name="user_project")
  58.      */
  59.     private $projects;
  60.     /**
  61.      * @ORM\Column(type="string", length=255, nullable=true)
  62.      */
  63.     private $slug;
  64.     /**
  65.      * @ORM\Column(type="text", nullable=true)
  66.      */
  67.     private $content;
  68.     /**
  69.      * @ORM\Column(type="datetime", nullable=true)
  70.      */
  71.     private $updatedAt;
  72.     /**
  73.      * @ORM\Column(type="string", length=150, nullable=true)
  74.      */
  75.     private $jobs;
  76.     public function __construct()
  77.     {
  78.         $this->projects = new ArrayCollection();
  79.     }
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function getEmail(): ?string
  85.     {
  86.         return $this->email;
  87.     }
  88.     public function setEmail(string $email): self
  89.     {
  90.         $this->email $email;
  91.         return $this;
  92.     }
  93.     /**
  94.      * A visual identifier that represents this user.
  95.      *
  96.      * @see UserInterface
  97.      */
  98.     public function getUserIdentifier(): string
  99.     {
  100.         return (string) $this->email;
  101.     }
  102.     /**
  103.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  104.      */
  105.     public function getUsername(): string
  106.     {
  107.         return (string) $this->email;
  108.     }
  109.     /**
  110.      * @see UserInterface
  111.      */
  112.     public function getRoles(): array
  113.     {
  114.         $roles $this->roles;
  115.         // guarantee every user at least has ROLE_USER
  116.         $roles[] = 'ROLE_USER';
  117.         return array_unique($roles);
  118.     }
  119.     /**
  120.      * @param array $roles
  121.      * @return User
  122.      */
  123.     public function setRoles(array $roles): self
  124.     {
  125.         $this->roles $roles;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @see PasswordAuthenticatedUserInterface
  130.      */
  131.     public function getPassword(): string
  132.     {
  133.         return $this->password;
  134.     }
  135.     public function setPassword(string $password): self
  136.     {
  137.         $this->password $password;
  138.         return $this;
  139.     }
  140.     /**
  141.      * Returning a salt is only needed, if you are not using a modern
  142.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  143.      *
  144.      * @see UserInterface
  145.      */
  146.     public function getSalt(): ?string
  147.     {
  148.         return null;
  149.     }
  150.     /**
  151.      * @see UserInterface
  152.      */
  153.     public function eraseCredentials(): void
  154.     {
  155.         // If you store any temporary, sensitive data on the user, clear it here
  156.         // $this->plainPassword = null;
  157.     }
  158.     public function getFirstName(): ?string
  159.     {
  160.         return $this->firstName;
  161.     }
  162.     public function setFirstName(?string $firstName): self
  163.     {
  164.         $this->firstName $firstName;
  165.         return $this;
  166.     }
  167.     public function getLastName(): ?string
  168.     {
  169.         return $this->lastName;
  170.     }
  171.     public function setLastName(?string $lastName): self
  172.     {
  173.         $this->lastName $lastName;
  174.         return $this;
  175.     }
  176.     public function getImage(): ?string
  177.     {
  178.         return $this->image;
  179.     }
  180.     public function setImage(?string $image): self
  181.     {
  182.         $this->image $image;
  183.         return $this;
  184.     }
  185.     public function getImageFile()
  186.                       {
  187.                           return $this->imageFile;
  188.                       }
  189.     /**
  190.      * @param \Symfony\Component\HttpFoundation\File\File|null $imageFile
  191.      */
  192.     public function setImageFile(File $imageFile null): void
  193.                       {
  194.                           $this->imageFile $imageFile;
  195.                           if ($imageFile) {
  196.                               $this->updatedAt = new \DateTime('now');
  197.                           }
  198.                   
  199.                       }
  200.     /**
  201.      * @return Collection|Project[]
  202.      */
  203.     public function getProjects(): Collection
  204.     {
  205.         return $this->projects;
  206.     }
  207.     public function addProject(Project $project): self
  208.     {
  209.         if (!$this->projects->contains($project)) {
  210.             $this->projects[] = $project;
  211.         }
  212.         return $this;
  213.     }
  214.     public function removeProject(Project $project): self
  215.     {
  216.         $this->projects->removeElement($project);
  217.         return $this;
  218.     }
  219.     public function getSlug(): ?string
  220.     {
  221.         return $this->slug;
  222.     }
  223.     public function setSlug(?string $slug): self
  224.     {
  225.         $this->slug $slug;
  226.         return $this;
  227.     }
  228.     public function getContent(): ?string
  229.     {
  230.         return $this->content;
  231.     }
  232.     public function setContent(?string $content): self
  233.     {
  234.         $this->content $content;
  235.         return $this;
  236.     }
  237.     public function getUpdatedAt(): ?\DateTimeInterface
  238.     {
  239.         return $this->updatedAt;
  240.     }
  241.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  242.     {
  243.         $this->updatedAt $updatedAt;
  244.         return $this;
  245.     }
  246.     public function getFullname(): string
  247.              {
  248.                  return $this->getFirstName().' '.$this->getLastName();
  249.              }
  250.     public function getJobs(): ?string
  251.     {
  252.         return $this->jobs;
  253.     }
  254.     public function setJobs(?string $jobs): self
  255.     {
  256.         $this->jobs $jobs;
  257.         return $this;
  258.     }
  259. }