src/Entity/User.php line 17

Open in your IDE?
  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 Doctrine\Common\Collections\Collection;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  12. #[ORM\Entity(repositoryClass: UserRepository::class)]
  13. #[ORM\Table(name: '`user`')]
  14. #[UniqueEntity(fields: ['nom'], message: 'There is already an account with this name')]
  15. class User implements UserInterface, PasswordAuthenticatedUserInterface
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column]
  20.     private ?int $id = null;
  21.     #[ORM\Column(length: 180)]
  22.     #[Groups(['show_search'])]
  23.     private ?string $email = null;
  24.     #[ORM\Column]
  25.     private array $roles = [];
  26.     /**
  27.      * @var string The hashed password
  28.      */
  29.     #[ORM\Column]
  30.     private ?string $password = null;
  31.     #[ORM\Column(type: 'boolean')]
  32.     private $isVerified = false;
  33.     #[ORM\Column(length: 255, nullable: false, unique: true)]
  34.     #[Groups(['show_search'])]
  35.     private ?string $nom = null;
  36.     #[ORM\Column(length: 255, nullable: true)]
  37.     #[Groups(['show_search'])]
  38.     private ?string $prenom = null;
  39.     #[ORM\Column(length: 255, nullable: true)]
  40.     #[Groups(['show_search'])]
  41.     private ?string $image_profie = null;
  42.     #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
  43.     private ?\DateTimeInterface $date_creation = null;
  44.     #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
  45.     private ?\DateTimeInterface $date_modification = null;
  46.     #[ORM\Column]
  47.     private ?bool $active = null;
  48.     #[ORM\ManyToMany(targetEntity: Roles::class, inversedBy: 'users')]
  49.     private Collection $roles_user;
  50.     #[ORM\OneToMany(mappedBy: 'user', targetEntity: Session::class)]
  51.     private Collection $sessions;
  52.     #[ORM\OneToMany(mappedBy: 'creer_par', targetEntity: OrderFabrication::class)]
  53.     private Collection $orderFabrications;
  54.     
  55.     #[ORM\OneToMany(mappedBy: 'user', targetEntity: Opportunity::class)]
  56.     private Collection $opportunities;
  57.     #[ORM\Column(length: 255, nullable: true)]
  58.     private ?string $company_name = null;
  59.     #[ORM\Column(length: 255, nullable: true)]
  60.     private ?string $identifiant_odoo = null;
  61.     #[ORM\Column(length: 255, nullable: true)]
  62.     private ?string $display_name = null;
  63.     
  64.     #[ORM\OneToMany(mappedBy: 'created_by', targetEntity: OrderFabricationTypes::class)]
  65.     private Collection $orderFabricationTypes;
  66.     #[ORM\OneToMany(mappedBy: 'user', targetEntity: OrderHistory::class)]
  67.     private Collection $orderHistories;
  68.     public function __construct()
  69.     {
  70.         $this->roles = ['ROLE_USER'];
  71.         $this->roles_user = new ArrayCollection();
  72.         $this->sessions = new ArrayCollection();
  73.         $this->orderFabrications = new ArrayCollection();
  74.         $this->opportunities = new ArrayCollection();
  75.         $this->orderFabricationTypes = new ArrayCollection();
  76.         $this->orderHistories = new ArrayCollection();
  77.     }
  78.     /**
  79.      * fill all class properties from array
  80.      *
  81.      * @param array $row => array of properties
  82.      * @return self
  83.      */
  84.     public static function withRow( array $row , $instance = null) {
  85.         if(empty($instance))
  86.         $instance = new self();
  87.         $instance->fill($row);
  88.         return $instance;
  89.     }
  90.     protected function fill( array $row ) {
  91.         // fill all properties from array
  92.         foreach($row as $key=>$value)
  93.         {
  94.             $this->$key = $value;
  95.         }
  96.     }
  97.     
  98.     public function getId(): ?int
  99.     {
  100.         return $this->id;
  101.     }
  102.     public function getEmail(): ?string
  103.     {
  104.         return $this->email;
  105.     }
  106.     public function setEmail(string $email): self
  107.     {
  108.         $this->email = $email;
  109.         return $this;
  110.     }
  111.     /**
  112.      * A visual identifier that represents this user.
  113.      *
  114.      * @see UserInterface
  115.      */
  116.     public function getUserIdentifier(): string
  117.     {
  118.         return (string) $this->email;
  119.     }
  120.     /**
  121.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  122.      */
  123.     public function getUsername(): string
  124.     {
  125.         return (string) $this->email;
  126.     }
  127.     /**
  128.      * @see UserInterface
  129.      */
  130.     public function getRoles(): array
  131.     {
  132.         $roles = $this->roles;
  133.         // guarantee every user at least has ROLE_USER
  134.         $roles[] = 'ROLE_USER';
  135.         return array_unique($roles);
  136.     }
  137.     public function setRoles(array $roles): self
  138.     {
  139.         $this->roles = $roles;
  140.         return $this;
  141.     }
  142.     /**
  143.      * @see PasswordAuthenticatedUserInterface
  144.      */
  145.     public function getPassword(): string
  146.     {
  147.         return $this->password;
  148.     }
  149.     public function setPassword(string $password): self
  150.     {
  151.         $this->password = $password;
  152.         return $this;
  153.     }
  154.     /**
  155.      * Returning a salt is only needed, if you are not using a modern
  156.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  157.      *
  158.      * @see UserInterface
  159.      */
  160.     public function getSalt(): ?string
  161.     {
  162.         return null;
  163.     }
  164.     /**
  165.      * @see UserInterface
  166.      */
  167.     public function eraseCredentials()
  168.     {
  169.         // If you store any temporary, sensitive data on the user, clear it here
  170.         // $this->plainPassword = null;
  171.     }
  172.     public function isVerified(): bool
  173.     {
  174.         return $this->isVerified;
  175.     }
  176.     public function setIsVerified(bool $isVerified): self
  177.     {
  178.         $this->isVerified = $isVerified;
  179.         return $this;
  180.     }
  181.     public function getNom(): ?string
  182.     {
  183.         return $this->nom;
  184.     }
  185.     public function setNom(string $nom): self
  186.     {
  187.         $this->nom = $nom;
  188.         return $this;
  189.     }
  190.     public function getPrenom(): ?string
  191.     {
  192.         return $this->prenom;
  193.     }
  194.     public function setPrenom(?string $prenom): self
  195.     {
  196.         $this->prenom = $prenom;
  197.         return $this;
  198.     }
  199.     public function getImageProfie(): ?string
  200.     {
  201.         return $this->image_profie;
  202.     }
  203.     public function setImageProfie(?string $image_profie): self
  204.     {
  205.         $this->image_profie = $image_profie;
  206.         return $this;
  207.     }
  208.     public function getDateCreation(): ?\DateTimeInterface
  209.     {
  210.         return $this->date_creation;
  211.     }
  212.     public function setDateCreation(\DateTimeInterface $date_creation): self
  213.     {
  214.         $this->date_creation = $date_creation;
  215.         return $this;
  216.     }
  217.     public function getDateModification(): ?\DateTimeInterface
  218.     {
  219.         return $this->date_modification;
  220.     }
  221.     public function setDateModification(\DateTimeInterface $date_modification): self
  222.     {
  223.         $this->date_modification = $date_modification;
  224.         return $this;
  225.     }
  226.     public function isActive(): ?bool
  227.     {
  228.         return $this->active;
  229.     }
  230.     public function setActive(bool $active): self
  231.     {
  232.         $this->active = $active;
  233.         return $this;
  234.     }
  235.     /**
  236.      * @return Collection<int, Roles>
  237.      */
  238.     public function getRolesUser(): Collection
  239.     {
  240.         return $this->roles_user;
  241.     }
  242.     public function addRolesUser(Roles $rolesUser): self
  243.     {
  244.         if (!$this->roles_user->contains($rolesUser)) {
  245.             $this->roles_user->add($rolesUser);
  246.         }
  247.         return $this;
  248.     }
  249.     public function removeRolesUser(Roles $rolesUser): self
  250.     {
  251.         $this->roles_user->removeElement($rolesUser);
  252.         return $this;
  253.     }
  254.     /**
  255.      * @return Collection<int, Session>
  256.      */
  257.     public function getSessions(): Collection
  258.     {
  259.         return $this->sessions;
  260.     }
  261.     public function addSession(Session $session): self
  262.     {
  263.         if (!$this->sessions->contains($session)) {
  264.             $this->sessions->add($session);
  265.             $session->setUser($this);
  266.         }
  267.         return $this;
  268.     }
  269.     public function removeSession(Session $session): self
  270.     {
  271.         if ($this->sessions->removeElement($session)) {
  272.             // set the owning side to null (unless already changed)
  273.             if ($session->getUser() === $this) {
  274.                 $session->setUser(null);
  275.             }
  276.         }
  277.         return $this;
  278.     }
  279.     /**
  280.      * @return Collection<int, OrderFabrication>
  281.      */
  282.     public function getOrderFabrications(): Collection
  283.     {
  284.         return $this->orderFabrications;
  285.     }
  286.     public function addOrderFabrication(OrderFabrication $orderFabrication): self
  287.     {
  288.         if (!$this->orderFabrications->contains($orderFabrication)) {
  289.             $this->orderFabrications->add($orderFabrication);
  290.             $orderFabrication->setCreerPar($this);
  291.         }
  292.         return $this;
  293.     }
  294.     /*
  295.      * @return Collection<int, Opportunity>
  296.      */
  297.     public function getOpportunities(): Collection
  298.     {
  299.         return $this->opportunities;
  300.     }
  301.     public function addOpportunity(Opportunity $opportunity): self
  302.     {
  303.         if (!$this->opportunities->contains($opportunity)) {
  304.             $this->opportunities->add($opportunity);
  305.             $opportunity->setUser($this);
  306.         }
  307.         return $this;
  308.     }
  309.     public function removeOrderFabrication(OrderFabrication $orderFabrication): self
  310.     {
  311.         if ($this->orderFabrications->removeElement($orderFabrication)) {
  312.             // set the owning side to null (unless already changed)
  313.             if ($orderFabrication->getCreerPar() === $this) {
  314.                 $orderFabrication->setCreerPar(null);
  315.             }
  316.         }
  317.         return $this;
  318.     }
  319.     public function removeOpportunity(Opportunity $opportunity): self
  320.     {
  321.         if ($this->opportunities->removeElement($opportunity)) {
  322.             // set the owning side to null (unless already changed)
  323.             if ($opportunity->getUser() === $this) {
  324.                 $opportunity->setUser(null);
  325.             }
  326.         }
  327.         return $this;
  328.     }
  329.     
  330.     public function getCompanyName(): ?string
  331.     {
  332.         return $this->company_name;
  333.     }
  334.     public function setCompanyName(?string $company_name): self
  335.     {
  336.         $this->company_name = $company_name;
  337.         return $this;
  338.     }
  339.     public function getIdentifiantOdoo(): ?string
  340.     {
  341.         return $this->identifiant_odoo;
  342.     }
  343.     public function setIdentifiantOdoo(?string $identifiant_odoo): self
  344.     {
  345.         $this->identifiant_odoo = $identifiant_odoo;
  346.         return $this;
  347.     }
  348.     public function getDisplayName(): ?string
  349.     {
  350.         return $this->display_name;
  351.     }
  352.     public function setDisplayName(?string $display_name): self
  353.     {
  354.         $this->display_name = $display_name;
  355.         return $this;
  356.     }
  357.     // when print object, it tansforme it to string
  358.     public function __toString()
  359.     {
  360.         return $this->display_name;
  361.     }
  362.     /*
  363.      * @return Collection<int, OrderFabricationTypes>
  364.      */
  365.     public function getOrderFabricationTypes(): Collection
  366.     {
  367.         return $this->orderFabricationTypes;
  368.     }
  369.     public function addOrderFabricationType(OrderFabricationTypes $orderFabricationType): self
  370.     {
  371.         if (!$this->orderFabricationTypes->contains($orderFabricationType)) {
  372.             $this->orderFabricationTypes->add($orderFabricationType);
  373.             $orderFabricationType->setCreatedBy($this);
  374.         }
  375.         return $this;
  376.     }
  377.     public function removeOrderFabricationType(OrderFabricationTypes $orderFabricationType): self
  378.     {
  379.         if ($this->orderFabricationTypes->removeElement($orderFabricationType)) {
  380.             // set the owning side to null (unless already changed)
  381.             if ($orderFabricationType->getCreatedBy() === $this) {
  382.                 $orderFabricationType->setCreatedBy(null);
  383.             }
  384.         }
  385.         return $this;
  386.     }
  387.     /**
  388.      * @return Collection<int, OrderHistory>
  389.      */
  390.     public function getOrderHistories(): Collection
  391.     {
  392.         return $this->orderHistories;
  393.     }
  394.     public function addOrderHistory(OrderHistory $orderHistory): self
  395.     {
  396.         if (!$this->orderHistories->contains($orderHistory)) {
  397.             $this->orderHistories->add($orderHistory);
  398.             $orderHistory->setUser($this);
  399.         }
  400.         return $this;
  401.     }
  402.     public function removeOrderHistory(OrderHistory $orderHistory): self
  403.     {
  404.         if ($this->orderHistories->removeElement($orderHistory)) {
  405.             // set the owning side to null (unless already changed)
  406.             if ($orderHistory->getUser() === $this) {
  407.                 $orderHistory->setUser(null);
  408.             }
  409.         }
  410.         return $this;
  411.     }
  412.     
  413. }