src/Entity/ValoracionesRelojes.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as JMS;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\ValoracionesRelojesRepository")
  11.  * @ORM\Table(name="valoraciones_relojes",
  12.  *     indexes={
  13.  *         @ORM\Index(name="idx_vrelojes_type_deleted", columns={"type", "deleted_at", "valoracion_id"})
  14.  *     }
  15.  * )
  16.  * @ORM\InheritanceType("SINGLE_TABLE")
  17.  * @ORM\DiscriminatorColumn(name="type", type="string")
  18.  * @ORM\DiscriminatorMap({"stock":"App\Entity\ValoracionesRelojesStock","sinstock":"App\Entity\ValoracionesRelojesSinStock"})
  19.  * @ORM\EntityListeners({"App\EntityListener\ValoracionesRelojes\CalcularIDPerseoListener"})
  20.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  21.  * @JMS\Discriminator(
  22.  *      field = "type",
  23.  *      map = {
  24.  *          "stock" = "App\Entity\ValoracionesRelojesStock",
  25.  *          "sinstock" = "App\Entity\ValoracionesRelojesSinStock"
  26.  *      }
  27.  *  )
  28.  */
  29. Abstract class ValoracionesRelojes
  30. {
  31.     /**
  32.      * @ORM\Id
  33.      * @ORM\Column(type="bigint")
  34.      * @ORM\GeneratedValue(strategy="AUTO")
  35.      * @JMS\Groups({"api_v1_valoracion_serialize"})
  36.      */
  37.     protected $id;
  38.     /**
  39.      * @ORM\Column(
  40.      *     type="string",
  41.      *     unique=true,
  42.      *     nullable=true,
  43.      *     name="id_perseo",
  44.      *     options={"comment":"Identificador de perseo único generado aleatoriamente combinación letras y números"}
  45.      * )
  46.      * @JMS\Groups({"api_v1_valoracion_serialize"})
  47.      */
  48.     protected $IDperseo;
  49.     /**
  50.      * @ORM\Column(type="text", nullable=true, name="info_valoracion_compra", options={"default":NULL})
  51.      * @JMS\Groups({
  52.      *      "api_v1_valoracion_serialize",
  53.      *      "api_v1_valoracionrelojcompra_deserialize"
  54.      *  })
  55.      */
  56.     protected $infoValoracion;
  57.     /**
  58.      * @ORM\Column(type="boolean", nullable=true, name="is_precio_chrono24", options={"default":0})
  59.      */
  60.     protected $isPrecioChrono24;
  61.     /**
  62.      * @ORM\Column(type="datetime", nullable=true, name="deleted_at")
  63.      * @JMS\Groups({"api_v1_valoracion_serialize"})
  64.      */
  65.     protected $deletedAt;
  66.     /**
  67.      * @ORM\Column(type="datetime", nullable=false, name="updated_at", options={"default":"2022-01-01 00:00:00"})
  68.      * @Gedmo\Timestampable(on="update")
  69.      */
  70.     protected $updatedAt;
  71.     /**
  72.      * @ORM\Column(type="datetime", nullable=false, name="created_at", options={"default":"2022-01-01 00:00:00"})
  73.      * @Gedmo\Timestampable(on="create")
  74.      */
  75.     protected $createdAt;
  76.     /**
  77.      * @ORM\OneToMany(targetEntity=\App\Entity\ValoracionesRelojes::class, mappedBy="clone")
  78.      */
  79.     protected $clones;
  80.     /**
  81.      * @ORM\ManyToOne(targetEntity="App\Entity\Valoracion", inversedBy="valoracionesRelojes", cascade={"persist"})
  82.      * @ORM\JoinColumn(name="valoracion_id", referencedColumnName="id")
  83.      */
  84.     protected $valoracion;
  85.     /**
  86.      * @ORM\ManyToOne(targetEntity="App\Entity\Reloj", inversedBy="valoracionesRelojes", cascade={"persist"})
  87.      * @ORM\JoinColumn(name="reloj_id", referencedColumnName="id")
  88.      * @JMS\Type(Reloj::class)
  89.      * @JMS\Groups({
  90.      *      "api_v1_valoracion_serialize",
  91.      *      "api_v1_valoracionrelojventa_deserialize"
  92.      *  })
  93.      */
  94.     protected $reloj;
  95.     /**
  96.      * @ORM\ManyToOne(targetEntity=\App\Entity\ValoracionesRelojes::class, inversedBy="clones")
  97.      * @ORM\JoinColumn(name="clone_id", referencedColumnName="id")
  98.      */
  99.     protected $clone;
  100.     public function __construct()
  101.     {
  102.         $this->clones = new ArrayCollection();
  103.     }
  104.     public function __clone(): void
  105.     {
  106.         $this->setCreatedAt(new DateTime('now'));
  107.         $this->setUpdatedAt(new DateTime('now'));
  108.         if($this instanceof ValoracionesRelojesSinStock) {
  109.             $this->setRelojInventario(null);
  110.             $costes $this->getCostes();
  111.             foreach ($costes as $coste) {
  112.                 $costeClone = clone $coste;
  113.                 $this->addCoste($costeClone);
  114.             }
  115.             $referencias $this->getReferencias();
  116.             foreach ($referencias as $referencia) {
  117.                 $referenciaClone = clone $referencia;
  118.                 $this->addReferencia($referenciaClone);
  119.             }
  120.         }
  121.     }
  122.     public function __toString(): string
  123.     {
  124.         return $this->getId()??'---';
  125.     }
  126.     public function getId(): ?int
  127.     {
  128.         return $this->id;
  129.     }
  130.     public function getDeletedAt(): ?\DateTimeInterface
  131.     {
  132.         return $this->deletedAt;
  133.     }
  134.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  135.     {
  136.         $this->deletedAt $deletedAt;
  137.         return $this;
  138.     }
  139.     public function getUpdatedAt(): ?\DateTimeInterface
  140.     {
  141.         return $this->updatedAt;
  142.     }
  143.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  144.     {
  145.         $this->updatedAt $updatedAt;
  146.         return $this;
  147.     }
  148.     public function getCreatedAt(): ?\DateTimeInterface
  149.     {
  150.         return $this->createdAt;
  151.     }
  152.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  153.     {
  154.         $this->createdAt $createdAt;
  155.         return $this;
  156.     }
  157.     public function getValoracion(): ?Valoracion
  158.     {
  159.         return $this->valoracion;
  160.     }
  161.     public function setValoracion(?Valoracion $valoracion): self
  162.     {
  163.         $this->valoracion $valoracion;
  164.         return $this;
  165.     }
  166.     public function getReloj(): ?Reloj
  167.     {
  168.         return $this->reloj;
  169.     }
  170.     public function setReloj(?Reloj $reloj): self
  171.     {
  172.         $this->reloj $reloj;
  173.         return $this;
  174.     }
  175.     public function getInfoValoracion(): ?string
  176.     {
  177.         return $this->infoValoracion;
  178.     }
  179.     public function setInfoValoracion(?string $infoValoracion): self
  180.     {
  181.         $this->infoValoracion $infoValoracion;
  182.         return $this;
  183.     }
  184.     public function getIDperseo(): ?string
  185.     {
  186.         return $this->IDperseo;
  187.     }
  188.     public function setIDperseo(string $IDperseo): self
  189.     {
  190.         $this->IDperseo $IDperseo;
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return Collection|Valoracion[]
  195.      */
  196.     public function getClones(): Collection
  197.     {
  198.         return $this->clones;
  199.     }
  200.     public function addClone(Valoracion $clone): self
  201.     {
  202.         if (!$this->clones->contains($clone)) {
  203.             $this->clones[] = $clone;
  204.             $clone->setClone($this);
  205.         }
  206.         return $this;
  207.     }
  208.     public function removeClone(Valoracion $clone): self
  209.     {
  210.         if ($this->clones->removeElement($clone)) {
  211.             // set the owning side to null (unless already changed)
  212.             if ($clone->getClone() === $this) {
  213.                 $clone->setClone(null);
  214.             }
  215.         }
  216.         return $this;
  217.     }
  218.     public function getClone(): ?self
  219.     {
  220.         return $this->clone;
  221.     }
  222.     public function setClone(?self $clone): self
  223.     {
  224.         $this->clone $clone;
  225.         return $this;
  226.     }
  227.     public function getRelojMarca(): ?Marca
  228.     {
  229.         if ($this instanceof ValoracionesRelojesSinStock) {
  230.             return $this->getRelojMarca();
  231.         }
  232.         if ($this instanceof ValoracionesRelojesStock) {
  233.             return $this->getReloj()?->getMarca();
  234.         }
  235.         return null;
  236.     }
  237.     public function getRelojModelo1(): ?string
  238.     {
  239.         if ($this instanceof ValoracionesRelojesSinStock) {
  240.             return $this->getRelojModelo1();
  241.         }
  242.         if ($this instanceof ValoracionesRelojesStock) {
  243.             return $this->getReloj()?->getModelo1();
  244.         }
  245.         return null;
  246.     }
  247.     public function getRelojRef1(): ?string
  248.     {
  249.         if ($this instanceof ValoracionesRelojesSinStock) {
  250.             return $this->getRelojRef1();
  251.         }
  252.         if ($this instanceof ValoracionesRelojesStock) {
  253.             return $this->getReloj()?->getRef1();
  254.         }
  255.         return null;
  256.     }
  257.     public function getMargenDeseado(): ?float
  258.     {
  259.         if ($this instanceof ValoracionesRelojesSinStock) {
  260.             return $this->getMargenDeseado();
  261.         }
  262.         if ($this instanceof ValoracionesRelojesStock) {
  263.             return $this->getReloj()?->getMargenDeseado();
  264.         }
  265.         return null;
  266.     }
  267.     public function getPrecioPagar(): ?float
  268.     {
  269.         if ($this instanceof ValoracionesRelojesSinStock) {
  270.             return $this->getprecioPagar();
  271.         }
  272.         if ($this instanceof ValoracionesRelojesStock) {
  273.             return $this->getReloj()?->getPrecioPagar();
  274.         }
  275.         return null;
  276.     }
  277. }