src/Entity/User.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Entity\Company;
  5. use App\Entity\Person;
  6. use App\Entity\Town;
  7. use App\Model\TranslationModel;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. // /**
  16. //  * User
  17. //  * @ORM\Table(name="userrv")
  18. //  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  19. //  * @ORM\InheritanceType("JOINED")
  20. //  * @ORM\DiscriminatorColumn(name="discr", type="string")
  21. //  * @ORM\DiscriminatorMap({"user" = "User", "person" = "Person","company" = "Company","town" = "Town" })
  22. //  */
  23. #[ORM\Table(name"userrv")]
  24. #[ORM\Entity(repositoryClass"App\Repository\UserRepository")]
  25. #[ORM\InheritanceType("JOINED")]
  26. #[ORM\DiscriminatorColumn(name"discr"type"string")]
  27. #[ORM\DiscriminatorMap(["user" => User::class, "person" => Person::class, "company" => Company::class, "town" => Town::class])]
  28. class User implements UserInterface
  29. {
  30.     // /**
  31.     //  * @var int
  32.     //  *
  33.     //  * @ORM\Column(name="id", type="integer", unique=true )
  34.     //  * @ORM\Id
  35.     //  * @ORM\GeneratedValue(strategy="AUTO")
  36.     //  */
  37.     #[ORM\Column(name"id"type"integer"uniquetrue)]
  38.     #[ORM\Id]
  39.     #[ORM\GeneratedValue(strategy"AUTO")]
  40.     #[Groups(['login','company''category''favorite'])]
  41.     protected $id;
  42.     // /**
  43.     //  * @var int
  44.     //  *
  45.     //  * @ORM\Column(name="gaeaUserId", type="integer", unique=true, nullable=true)
  46.     //  */
  47.     #[ORM\Column(name"gaeaUserId"type"integer"uniquetruenullabletrue)]
  48.     #[Groups(['login'])]
  49.     private $gaeaUserId;
  50.     //  * NE PAS LE SUPPRIMER DE LA TABLE DANS LA BDD, sinon aura l'exception getUserIdentifier : expected string, null returned quand on se login
  51.     #[ORM\Column(name"username"type"string"length255nullabletrue)]
  52.     #[Groups(['login'])]
  53.     private $username;
  54.     /**
  55.      * @var string
  56.      */
  57.     private $email;
  58.     /**
  59.      * @var string
  60.      */
  61.     private $password;
  62.     #[ORM\Column(type"string"length50)]
  63.     #[Groups(['login'])]
  64.     protected $role 'ROLE_USER';
  65.     #[ORM\Column(name"token"type"string"length255nullablefalse)]
  66.     #[Groups(['login'])]
  67.     protected $token;
  68.     #[ORM\Column(name"emailValidated"type"boolean")]
  69.     protected $emailValidated;
  70.     #[ORM\Column(type"boolean")]
  71.     #[Groups(['login'])]
  72.     protected $actived;
  73.     /**
  74.      * @var \DateTime
  75.      */
  76.     #[ORM\Column(name'inscription_date'type'date'nullabletrue)]
  77.     #[Groups(['login'])]
  78.     protected $inscriptiondate;
  79.     #[ORM\Column(name'avatar'type'string'nullabletrue)]
  80.     #[Groups(['login'])]
  81.     protected $avatar//all
  82.     #[Assert\File(maxSize'1024k'mimeTypesMessage'Merci de télécharger une image de votre produit')]
  83.     private $avatar2;
  84.     /**
  85.      * @var string
  86.      */
  87.     private $discr;
  88.     /**
  89.      * @return string
  90.      */
  91.     public function getgaeaUserId()
  92.     {
  93.         return $this->gaeaUserId;
  94.     }
  95.     /**
  96.      * @param string $username
  97.      */
  98.     public function setgaeaUserId($gaeaUserId)
  99.     {
  100.         $this->gaeaUserId $gaeaUserId;
  101.     }
  102.     /**
  103.      * @return string
  104.      */
  105.     public function getUsername()
  106.     {
  107.         return $this->username;
  108.     }
  109.     /**
  110.      * A visual identifier that represents this user.
  111.      *
  112.      * @see UserInterface
  113.      */
  114.     public function getUserIdentifier(): string
  115.     {
  116.         return (string) $this->gaeaUserId;
  117.     }
  118.     /**
  119.      * @param string $username
  120.      */
  121.     public function setUsername($username)
  122.     {
  123.         $this->username $username;
  124.     }
  125.     /**
  126.      * @return string
  127.      */
  128.     public function getEmail()
  129.     {
  130.         return $this->email;
  131.     }
  132.     /**
  133.      * @param string $email
  134.      */
  135.     public function setEmail($email)
  136.     {
  137.         $this->email $email;
  138.     }
  139.     /**
  140.      * @return string
  141.      */
  142.     public function getPassword()
  143.     {
  144.         return $this->password;
  145.     }
  146.     /**
  147.      * @param string $password
  148.      */
  149.     public function setPassword($password)
  150.     {
  151.         $this->password $password;
  152.     }
  153.     /**
  154.      * @return mixed
  155.      */
  156.     public function getRole()
  157.     {
  158.         return $this->role;
  159.     }
  160.     /**
  161.      * @param string $role
  162.      */
  163.     public function setRole(string $role): void
  164.     {
  165.         $this->role $role ?: 'ROLE_USER';
  166.     }
  167.     /**
  168.      * @return string
  169.      */
  170.     public function getToken()
  171.     {
  172.         return $this->token;
  173.     }
  174.     /**
  175.      * @param string $token
  176.      */
  177.     public function setToken($token)
  178.     {
  179.         $this->token $token;
  180.     }
  181.     /**
  182.      * @return bool
  183.      */
  184.     public function isEmailValidated()
  185.     {
  186.         return $this->emailValidated;
  187.     }
  188.     /**
  189.      * @param bool $emailValidated
  190.      */
  191.     public function setEmailValidated($emailValidated)
  192.     {
  193.         $this->emailValidated $emailValidated;
  194.     }
  195.     /**
  196.      * @return bool
  197.      */
  198.     public function isActived()
  199.     {
  200.         return $this->actived;
  201.     }
  202.     /**
  203.      * @return bool
  204.      */
  205.     public function getActived()
  206.     {
  207.         return $this->actived;
  208.     }
  209.     /**
  210.      * @param bool $actived
  211.      */
  212.     public function setActived($actived)
  213.     {
  214.         $this->actived $actived;
  215.     }
  216.     public function getSalt()
  217.     {
  218.         return null;
  219.     }
  220.     public function eraseCredentials()
  221.     {
  222.         return null;
  223.     }
  224.     public function getRoles()
  225.     {
  226.         return [$this->getRole()];
  227.     }
  228.     /**
  229.      * @return int
  230.      */
  231.     public function getId()
  232.     {
  233.         return $this->id;
  234.     }
  235.     /**
  236.      * @param int $id
  237.      */
  238.     public function setId($id)
  239.     {
  240.         $this->id $id;
  241.     }
  242.     /**
  243.      * @return \DateTime
  244.      */
  245.     public function getInscriptiondate()
  246.     {
  247.         return $this->inscriptiondate;
  248.     }
  249.     /**
  250.      * @param \DateTime $inscriptiondate
  251.      */
  252.     public function setInscriptiondate($inscriptiondate)
  253.     {
  254.         $this->inscriptiondate $inscriptiondate;
  255.     }
  256.     /**
  257.      * @return string
  258.      */
  259.     public function getAvatar()
  260.     {
  261.         return $this->avatar;
  262.     }
  263.     /**
  264.      * @param string avatar
  265.      * @return mixed
  266.      */
  267.     public function setAvatar($avatar)
  268.     {
  269.         $this->avatar $avatar;
  270.         return $this;
  271.     }
  272.     public function getAvatar2()
  273.     {
  274.         return $this->avatar2;
  275.     }
  276.     public function setAvatar2($avatar2)
  277.     {
  278.         $this->avatar2 $avatar2;
  279.         return $this;
  280.     }
  281.     ////////////////////////////////////////
  282.     // /**
  283.     //  * @ORM\ManyToMany(targetEntity="Company")
  284.     //  * @ORM\JoinTable (name="fav_company")
  285.     //  */
  286.     #[ORM\ManyToMany(targetEntity"Company")]
  287.     #[ORM\JoinTable(name"fav_company")]
  288.     private $companyfavs;
  289.     // /**
  290.     //  * @ORM\OneToMany(targetEntity="ProductFav", mappedBy="user", orphanRemoval=true, cascade={"persist", "remove", "merge"})
  291.     //  */
  292.     #[ORM\OneToMany(targetEntity"ProductFav"mappedBy"user"orphanRemovaltruecascade: ["persist""remove""merge"])]
  293.     private $productFavUsers;
  294.     // /**
  295.     //  *
  296.     //  * @ORM\OneToMany(targetEntity="App\Entity\Friendship", mappedBy="friend", fetch="EAGER")
  297.     //  */
  298.     #[ORM\OneToMany(targetEntity"Friendship"mappedBy"friend"fetch"EAGER"cascade: ["remove"])]
  299.     private $friendsWithMe;
  300.     // /**
  301.     //  * @var array
  302.     //  *
  303.     //  * @ORM\OneToMany(targetEntity="App\Entity\Friendship", mappedBy="user", fetch="EAGER")
  304.     //  */
  305.     #[ORM\OneToMany(targetEntity"Friendship"mappedBy"user"fetch"EAGER"cascade: ["remove"])]
  306.     private $myFriends;
  307.     // /**
  308.     //  * @ORM\OneToMany(targetEntity="CompanyFav", mappedBy="user")
  309.     //  */
  310.     #[ORM\OneToMany(targetEntity"CompanyFav"mappedBy"user"cascade: ["remove"])]
  311.     private $companyFavUsers;
  312.     // /**
  313.     //  * @ORM\OneToMany(targetEntity="Notification", mappedBy="owner")
  314.     //  */
  315.     #[ORM\OneToMany(targetEntity"Notification"mappedBy"owner"cascade: ["remove"])]
  316.     private $notifications;
  317.     public function _construct()
  318.     {
  319.         $this->companyfavs = new ArrayCollection();
  320.         $this->companyFavUsers = new ArrayCollection();
  321.         $this->productFavUsers = new ArrayCollection();
  322.         $this->friendsWithMe = new ArrayCollection();
  323.         $this->myFriends = new ArrayCollection();
  324.         $this->notifications = new ArrayCollection();
  325.     }
  326.     public function addCompanyFavs(Company $company)
  327.     {
  328.         if ($this->companyfavs->contains($company)) {
  329.             return;
  330.         }
  331.         $this->companyfavs[] = $company;
  332.     }
  333.     public function getCompanyFavs()
  334.     {
  335.         return $this->companyfavs;
  336.     }
  337.     public function deleteCompanyFavs($company)
  338.     {
  339.         return $this->companyfavs->removeElement($company);
  340.     }
  341.     public function getDiscr(): ?string
  342.     {
  343.         return $this->discr;
  344.     }
  345.     public function setDiscr(string $discr)
  346.     {
  347.         $this->discr $discr;
  348.         return $this;
  349.     }
  350.     /**
  351.      * @return Collection|ProductFav[]
  352.      */
  353.     public function getProductFavUsers(): Collection
  354.     {
  355.         return $this->productFavUsers;
  356.     }
  357.     public function addProductFav(ProductFav $productFav): self
  358.     {
  359.         if (!$this->productFavUsers->contains($productFav)) {
  360.             $this->productFavUsers[] = $productFav;
  361.             $productFav->setUser($this);
  362.         }
  363.         return $this;
  364.     }
  365.     public function removeProductFav(ProductFav $possession): self
  366.     {
  367.         if ($this->$possession->removeElement($possession)) {
  368.             // set the owning side to null (unless already changed)
  369.             if ($possession->getUser() === $this) {
  370.                 $possession->setUser(null);
  371.             }
  372.         }
  373.         return $this;
  374.     }
  375.     /**
  376.      * @return Collection|Notification[]
  377.      */
  378.     public function getNotifications(): Collection
  379.     {
  380.         return $this->notifications;
  381.     }
  382.     public function addNotification(Notification $notification): self
  383.     {
  384.         if (!$this->notifications->contains($notification)) {
  385.             $this->notifications[] = $notification;
  386.             $notification->setOwner($this);
  387.         }
  388.         return $this;
  389.     }
  390.     public function removeNotification(Notification $notification): self
  391.     {
  392.         if ($this->notifications->removeElement($notification)) {
  393.             // set the owning side to null (unless already changed)
  394.             if ($notification->getOwner() === $this) {
  395.                 $notification->setOwner(null);
  396.             }
  397.         }
  398.         return $this;
  399.     }
  400.     /**
  401.      * @return array
  402.      */
  403.     public function getFriendsWithMe()
  404.     {
  405.         return $this->friendsWithMe;
  406.     }
  407.     /**
  408.      * @param array $friendsWithMe
  409.      */
  410.     public function setFriendsWithMe(array $friendsWithMe): void
  411.     {
  412.         $this->friendsWithMe $friendsWithMe;
  413.     }
  414.     /**
  415.      * @return array
  416.      */
  417.     public function getMyFriends()
  418.     {
  419.         return $this->myFriends;
  420.     }
  421.     /**
  422.      * @param array $myFriends
  423.      */
  424.     public function setMyFriends(array $myFriends): void
  425.     {
  426.         $this->myFriends $myFriends;
  427.     }
  428.     /**
  429.      * @return mixed
  430.      */
  431.     public function getCompanyFavUsers()
  432.     {
  433.         return $this->companyFavUsers;
  434.     }
  435.     /**
  436.      * @param mixed $companyFavUsers
  437.      */
  438.     public function setCompanyFavUsers($companyFavUsers): void
  439.     {
  440.         $this->companyFavUsers $companyFavUsers;
  441.     }
  442.     // /**
  443.     //  * @var boolean
  444.     //  *
  445.     //  * @ORM\Column(name="connected", type="boolean", nullable=true)
  446.     //  */
  447.     #[ORM\Column(name"connected"type"boolean"nullabletrue)]
  448.     private $connected;
  449.     // /**
  450.     //  * @ORM\Column(type="string", length=255)
  451.     //  */
  452.     #[ORM\Column(type"string"length255)]
  453.     #[Groups(['login''company'])]
  454.     private $firstname;
  455.     // /**
  456.     //  * @ORM\Column(type="string", length=255)
  457.     //  */
  458.     #[ORM\Column(type"string"length255)]
  459.     #[Groups(['login''company'])]
  460.     private $lastname;
  461.     // /**
  462.     //  * @ORM\OneToMany(targetEntity=UserPreference::class, mappedBy="user")
  463.     //  */
  464.     #[ORM\OneToMany(targetEntityUserPreference::class, mappedBy"user"cascade: ["remove"])]
  465.     private $userPreferences;
  466.     // /**
  467.     //  * @ORM\OneToMany(targetEntity=FavoriteCategory::class, mappedBy="user", orphanRemoval=true)
  468.     //  */
  469.     #[ORM\OneToMany(targetEntityFavoriteCategory::class, mappedBy"user"orphanRemovaltruecascade: ["remove"])]
  470.     private $favoriteCategories;
  471.     // /**
  472.     //  * @ORM\OneToMany(targetEntity=FavoriteCompany::class, mappedBy="user", orphanRemoval=true)
  473.     //  */
  474.     #[ORM\OneToMany(targetEntityFavoriteCompany::class, mappedBy"company"orphanRemovaltruecascade: ["remove"])]
  475.     private $favoriteCompanies;
  476.     public function __construct()
  477.     {
  478.         $this->userPreferences = new ArrayCollection();
  479.         $this->favoriteCategories = new ArrayCollection();
  480.         $this->favoriteCompanies = new ArrayCollection();
  481.     }
  482.     // /**
  483.     //  * @ORM\OneToMany(targetEntity=Newsletter::class, mappedBy="gaeaUserNewsletter", orphanRemoval=true)
  484.     //  */
  485.     // private $gaeaUserNewsletter;
  486.     // public function __construct()
  487.     // {
  488.     //     $this->gaeaUserNewsletter = new ArrayCollection();
  489.     // }
  490.     /**
  491.      * @return bool
  492.      */
  493.     public function isConnected(): ?bool
  494.     {
  495.         return $this->connected;
  496.     }
  497.     // /**
  498.     //  * @param bool $connected
  499.     //  */
  500.     public function setConnected(bool $connected): void
  501.     {
  502.         $this->connected $connected;
  503.     }
  504.     public function getLastname(): ?string
  505.     {
  506.         return $this->lastname;
  507.     }
  508.     public function setLastname(string $lastname): self
  509.     {
  510.         $this->lastname $lastname;
  511.         return $this;
  512.     }
  513.     public function getFirstname(): ?string
  514.     {
  515.         return $this->firstname;
  516.     }
  517.     public function setFirstname(string $firstname): self
  518.     {
  519.         $this->firstname $firstname;
  520.         return $this;
  521.     }
  522.     /**
  523.      * @return Collection|UserPreference[]
  524.      */
  525.     public function getUserPreferences(): Collection
  526.     {
  527.         return $this->userPreferences;
  528.     }
  529.     public function addUserPreference(UserPreference $userPreference): self
  530.     {
  531.         if (!$this->userPreferences->contains($userPreference)) {
  532.             $this->userPreferences[] = $userPreference;
  533.             $userPreference->setUser($this);
  534.         }
  535.         return $this;
  536.     }
  537.     public function removeUserPreference(UserPreference $userPreference): self
  538.     {
  539.         if ($this->userPreferences->removeElement($userPreference)) {
  540.             // set the owning side to null (unless already changed)
  541.             if ($userPreference->getUser() === $this) {
  542.                 $userPreference->setUser(null);
  543.             }
  544.         }
  545.         return $this;
  546.     }
  547.     /**
  548.      * @return Collection|FavoriteCategory[]
  549.      */
  550.     public function getFavoriteCategories(): Collection
  551.     {
  552.         return $this->favoriteCategories;
  553.     }
  554.     public function addFavoriteCategory(FavoriteCategory $favoriteCategory): self
  555.     {
  556.         if (!$this->favoriteCategories->contains($favoriteCategory)) {
  557.             $this->favoriteCategories[] = $favoriteCategory;
  558.             $favoriteCategory->setUser($this);
  559.         }
  560.         return $this;
  561.     }
  562.     public function removeFavoriteCategory(FavoriteCategory $favoriteCategory): self
  563.     {
  564.         if ($this->favoriteCategories->removeElement($favoriteCategory)) {
  565.             // set the owning side to null (unless already changed)
  566.             if ($favoriteCategory->getUser() === $this) {
  567.                 $favoriteCategory->setUser(null);
  568.             }
  569.         }
  570.         return $this;
  571.     }
  572.     /**
  573.      * @return Collection|FavoriteCompany[]
  574.      */
  575.     public function getFavoriteCompanies(): Collection
  576.     {
  577.         return $this->favoriteCompanies;
  578.     }
  579.     public function addFavoriteCompanies(FavoriteCompany $favoriteCompany): self
  580.     {
  581.         if (!$this->favoriteCompanies->contains($favoriteCompany)) {
  582.             $this->favoriteCompanies[] = $favoriteCompany;
  583.             $favoriteCompany->setUser($this);
  584.         }
  585.         return $this;
  586.     }
  587.     public function removeFavoriteCompanies(FavoriteCompany $favoriteCompany): self
  588.     {
  589.         if ($this->favoriteCompanies->removeElement($favoriteCompany)) {
  590.             // set the owning side to null (unless already changed)
  591.             if ($favoriteCompany->getUser() === $this) {
  592.                 $favoriteCompany->setUser(null);
  593.             }
  594.         }
  595.         return $this;
  596.     }
  597.     // public function getX(): ?string
  598.     // {
  599.     //     return $this->x;
  600.     // }
  601.     // public function setX(string $x): self
  602.     // {
  603.     //     $this->x = $x;
  604.     //     return $this;
  605.     // }
  606. }