src/Entity/User.php line 22

Open in your IDE?
  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 Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. /**
  15.  * @ORM\Entity(repositoryClass=UserRepository::class)
  16.  * @Vich\Uploadable
  17.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  18.  */
  19. class User implements UserInterfacePasswordAuthenticatedUserInterface
  20. {
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      * @Groups({"user"})
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(type="string", length=100, unique=true)
  30.      * @Assert\NotBlank
  31.      * @Assert\Email()
  32.      * @Groups({"user"})
  33.      */
  34.     private $email;
  35.     private $roles = [];
  36.     /**
  37.      * ROLE_ADMIN : Super usuario
  38.      * ROLE_CHIEF : Administrador cliente
  39.      * ROLE_USER : Usuario cliente
  40.      * ROLE_SUPPLIER_CHIEF : Administrador proveedor
  41.      * ROLE_SUPPLIER : Usuario proveedor
  42.      * 
  43.      * @ORM\Column(type="string", length=255)
  44.      * @Assert\NotBlank
  45.      * @Groups({"user"})
  46.      */
  47.     private $role;
  48.     /**
  49.      * @var string The hashed password
  50.      * @ORM\Column(type="string", nullable=true)
  51.      */
  52.     private $password;
  53.     /**
  54.      * @ORM\Column(type="string", length=100)
  55.      * @Assert\NotBlank
  56.      * @Groups({"user"})
  57.      */
  58.     private $name;
  59.     /**
  60.      * @ORM\Column(type="string", length=100, nullable=true)
  61.      */
  62.     private $department;
  63.     /**
  64.      * @ORM\Column(type="string", length=100, nullable=true)
  65.      * @Assert\NotBlank()
  66.      */
  67.     private $position;
  68.     /**
  69.      * @ORM\Column(type="string", length=255, nullable=true)
  70.      */
  71.     private $work_center;
  72.     /**
  73.      * @ORM\Column(type="string", length=50, nullable=true)
  74.      */
  75.     private $phone;
  76.     /**
  77.      * @ORM\Column(type="datetime")
  78.      */
  79.     private $created_at;
  80.     /**
  81.      * @ORM\Column(type="datetime")
  82.      */
  83.     private $updated_at;
  84.     /**
  85.      * @ORM\Column(type="boolean")
  86.      */
  87.     private $accept_terms false;
  88.     /**
  89.      * @ORM\Column(type="datetime", nullable=true)
  90.      */
  91.     private $accepted_at;
  92.     /**
  93.      * @ORM\Column(type="boolean")
  94.      */
  95.     private $active false;
  96.     /**
  97.      * @ORM\Column(type="boolean")
  98.      */
  99.     private $isVerified false;
  100.     /**
  101.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="user")
  102.      * @ORM\JoinColumn(nullable=false)
  103.      * @Assert\NotBlank(groups={"RequiredUser"})
  104.      */
  105.     private $company;
  106.     /**
  107.      * @ORM\Column(type="string", length=100)
  108.      * @Assert\NotBlank
  109.      */
  110.     private $surname;
  111.     /**
  112.      * @ORM\Column(type="string", length=8, nullable=true)
  113.      */
  114.     private $ref;
  115.     /**
  116.      * @ORM\ManyToOne(targetEntity=Supplier::class, inversedBy="user")
  117.      * @ORM\JoinColumn(onDelete="CASCADE")
  118.      */
  119.     private $supplier;
  120.     /**
  121.      * Usuario de empresa OEM (1) ó SB (2)
  122.      * 
  123.      * @ORM\Column(type="smallint")
  124.      */
  125.     private $type;
  126.     /**
  127.      * @ORM\OneToMany(targetEntity=OrderMessage::class, mappedBy="user")
  128.      */
  129.     private $orderMessages;
  130.     /**
  131.      * @ORM\OneToMany(targetEntity=Equipment::class, mappedBy="user")
  132.      */
  133.     private $equipment;
  134.     /**
  135.      * @ORM\Column(type="string", length=255, nullable=true)
  136.      */
  137.     private $photo;
  138.     /**
  139.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  140.      * 
  141.      * @Vich\UploadableField(mapping="user_file", fileNameProperty="photo")
  142.      * @Assert\File(
  143.      *     maxSize = "2M",
  144.      *     mimeTypes = {"image/jpeg","image/gif","image/png"},
  145.      *     maxSizeMessage = "El tamaño máximo permitido del archivo es {{ limit }} MB.",
  146.      *     mimeTypesMessage = "El tipo de archivo no es válido ({{ type }}). Tipos de archivo permitidos {{ types }}"
  147.      * )
  148.      * 
  149.      * @var File|null
  150.      */
  151.     private $photoFile;
  152.     /**
  153.      * @ORM\OneToOne(targetEntity=NotificationsConfig::class, cascade={"persist", "remove"})
  154.      */
  155.     private $notifications_config;
  156.     /**
  157.      * @ORM\ManyToOne(targetEntity=CompanyClient::class)
  158.      * @ORM\JoinColumn(onDelete="CASCADE")
  159.      */
  160.     private $company_client;
  161.     public function __construct()
  162.     {    
  163.         $this->created_at = new \DateTime();
  164.         $this->markAsUpdated();
  165.         $this->orderMessages = new ArrayCollection();
  166.         $this->equipment = new ArrayCollection();
  167.     }
  168.     // Registra el método mágico para imprimir el nombre del estado, por ejemplo, California
  169.     public function __toString() {
  170.         return $this->name .' '$this->surname;
  171.     }
  172.     public function getId(): ?int
  173.     {
  174.         return $this->id;
  175.     }
  176.     public function getEmail(): ?string
  177.     {
  178.         return $this->email;
  179.     }
  180.     public function setEmail(string $email): self
  181.     {
  182.         $this->email $email;
  183.         return $this;
  184.     }
  185.     /**
  186.      * A visual identifier that represents this user.
  187.      *
  188.      * @see UserInterface
  189.      */
  190.     public function getUsername(): string
  191.     {
  192.         return (string) $this->email;
  193.     }
  194.     public function getRole(): ?string
  195.     {
  196.         return $this->role;
  197.     }
  198.     
  199.     /**
  200.      * @see UserInterface
  201.      */    
  202.     public function getRoles(): array
  203.     {        
  204.         return array($this->role);
  205.     }
  206.     
  207.     public function setRole($role)
  208.     {
  209.         if (!is_string($role)) {
  210.             throw new \InvalidArgumentException('Invalid role');
  211.         }
  212.         $this->role $role;
  213.     }
  214.     
  215.     
  216.     public function setRoles(array $roles): self
  217.     {
  218.         $this->roles $roles;
  219.         return $this;
  220.     }
  221.     
  222.     /**
  223.      * @see UserInterface
  224.      */
  225.     public function getPassword(): string
  226.     {
  227.         return (string) $this->password;
  228.     }
  229.     public function setPassword(string $password): self
  230.     {
  231.         $this->password $password;
  232.         return $this;
  233.     }
  234.     /**
  235.      * Returning a salt is only needed, if you are not using a modern
  236.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  237.      *
  238.      * @see UserInterface
  239.      */
  240.     public function getSalt(): ?string
  241.     {
  242.         return null;
  243.     }
  244.     /**
  245.      * @see UserInterface
  246.      */
  247.     public function eraseCredentials()
  248.     {
  249.         // If you store any temporary, sensitive data on the user, clear it here
  250.         // $this->plainPassword = null;
  251.     }
  252.     public function getName(): ?string
  253.     {
  254.         return $this->name;
  255.     }
  256.     public function setName(string $name): self
  257.     {
  258.         $this->name $name;
  259.         return $this;
  260.     }
  261.     public function getDepartment(): ?string
  262.     {
  263.         return $this->department;
  264.     }
  265.     public function setDepartment(?string $department): self
  266.     {
  267.         $this->department $department;
  268.         return $this;
  269.     }
  270.     public function getPosition(): ?string
  271.     {
  272.         return $this->position;
  273.     }
  274.     public function setPosition(string $position): self
  275.     {
  276.         $this->position $position;
  277.         return $this;
  278.     }
  279.     public function getWorkCenter(): ?string
  280.     {
  281.         return $this->work_center;
  282.     }
  283.     public function setWorkCenter(string $work_center): self
  284.     {
  285.         $this->work_center $work_center;
  286.         return $this;
  287.     }
  288.     public function getPhone(): ?string
  289.     {
  290.         return $this->phone;
  291.     }
  292.     public function setPhone(string $phone): self
  293.     {
  294.         $this->phone $phone;
  295.         return $this;
  296.     }
  297.     public function getCreatedAt(): ?\DateTimeInterface
  298.     {
  299.         return $this->created_at;
  300.     }
  301.     public function getUpdatedAt(): ?\DateTimeInterface
  302.     {
  303.         return $this->updated_at;
  304.     }
  305.     /**
  306.      * Set the value of updatedAt
  307.      *
  308.      * @param \DateTime $updatedAt
  309.      */
  310.     public function markAsUpdated() : void
  311.     {
  312.         $this->updated_at = new \DateTime();
  313.     }
  314.     public function getAcceptTerms(): ?bool
  315.     {
  316.         return $this->accept_terms;
  317.     }
  318.     public function setAcceptTerms(bool $accept_terms): self
  319.     {
  320.         $this->accept_terms $accept_terms;
  321.         return $this;
  322.     }
  323.     public function getAcceptedAt(): ?\DateTimeInterface
  324.     {
  325.         return $this->accepted_at;
  326.     }
  327.     public function setAcceptedAt(?\DateTimeInterface $accepted_at): self
  328.     {
  329.         $this->accepted_at $accepted_at;
  330.         return $this;
  331.     }
  332.     public function getActive(): ?bool
  333.     {
  334.         return $this->active;
  335.     }
  336.     public function setActive(bool $active): self
  337.     {
  338.         $this->active $active;
  339.         return $this;
  340.     }
  341.     public function isVerified(): bool
  342.     {
  343.         return $this->isVerified;
  344.     }
  345.     public function setIsVerified(bool $isVerified): self
  346.     {
  347.         $this->isVerified $isVerified;
  348.         return $this;
  349.     }
  350.     public function getCompany(): ?Company
  351.     {
  352.         return $this->company;
  353.     }
  354.     public function setCompany(?Company $company): self
  355.     {
  356.         $this->company $company;
  357.         return $this;
  358.     }
  359.     public function getSurname(): ?string
  360.     {
  361.         return $this->surname;
  362.     }
  363.     public function setSurname(string $surname): self
  364.     {
  365.         $this->surname $surname;
  366.         return $this;
  367.     }
  368.     public function getRef(): ?string
  369.     {
  370.         return $this->ref;
  371.     }
  372.     public function setRef(string $ref): self
  373.     {
  374.         $ref++;
  375.         $this->ref $ref;
  376.         return $this;
  377.     }
  378.     public function getSupplier(): ?Supplier
  379.     {
  380.         return $this->supplier;
  381.     }
  382.     public function setSupplier(?Supplier $supplier): self
  383.     {
  384.         $this->supplier $supplier;
  385.         return $this;
  386.     }
  387.     public function getType(): ?int
  388.     {
  389.         return $this->type;
  390.     }
  391.     public function setType(int $type): self
  392.     {
  393.         $this->type $type;
  394.         return $this;
  395.     }
  396.     /**
  397.      * @return Collection<int, OrderMessage>
  398.      */
  399.     public function getOrderMessages(): Collection
  400.     {
  401.         return $this->orderMessages;
  402.     }
  403.     public function addOrderMessage(OrderMessage $orderMessage): self
  404.     {
  405.         if (!$this->orderMessages->contains($orderMessage)) {
  406.             $this->orderMessages[] = $orderMessage;
  407.             $orderMessage->setUser($this);
  408.         }
  409.         return $this;
  410.     }
  411.     public function removeOrderMessage(OrderMessage $orderMessage): self
  412.     {
  413.         if ($this->orderMessages->removeElement($orderMessage)) {
  414.             // set the owning side to null (unless already changed)
  415.             if ($orderMessage->getUser() === $this) {
  416.                 $orderMessage->setUser(null);
  417.             }
  418.         }
  419.         return $this;
  420.     }
  421.     /**
  422.      * @return Collection<int, Equipment>
  423.      */
  424.     public function getEquipment(): Collection
  425.     {
  426.         return $this->equipment;
  427.     }
  428.     public function addEquipment(Equipment $equipment): self
  429.     {
  430.         if (!$this->equipment->contains($equipment)) {
  431.             $this->equipment[] = $equipment;
  432.             $equipment->setUser($this);
  433.         }
  434.         return $this;
  435.     }
  436.     public function removeEquipment(Equipment $equipment): self
  437.     {
  438.         if ($this->equipment->removeElement($equipment)) {
  439.             // set the owning side to null (unless already changed)
  440.             if ($equipment->getUser() === $this) {
  441.                 $equipment->setUser(null);
  442.             }
  443.         }
  444.         return $this;
  445.     }
  446.     public function getPhoto(): ?string
  447.     {
  448.         return $this->photo;
  449.     }
  450.     public function setPhoto(?string $photo): self
  451.     {
  452.         $this->photo $photo;
  453.         return $this;
  454.     }
  455.     /**
  456.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  457.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  458.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  459.      * must be able to accept an instance of 'File' as the bundle will inject one here
  460.      * during Doctrine hydration.
  461.      *
  462.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
  463.      */
  464.     public function setPhotoFile(?File $photoFile null): void
  465.     {
  466.         $this->photoFile $photoFile;
  467.         if (null !== $photoFile) {
  468.             // It is required that at least one field changes if you are using doctrine
  469.             // otherwise the event listeners won't be called and the file is lost
  470.             $this->markAsUpdated();
  471.         }
  472.     }
  473.     public function getPhotoFile(): ?File
  474.     {
  475.         return $this->photoFile;
  476.     }
  477.     public function getNotificationsConfig(): ?NotificationsConfig
  478.     {
  479.         return $this->notifications_config;
  480.     }
  481.     public function setNotificationsConfig(?NotificationsConfig $notifications_config): self
  482.     {
  483.         $this->notifications_config $notifications_config;
  484.         return $this;
  485.     }
  486.     public function getCompanyClient(): ?CompanyClient
  487.     {
  488.         return $this->company_client;
  489.     }
  490.     public function setCompanyClient(?CompanyClient $company_client): self
  491.     {
  492.         $this->company_client $company_client;
  493.         return $this;
  494.     }
  495. }