<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @Vich\Uploadable
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"user"})
*/
private $id;
/**
* @ORM\Column(type="string", length=100, unique=true)
* @Assert\NotBlank
* @Assert\Email()
* @Groups({"user"})
*/
private $email;
private $roles = [];
/**
* ROLE_ADMIN : Super usuario
* ROLE_CHIEF : Administrador cliente
* ROLE_USER : Usuario cliente
* ROLE_SUPPLIER_CHIEF : Administrador proveedor
* ROLE_SUPPLIER : Usuario proveedor
*
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Groups({"user"})
*/
private $role;
/**
* @var string The hashed password
* @ORM\Column(type="string", nullable=true)
*/
private $password;
/**
* @ORM\Column(type="string", length=100)
* @Assert\NotBlank
* @Groups({"user"})
*/
private $name;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $department;
/**
* @ORM\Column(type="string", length=100, nullable=true)
* @Assert\NotBlank()
*/
private $position;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $work_center;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\Column(type="datetime")
*/
private $updated_at;
/**
* @ORM\Column(type="boolean")
*/
private $accept_terms = false;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $accepted_at;
/**
* @ORM\Column(type="boolean")
*/
private $active = false;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="user")
* @ORM\JoinColumn(nullable=false)
* @Assert\NotBlank(groups={"RequiredUser"})
*/
private $company;
/**
* @ORM\Column(type="string", length=100)
* @Assert\NotBlank
*/
private $surname;
/**
* @ORM\Column(type="string", length=8, nullable=true)
*/
private $ref;
/**
* @ORM\ManyToOne(targetEntity=Supplier::class, inversedBy="user")
* @ORM\JoinColumn(onDelete="CASCADE")
*/
private $supplier;
/**
* Usuario de empresa OEM (1) ó SB (2)
*
* @ORM\Column(type="smallint")
*/
private $type;
/**
* @ORM\OneToMany(targetEntity=OrderMessage::class, mappedBy="user")
*/
private $orderMessages;
/**
* @ORM\OneToMany(targetEntity=Equipment::class, mappedBy="user")
*/
private $equipment;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $photo;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="user_file", fileNameProperty="photo")
* @Assert\File(
* maxSize = "2M",
* mimeTypes = {"image/jpeg","image/gif","image/png"},
* maxSizeMessage = "El tamaño máximo permitido del archivo es {{ limit }} MB.",
* mimeTypesMessage = "El tipo de archivo no es válido ({{ type }}). Tipos de archivo permitidos {{ types }}"
* )
*
* @var File|null
*/
private $photoFile;
/**
* @ORM\OneToOne(targetEntity=NotificationsConfig::class, cascade={"persist", "remove"})
*/
private $notifications_config;
/**
* @ORM\ManyToOne(targetEntity=CompanyClient::class)
* @ORM\JoinColumn(onDelete="CASCADE")
*/
private $company_client;
public function __construct()
{
$this->created_at = new \DateTime();
$this->markAsUpdated();
$this->orderMessages = new ArrayCollection();
$this->equipment = new ArrayCollection();
}
// Registra el método mágico para imprimir el nombre del estado, por ejemplo, California
public function __toString() {
return $this->name .' '. $this->surname;
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
}
public function getRole(): ?string
{
return $this->role;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
return array($this->role);
}
public function setRole($role)
{
if (!is_string($role)) {
throw new \InvalidArgumentException('Invalid role');
}
$this->role = $role;
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDepartment(): ?string
{
return $this->department;
}
public function setDepartment(?string $department): self
{
$this->department = $department;
return $this;
}
public function getPosition(): ?string
{
return $this->position;
}
public function setPosition(string $position): self
{
$this->position = $position;
return $this;
}
public function getWorkCenter(): ?string
{
return $this->work_center;
}
public function setWorkCenter(string $work_center): self
{
$this->work_center = $work_center;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
/**
* Set the value of updatedAt
*
* @param \DateTime $updatedAt
*/
public function markAsUpdated() : void
{
$this->updated_at = new \DateTime();
}
public function getAcceptTerms(): ?bool
{
return $this->accept_terms;
}
public function setAcceptTerms(bool $accept_terms): self
{
$this->accept_terms = $accept_terms;
return $this;
}
public function getAcceptedAt(): ?\DateTimeInterface
{
return $this->accepted_at;
}
public function setAcceptedAt(?\DateTimeInterface $accepted_at): self
{
$this->accepted_at = $accepted_at;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getSurname(): ?string
{
return $this->surname;
}
public function setSurname(string $surname): self
{
$this->surname = $surname;
return $this;
}
public function getRef(): ?string
{
return $this->ref;
}
public function setRef(string $ref): self
{
$ref++;
$this->ref = $ref;
return $this;
}
public function getSupplier(): ?Supplier
{
return $this->supplier;
}
public function setSupplier(?Supplier $supplier): self
{
$this->supplier = $supplier;
return $this;
}
public function getType(): ?int
{
return $this->type;
}
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
/**
* @return Collection<int, OrderMessage>
*/
public function getOrderMessages(): Collection
{
return $this->orderMessages;
}
public function addOrderMessage(OrderMessage $orderMessage): self
{
if (!$this->orderMessages->contains($orderMessage)) {
$this->orderMessages[] = $orderMessage;
$orderMessage->setUser($this);
}
return $this;
}
public function removeOrderMessage(OrderMessage $orderMessage): self
{
if ($this->orderMessages->removeElement($orderMessage)) {
// set the owning side to null (unless already changed)
if ($orderMessage->getUser() === $this) {
$orderMessage->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Equipment>
*/
public function getEquipment(): Collection
{
return $this->equipment;
}
public function addEquipment(Equipment $equipment): self
{
if (!$this->equipment->contains($equipment)) {
$this->equipment[] = $equipment;
$equipment->setUser($this);
}
return $this;
}
public function removeEquipment(Equipment $equipment): self
{
if ($this->equipment->removeElement($equipment)) {
// set the owning side to null (unless already changed)
if ($equipment->getUser() === $this) {
$equipment->setUser(null);
}
}
return $this;
}
public function getPhoto(): ?string
{
return $this->photo;
}
public function setPhoto(?string $photo): self
{
$this->photo = $photo;
return $this;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setPhotoFile(?File $photoFile = null): void
{
$this->photoFile = $photoFile;
if (null !== $photoFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->markAsUpdated();
}
}
public function getPhotoFile(): ?File
{
return $this->photoFile;
}
public function getNotificationsConfig(): ?NotificationsConfig
{
return $this->notifications_config;
}
public function setNotificationsConfig(?NotificationsConfig $notifications_config): self
{
$this->notifications_config = $notifications_config;
return $this;
}
public function getCompanyClient(): ?CompanyClient
{
return $this->company_client;
}
public function setCompanyClient(?CompanyClient $company_client): self
{
$this->company_client = $company_client;
return $this;
}
}