src/Entity/User.php line 19

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\DBAL\Types\Types;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\UserRepository;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  13. #[ORM\Entity(repositoryClassUserRepository::class)]
  14. #[Vich\Uploadable]
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column]
  20.     #[Groups("shop_browse")]
  21.     private ?int $id null;
  22.     #[ORM\Column(length180uniquetrue)]
  23.     private ?string $email null;
  24.     #[ORM\Column(type'json')]
  25.     private $roles = [];
  26.     /**
  27.      * @var string The hashed password
  28.      */
  29.     #[ORM\Column]
  30.     private ?string $password null;
  31.     #[ORM\Column(length255)]
  32.     #[Groups("shop_browse")]
  33.     private ?string $firstName null;
  34.     #[ORM\Column(length255)]
  35.     private ?string $lastName null;
  36.     // START IMAGE
  37.     #[Vich\UploadableField(mapping'user_images'fileNameProperty'imageNameUser')]
  38.     private ?File $picture null;
  39.     #[ORM\Column(nullabletrue)]
  40.     private ?string $imageNameUser null;
  41.     #[ORM\Column(length64)]
  42.     private ?string $phoneNumber null;
  43.     #[ORM\Column(length255nullabletrue)]
  44.     private ?string $about null;
  45.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  46.     private ?\DateTimeInterface $updatedAt null;
  47.     /*#[ORM\ManyToMany(targetEntity: Shop::class, inversedBy: 'users', cascade: ["persist"])]
  48.     #[ORM\JoinTable(name: "user_shop")]
  49.     #[Groups("shop_browse")]
  50.     private Collection $shops;*/
  51.     #[ORM\OneToMany(mappedBy'users'targetEntityShop::class, cascade: ["persist"])]
  52.     #[Groups("shop_browse")]
  53.     private Collection $shops;
  54.     public function __construct()
  55.     {
  56.         $this->shops = new ArrayCollection();
  57.     }
  58.     public function getId(): ?int
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function getEmail(): ?string
  63.     {
  64.         return $this->email;
  65.     }
  66.     public function setEmail(string $email): self
  67.     {
  68.         $this->email $email;
  69.         return $this;
  70.     }
  71.     /**
  72.      * A visual identifier that represents this user.
  73.      *
  74.      * @see UserInterface
  75.      */
  76.     public function getUserIdentifier(): string
  77.     {
  78.         return (string) $this->email;
  79.     }
  80.     /**
  81.      * @see UserInterface
  82.      */
  83.     public function getRoles(): array
  84.     {
  85.         $roles $this->roles;
  86.         // guarantee every user at least has ROLE_USER
  87.         $roles[] = 'ROLE_USER';
  88.         return array_unique($roles);
  89.     }
  90.     public function setRoles(array $roles): self
  91.     {
  92.         $this->roles $roles;
  93.         return $this;
  94.     }
  95.     /**
  96.      * @see PasswordAuthenticatedUserInterface
  97.      */
  98.     public function getPassword(): string
  99.     {
  100.         return $this->password;
  101.     }
  102.     public function setPassword(string $password): self
  103.     {
  104.         $this->password $password;
  105.         return $this;
  106.     }
  107.     /**
  108.      * @see UserInterface
  109.      */
  110.     public function eraseCredentials()
  111.     {
  112.         // If you store any temporary, sensitive data on the user, clear it here
  113.         // $this->plainPassword = null;
  114.     }
  115.     public function getFirstName(): ?string
  116.     {
  117.         return $this->firstName;
  118.     }
  119.     public function setFirstName(string $firstName): self
  120.     {
  121.         $this->firstName $firstName;
  122.         return $this;
  123.     }
  124.     public function getLastName(): ?string
  125.     {
  126.         return $this->lastName;
  127.     }
  128.     public function setLastName(string $lastName): self
  129.     {
  130.         $this->lastName $lastName;
  131.         return $this;
  132.     }
  133.     // PICTURE  ------ DEBUT DE L'UTILISATION DE VICH ---------------------------
  134.     /**
  135.      *
  136.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $picture
  137.      */
  138.     public function setPicture(?File $picture null): void
  139.     {
  140.         $this->picture $picture;
  141.         /*if (null !== $picture) {
  142.             // It is required that at least one field changes if you are using doctrine
  143.             // otherwise the event listeners won't be called and the file is lost
  144.             $this->updatedAt = new \DateTimeImmutable();
  145.         }*/
  146.     }
  147.     public function getPicture(): ?File
  148.     {
  149.         return $this->picture;
  150.     }
  151.     public function setImageNameUser(?string $imageNameUser): void
  152.     {
  153.         $this->imageNameUser $imageNameUser;
  154.     }
  155.     public function getImageNameUser(): ?string
  156.     {
  157.         return $this->imageNameUser;
  158.     }
  159.     public function getUpdatedAt(): ?\DateTimeInterface
  160.     {
  161.         return $this->updatedAt;
  162.     }
  163.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  164.     {
  165.         $this->updatedAt $updatedAt;
  166.         return $this;
  167.     }
  168. /*
  169.     public function getPicture(): ?string
  170.     {
  171.         return $this->picture;
  172.     }
  173.     public function setPicture(string $picture): self
  174.     {
  175.         $this->picture = $picture;
  176.         return $this;
  177.     }
  178. */
  179.     public function getPhoneNumber(): ?string
  180.     {
  181.         return $this->phoneNumber;
  182.     }
  183.     public function setPhoneNumber(string $phoneNumber): self
  184.     {
  185.         $this->phoneNumber $phoneNumber;
  186.         return $this;
  187.     }
  188.     public function getAbout(): ?string
  189.     {
  190.         return $this->about;
  191.     }
  192.     public function setAbout(?string $about): self
  193.     {
  194.         $this->about $about;
  195.         return $this;
  196.     }
  197.     /**
  198.      * @return Collection<int, Shop>
  199.      */
  200.     public function getShops(): Collection
  201.     {
  202.         return $this->shops;
  203.     }
  204.     public function addShop(Shop $shop): self
  205.     {
  206.         if (!$this->shops->contains($shop)) {
  207.             $this->shops->add($shop);
  208.             $shop->setUsers($this);
  209.         }
  210.         return $this;
  211.     }
  212.     public function removeShop(Shop $shop): self
  213.     {
  214.         if ($this->shops->removeElement($shop)) {
  215.             // set the owning side to null (unless already changed)
  216.             if ($shop->getUsers() === $this) {
  217.                 $shop->setUsers(null);
  218.             }
  219.         }
  220.         return $this;
  221.     }
  222. }