src/Entity/Usuario.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as JMS;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. /**
  10.  * @ORM\Table(name="usuario")
  11.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  12.  * @ORM\Entity(repositoryClass="App\Repository\UsuarioRepository")
  13.  */
  14. class Usuario
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\Column(type="bigint", options={"unsigned":true})
  19.      * @ORM\GeneratedValue(strategy="AUTO")
  20.      * @JMS\Groups({
  21.      *     "api_v1_usuario_serialize",
  22.      *     "api_v1_valoracion_serialize",
  23.      *     "api_v1_operacion_show_serialize"
  24.      *     })
  25.      */
  26.     protected $id;
  27.     /**
  28.      * @ORM\Column(type="string", unique=true, length=5, nullable=false, name="id_perseo")
  29.      * @JMS\Groups({
  30.      *      "api_v1_usuario_serialize",
  31.      *      "api_v1_valoracion_serialize"
  32.      *      })
  33.      */
  34.     protected $IDperseo;
  35.     /**
  36.      * @ORM\Column(type="string", nullable=true)
  37.      */
  38.     protected $avatar;
  39.     /**
  40.      * @ORM\Column(type="datetime", nullable=true, name="deleted_at")
  41.      * @JMS\Groups({
  42.      *      "api_v1_usuario_serialize",
  43.      *      "api_v1_valoracion_serialize",
  44.      *      "api_v1_operacion_show_serialize"
  45.      *      })
  46.      */
  47.     protected $deletedAt;
  48.     /**
  49.      * @ORM\Column(type="datetime", nullable=false, name="updated_at", options={"default":"2022-01-01 00:00:00"})
  50.      * @Gedmo\Timestampable(on="update")
  51.      */
  52.     protected $updatedAt;
  53.     /**
  54.      * @ORM\Column(type="datetime", nullable=false, name="created_at", options={"default":"2022-01-01 00:00:00"})
  55.      * @Gedmo\Timestampable(on="create")
  56.      */
  57.     protected $createdAt;
  58.     /**
  59.      * @ORM\OneToOne(targetEntity="App\Entity\User", mappedBy="usuario", cascade={"persist"})
  60.      * @JMS\Type(User::class)
  61.      * @JMS\Groups({
  62.      *      "api_v1_usuario_serialize",
  63.      *      "api_v1_valoracion_serialize",
  64.      *      "api_v1_operacion_show_serialize"
  65.      *      })
  66.      */
  67.     protected $user;
  68.     /**
  69.      * @ORM\OneToOne(targetEntity="App\Entity\UnidadNegocio", mappedBy="responsable")
  70.      */
  71.     protected $unidadNegocioResponsable;
  72.     /**
  73.      * @ORM\OneToMany(targetEntity="App\Entity\Valoracion", mappedBy="usuario")
  74.      */
  75.     protected $valoraciones;
  76.     /**
  77.      * @ORM\OneToMany(targetEntity=\App\Entity\ActividadAbstract::class, mappedBy="usuario")
  78.      */
  79.     private $actividades;
  80.     /**
  81.      * @ORM\OneToMany(targetEntity="App\Entity\Operacion", mappedBy="usuario")
  82.      */
  83.     protected $operaciones;
  84.     /**
  85.      * @ORM\ManyToOne(targetEntity="App\Entity\UnidadNegocio", inversedBy="usuarios")
  86.      * @ORM\JoinColumn(name="unidad_negocio_id", referencedColumnName="id")
  87.      * @JMS\Type(UnidadNegocio::class)
  88.      * @JMS\Groups({
  89.      *       "api_v1_usuario_serialize"
  90.      *       })
  91.      */
  92.     protected $unidadNegocio;
  93.     /**
  94.      * @ORM\ManyToMany(targetEntity="App\Entity\UnidadNegocio", mappedBy="comerciales")
  95.      */
  96.     protected $unidadesNegocioComercial;
  97.     public function __construct()
  98.     {
  99.         $this->user = new User();
  100.         $this->valoraciones = new ArrayCollection();
  101.         $this->unidadesNegocioComercial = new ArrayCollection();
  102.         $this->operaciones = new ArrayCollection();
  103.         $this->actividades = new ArrayCollection();
  104.     }
  105.     public function __toString(): string
  106.     {
  107.         return $this->getUser()?->getNombreCompleto()??$this->getUser()?->getUserIdentifier();
  108.     }
  109.     public function getId(): ?string
  110.     {
  111.         return $this->id;
  112.     }
  113.     public function getIDperseo(): ?string
  114.     {
  115.         return $this->IDperseo;
  116.     }
  117.     public function setIDperseo(string $IDperseo): self
  118.     {
  119.         $this->IDperseo $IDperseo;
  120.         return $this;
  121.     }
  122.     public function getAvatar(): ?string
  123.     {
  124.         return $this->avatar;
  125.     }
  126.     public function setAvatar(?string $avatar): self
  127.     {
  128.         $this->avatar $avatar;
  129.         return $this;
  130.     }
  131.     public function getDeletedAt(): ?\DateTimeInterface
  132.     {
  133.         return $this->deletedAt;
  134.     }
  135.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  136.     {
  137.         $this->deletedAt $deletedAt;
  138.         return $this;
  139.     }
  140.     public function getUpdatedAt(): ?\DateTimeInterface
  141.     {
  142.         return $this->updatedAt;
  143.     }
  144.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  145.     {
  146.         $this->updatedAt $updatedAt;
  147.         return $this;
  148.     }
  149.     public function getCreatedAt(): ?\DateTimeInterface
  150.     {
  151.         return $this->createdAt;
  152.     }
  153.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  154.     {
  155.         $this->createdAt $createdAt;
  156.         return $this;
  157.     }
  158.     public function getUser(): ?User
  159.     {
  160.         return $this->user;
  161.     }
  162.     public function setUser(?User $user): self
  163.     {
  164.         // unset the owning side of the relation if necessary
  165.         if ($user === null && $this->user !== null) {
  166.             $this->user->setUsuario(null);
  167.         }
  168.         // set the owning side of the relation if necessary
  169.         if ($user !== null && $user->getUsuario() !== $this) {
  170.             $user->setUsuario($this);
  171.         }
  172.         $this->user $user;
  173.         return $this;
  174.     }
  175.     public function getUnidadNegocioResponsable(): ?UnidadNegocio
  176.     {
  177.         return $this->unidadNegocioResponsable;
  178.     }
  179.     public function setUnidadNegocioResponsable(?UnidadNegocio $unidadNegocioResponsable): self
  180.     {
  181.         // unset the owning side of the relation if necessary
  182.         if ($unidadNegocioResponsable === null && $this->unidadNegocioResponsable !== null) {
  183.             $this->unidadNegocioResponsable->setResponsable(null);
  184.         }
  185.         // set the owning side of the relation if necessary
  186.         if ($unidadNegocioResponsable !== null && $unidadNegocioResponsable->getResponsable() !== $this) {
  187.             $unidadNegocioResponsable->setResponsable($this);
  188.         }
  189.         $this->unidadNegocioResponsable $unidadNegocioResponsable;
  190.         return $this;
  191.     }
  192.     /**
  193.      * @return Collection|Valoracion[]
  194.      */
  195.     public function getValoraciones(): Collection
  196.     {
  197.         return $this->valoraciones;
  198.     }
  199.     public function addValoracione(Valoracion $valoracione): self
  200.     {
  201.         if (!$this->valoraciones->contains($valoracione)) {
  202.             $this->valoraciones[] = $valoracione;
  203.             $valoracione->setUsuario($this);
  204.         }
  205.         return $this;
  206.     }
  207.     public function removeValoracione(Valoracion $valoracione): self
  208.     {
  209.         if ($this->valoraciones->removeElement($valoracione)) {
  210.             // set the owning side to null (unless already changed)
  211.             if ($valoracione->getUsuario() === $this) {
  212.                 $valoracione->setUsuario(null);
  213.             }
  214.         }
  215.         return $this;
  216.     }
  217.     public function getUnidadNegocio(): ?UnidadNegocio
  218.     {
  219.         return $this->unidadNegocio;
  220.     }
  221.     public function setUnidadNegocio(?UnidadNegocio $unidadNegocio): self
  222.     {
  223.         $this->unidadNegocio $unidadNegocio;
  224.         return $this;
  225.     }
  226.     /**
  227.      * @return Collection|UnidadNegocio[]
  228.      */
  229.     public function getUnidadesNegocioComercial(): Collection
  230.     {
  231.         return $this->unidadesNegocioComercial;
  232.     }
  233.     public function addUnidadesNegocioComercial(UnidadNegocio $unidadesNegocioComercial): self
  234.     {
  235.         if (!$this->unidadesNegocioComercial->contains($unidadesNegocioComercial)) {
  236.             $this->unidadesNegocioComercial[] = $unidadesNegocioComercial;
  237.             $unidadesNegocioComercial->addComerciale($this);
  238.         }
  239.         return $this;
  240.     }
  241.     public function removeUnidadesNegocioComercial(UnidadNegocio $unidadesNegocioComercial): self
  242.     {
  243.         if ($this->unidadesNegocioComercial->removeElement($unidadesNegocioComercial)) {
  244.             $unidadesNegocioComercial->removeComerciale($this);
  245.         }
  246.         return $this;
  247.     }
  248.     /**
  249.      * @return Collection|Operacion[]
  250.      */
  251.     public function getOperaciones(): Collection
  252.     {
  253.         return $this->operaciones;
  254.     }
  255.     public function addOperacione(Operacion $operacione): self
  256.     {
  257.         if (!$this->operaciones->contains($operacione)) {
  258.             $this->operaciones[] = $operacione;
  259.             $operacione->setUsuario($this);
  260.         }
  261.         return $this;
  262.     }
  263.     public function removeOperacione(Operacion $operacione): self
  264.     {
  265.         if ($this->operaciones->removeElement($operacione)) {
  266.             // set the owning side to null (unless already changed)
  267.             if ($operacione->getUsuario() === $this) {
  268.                 $operacione->setUsuario(null);
  269.             }
  270.         }
  271.         return $this;
  272.     }
  273.     /**
  274.      * @return Collection<int, ActividadAbstract>
  275.      */
  276.     public function getActividades(): Collection
  277.     {
  278.         return $this->actividades;
  279.     }
  280.     public function addActividade(ActividadAbstract $actividade): static
  281.     {
  282.         if (!$this->actividades->contains($actividade)) {
  283.             $this->actividades->add($actividade);
  284.             $actividade->setUsuario($this);
  285.         }
  286.         return $this;
  287.     }
  288.     public function removeActividade(ActividadAbstract $actividade): static
  289.     {
  290.         if ($this->actividades->removeElement($actividade)) {
  291.             // set the owning side to null (unless already changed)
  292.             if ($actividade->getUsuario() === $this) {
  293.                 $actividade->setUsuario(null);
  294.             }
  295.         }
  296.         return $this;
  297.     }
  298. }