src/Entity/User.php line 67
<?phpnamespace App\Entity;use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;use Ramsey\Uuid\Uuid;use App\Trait\UuidTrait;use ApiPlatform\Metadata\Get;use ApiPlatform\Metadata\Put;use ApiPlatform\Metadata\Post;use Doctrine\DBAL\Types\Types;use ApiPlatform\Metadata\Patch;use ApiPlatform\Metadata\Delete;use Doctrine\ORM\Mapping as ORM;use App\State\UserPasswordHasher;use App\Repository\UserRepository;use ApiPlatform\Metadata\ApiFilter;use ApiPlatform\Metadata\ApiProperty;use ApiPlatform\Metadata\ApiResource;use App\Controller\CurrentController;use ApiPlatform\Metadata\GetCollection;use Doctrine\Common\Collections\Collection;use App\Controller\ChangeMainEmpresaController;use Doctrine\Common\Collections\ArrayCollection;use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;use Symfony\Component\Serializer\Annotation\Groups;use Symfony\Component\Validator\Constraints as Assert;use Symfony\Component\Security\Core\User\UserInterface;use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;#[ApiResource(operations: [new GetCollection(uriTemplate: 'usuarios'),new GetCollection(uriTemplate: 'current',controller: CurrentController::class,output: User::class,paginationEnabled: false,),new Post(uriTemplate: 'usuarios', processor: UserPasswordHasher::class, validationContext: ['groups' => ['Default', 'user:create']], denormalizationContext: ['groups' => ['user:create']]),new Get(uriTemplate: 'usuarios/{uuid}'),new Put(uriTemplate: 'usuarios/{uuid}', processor: UserPasswordHasher::class, denormalizationContext: ['groups' => ['user:update']]),new Put(uriTemplate: 'usuarios/{uuid}/cambioEmpresa', denormalizationContext: ['groups' => ['user:changeEmpresa']], controller: ChangeMainEmpresaController::class, security: "is_granted('ROLE_ADMIN_GROUP')"),new Patch(uriTemplate: 'usuarios/{uuid}', processor: UserPasswordHasher::class, denormalizationContext: ['groups' => ['user:update']]),new Delete(uriTemplate: 'usuarios/{uuid}'),],normalizationContext: ['groups' => ['user:read', 'uuid']],)]#[ORM\Entity(repositoryClass: UserRepository::class)]#[ORM\Table(name: '`user`')]#[ApiFilter(SearchFilter::class,properties: ['username' => 'exact','nombre' => 'exact','apellido1' => 'exact','apellido2' => 'exact','nif' => 'exact','codigo' => 'exact','tipo' => 'exact','isActivo' => 'exact','emails.direccion' => 'exact'])]#[ApiFilter(OrderFilter::class, properties: ['nombre', 'codigo', 'emails.direccion', 'telefonos.numero'])]class User implements UserInterface, PasswordAuthenticatedUserInterface{use UuidTrait;public const MODULO = 'users';public const TIPO_CLIENTE = 'cliente';public const TIPO_EVALUADOR = 'evaluador';public const TIPO_ADMIN = 'administrador';public const TIPO_ADMIN_GROUP = 'administradorGrupo';public const USER_CREATED = 'user.created';public const USER_UPDATED = 'user.updated';public const USER_DELETED = 'user.deleted';#[Assert\NotBlank(groups: ['user:create'])]#[Groups(['user:read', 'user:create', 'user:update', 'sesion:read'])]#[ORM\Column(length: 180, unique: true)]private ?string $username = null;#[Groups(['user:read', 'user:create', 'user:update'])]#[ORM\Column]private array $roles = [];#[ORM\Column]private ?string $password = null;#[Assert\NotBlank(groups: ['user:create'])]#[Groups(['user:create', 'user:update'])]private ?string $plainPassword = null;#[Groups(['user:read', 'user:create', 'user:update', 'sesion:read'])]#[ORM\Column(length: 255, nullable: true)]private ?string $codigo = null;#[Groups(['user:read', 'user:create', 'user:update', 'sesion:read'])]#[ORM\Column(length: 255, nullable: true)]private ?string $nombre = null;#[Groups(['user:read', 'user:create', 'user:update', 'sesion:read'])]#[ORM\Column(length: 255, nullable: true)]private ?string $apellido1 = null;#[Groups(['user:read', 'user:create', 'user:update', 'sesion:read'])]#[ORM\Column(length: 255, nullable: true)]private ?string $apellido2 = null;#[Groups(['user:read', 'user:create', 'user:update'])]#[ORM\Column(length: 255, nullable: true)]private ?string $cp = null;#[Groups(['user:read', 'user:create', 'user:update'])]#[ORM\Column(type: Types::TEXT, nullable: true)]private ?string $observaciones = null;#[Groups(['user:read', 'user:create', 'user:update', 'sesion:read'])]#[ORM\Column(length: 255, nullable: true)]private ?string $nif = null;#[Groups(['user:read', 'user:update'])]#[ORM\Column()]private bool $isActivo = true;#[Groups(['user:read', 'user:create', 'user:update', 'sesion:read'])]#[ORM\Column(nullable: true)]private ?string $descripcion = null;#[Groups(['user:read', 'user:create', 'user:update', 'sesion:read'])]#[ORM\Column(length: 255)]private ?string $tipo = null;#[Groups(['user:read', 'user:create', 'user:update'])]#[ORM\OneToMany(mappedBy: 'user', targetEntity: Email::class, orphanRemoval: true, cascade: ['persist', 'remove'])]private Collection $emails;#[Groups(['user:read', 'user:create', 'user:update'])]#[ORM\OneToMany(mappedBy: 'user', targetEntity: Telefono::class, orphanRemoval: true, cascade: ['persist', 'remove'])]private Collection $telefonos;#[Groups(['user:read', 'user:create', 'user:update'])]#[ORM\OneToMany(mappedBy: 'user', targetEntity: Direccion::class, orphanRemoval: true, cascade: ['persist', 'remove'])]private Collection $direcciones;#[Groups(['user:read', 'user:create', 'user:update'])]#[ORM\Column(length: 255, nullable: true)]private ?string $nombreRepresentante = null;#[Groups(['user:read', 'user:create', 'user:update'])]#[ORM\Column(length: 255, nullable: true)]private ?string $emailRepresentante = null;#[Groups(['user:read', 'user:create', 'user:update'])]#[ORM\Column(length: 255, nullable: true)]private ?string $telefonoRepresentante = null;#[Groups(['user:read', 'user:create', 'user:update'])]#[ORM\Column(length: 255, nullable: true)]private ?string $nifRepresentante = null;#[Groups(['user:read', 'user:create', 'user:update'])]#[ORM\Column(length: 255, nullable: true)]private ?string $cargoRepresentante = null;#[Groups(['user:read', 'user:create', 'user:update'])]#[ORM\Column(nullable: true)]private array $seguimiento = [];#[Groups(['user:read'])]#[ORM\ManyToOne(inversedBy: 'users')]private ?Empresa $empresa = null;#[Assert\NotBlank(groups: ['user:changeEmpresa'])]#[Groups(['user:changeEmpresa'])]private ?Empresa $cambioEmpresa = null;#[Groups(['user:read'])]#[ORM\OneToMany(mappedBy: 'user', targetEntity: Notificacion::class, orphanRemoval: true)]private Collection $notificaciones;#[ORM\ManyToOne]#[Groups(['user:read', 'user:create', 'user:update'])]private ?GrupoEmpresa $grupoEmpresa = null;public function __construct(){$this->emails = new ArrayCollection();$this->telefonos = new ArrayCollection();$this->direcciones = new ArrayCollection();$this->uuid = Uuid::uuid4()->toString();$this->notificaciones = new ArrayCollection();}#[ApiProperty(security: "is_granted('ROLE_ADMIN_GROUP')")]#[Groups(['user:read'])]public function getEmpresasInGrupo(){if ($this->getEmpresa() === null || $this->getEmpresa()->getGrupoEmpresa() === null) {return [];}return array_map(function ($empresa) {return ['uuid' => $empresa->getUuid(),'nombre' => $empresa->getNombre()];}, $this->getEmpresa()->getGrupoEmpresa()->getEmpresas()->toArray());}#[Groups(['user:read'])]public function getNombreCompleto(): string{return trim($this->nombre . ' ' . $this->apellido1 . ' ' . $this->apellido2);}#[Groups(['user:read'])]public function getNombreCompletoRepresentante(): string{return $this->nombreRepresentante . ' ' . $this->apellido1 . ' ' . $this->apellido2;}public function getUsername(): ?string{return $this->username;}public function setUsername(string $username): self{$this->username = $username;return $this;}/*** A visual identifier that represents this user.** @see UserInterface*/public function getUserIdentifier(): string{return (string) $this->username;}/*** @see UserInterface*/public function getRoles(): array{$roles = $this->roles;// guarantee every user at least has ROLE_USER$roles[] = 'ROLE_USER';return array_unique($roles);}public function setRoles(array $roles): self{$this->roles = $roles;return $this;}/*** @see PasswordAuthenticatedUserInterface*/public function getPassword(): string{return $this->password;}public function setPassword(string $password): self{$this->password = $password;return $this;}/*** @see UserInterface*/public function eraseCredentials(){// If you store any temporary, sensitive data on the user, clear it here$this->plainPassword = null;$this->cambioEmpresa = null;}public function getCodigo(): ?string{return $this->codigo;}public function setCodigo(?string $codigo): self{$this->codigo = $codigo;return $this;}public function getNombre(): ?string{return $this->nombre;}public function setNombre(?string $nombre): self{$this->nombre = $nombre;return $this;}public function getApellido1(): ?string{return $this->apellido1;}public function setApellido1(?string $apellido1): self{$this->apellido1 = $apellido1;return $this;}public function getApellido2(): ?string{return $this->apellido2;}public function setApellido2(?string $apellido2): self{$this->apellido2 = $apellido2;return $this;}public function getCp(): ?string{return $this->cp;}public function setCp(?string $cp): self{$this->cp = $cp;return $this;}public function getObservaciones(): ?string{return $this->observaciones;}public function setObservaciones(?string $observaciones): self{$this->observaciones = $observaciones;return $this;}public function getNif(): ?string{return $this->nif;}public function setNif(?string $nif): self{$this->nif = $nif;return $this;}public function isIsActivo(): ?bool{return $this->isActivo;}public function setIsActivo(?bool $isActivo): self{$this->isActivo = $isActivo;return $this;}public function getDescripcion(): string{return $this->descripcion;}public function setDescripcion(?string $descripcion): self{$this->descripcion = $descripcion;return $this;}public function getPlainPassword(): ?string{return $this->plainPassword;}public function setPlainPassword(?string $plainPassword): self{$this->plainPassword = $plainPassword;return $this;}public function getTipo(): ?string{return $this->tipo;}public function setTipo(string $tipo): self{$this->tipo = $tipo;return $this;}/*** @return Collection<int, Email>*/public function getEmails(): Collection{return $this->emails;}public function addEmail(Email $email): self{if (!$this->emails->contains($email)) {$this->emails->add($email);$email->setUser($this);}return $this;}public function removeEmail(Email $email): self{if ($this->emails->removeElement($email)) {// set the owning side to null (unless already changed)if ($email->getUser() === $this) {$email->setUser(null);}}return $this;}/*** @return Collection<int, Telefono>*/public function getTelefonos(): Collection{return $this->telefonos;}public function addTelefono(Telefono $telefono): self{if (!$this->telefonos->contains($telefono)) {$this->telefonos->add($telefono);$telefono->setUser($this);}return $this;}public function removeTelefono(Telefono $telefono): self{if ($this->telefonos->removeElement($telefono)) {// set the owning side to null (unless already changed)if ($telefono->getUser() === $this) {$telefono->setUser(null);}}return $this;}/*** @return Collection<int, Direccion>*/public function getDirecciones(): Collection{return $this->direcciones;}public function addDireccione(Direccion $direccione): self{if (!$this->direcciones->contains($direccione)) {$this->direcciones->add($direccione);$direccione->setUser($this);}return $this;}public function removeDireccione(Direccion $direccione): self{if ($this->direcciones->removeElement($direccione)) {// set the owning side to null (unless already changed)if ($direccione->getUser() === $this) {$direccione->setUser(null);}}return $this;}public function getNombreRepresentante(): ?string{return $this->nombreRepresentante;}public function setNombreRepresentante(?string $nombreRepresentante): self{$this->nombreRepresentante = $nombreRepresentante;return $this;}public function getEmailRepresentante(): ?string{return $this->emailRepresentante;}public function setEmailRepresentante(?string $emailRepresentante): self{$this->emailRepresentante = $emailRepresentante;return $this;}public function getTelefonoRepresentante(): ?string{return $this->telefonoRepresentante;}public function setTelefonoRepresentante(?string $telefonoRepresentante): self{$this->telefonoRepresentante = $telefonoRepresentante;return $this;}public function getNifRepresentante(): ?string{return $this->nifRepresentante;}public function setNifRepresentante(?string $nifRepresentante): self{$this->nifRepresentante = $nifRepresentante;return $this;}public function getCargoRepresentante(): ?string{return $this->cargoRepresentante;}public function setCargoRepresentante(?string $cargoRepresentante): self{$this->cargoRepresentante = $cargoRepresentante;return $this;}public function getSeguimiento(): array{return $this->seguimiento;}public function setSeguimiento(?array $seguimiento): self{$this->seguimiento = $seguimiento;return $this;}public function getEmpresa(): ?Empresa{return $this->empresa;}public function setEmpresa(?Empresa $empresa): self{$this->empresa = $empresa;return $this;}public function getCambioEmpresa(): ?Empresa{return $this->cambioEmpresa;}public function setCambioEmpresa(?Empresa $cambioEmpresa): self{$this->cambioEmpresa = $cambioEmpresa;return $this;}/*** @return Collection<int, Notificacion>*/public function getNotificaciones(): Collection{return $this->notificaciones;}public function addNotificacione(Notificacion $notificacione): self{if (!$this->notificaciones->contains($notificacione)) {$this->notificaciones->add($notificacione);$notificacione->setUser($this);}return $this;}public function removeNotificacione(Notificacion $notificacione): self{if ($this->notificaciones->removeElement($notificacione)) {// set the owning side to null (unless already changed)if ($notificacione->getUser() === $this) {$notificacione->setUser(null);}}return $this;}public function getGrupoEmpresa(): ?GrupoEmpresa{return $this->grupoEmpresa;}public function setGrupoEmpresa(?GrupoEmpresa $grupoEmpresa): static{$this->grupoEmpresa = $grupoEmpresa;return $this;}}