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.      * @JMS\Groups({"api_v1_valoracion_serialize"})
  75.      */
  76.     protected $createdAt;
  77.     /**
  78.      * @ORM\OneToMany(targetEntity=\App\Entity\ValoracionesRelojes::class, mappedBy="clone")
  79.      */
  80.     protected $clones;
  81.     /**
  82.      * @ORM\ManyToOne(targetEntity="App\Entity\Valoracion", inversedBy="valoracionesRelojes", cascade={"persist"})
  83.      * @ORM\JoinColumn(name="valoracion_id", referencedColumnName="id")
  84.      */
  85.     protected $valoracion;
  86.     /**
  87.      * @ORM\ManyToOne(targetEntity="App\Entity\Reloj", inversedBy="valoracionesRelojes", cascade={"persist"})
  88.      * @ORM\JoinColumn(name="reloj_id", referencedColumnName="id")
  89.      * @JMS\Type(Reloj::class)
  90.      * @JMS\Groups({
  91.      *      "api_v1_valoracion_serialize",
  92.      *      "api_v1_valoracionrelojventa_deserialize"
  93.      *  })
  94.      */
  95.     protected $reloj;
  96.     /**
  97.      * @ORM\ManyToOne(targetEntity=\App\Entity\ValoracionesRelojes::class, inversedBy="clones")
  98.      * @ORM\JoinColumn(name="clone_id", referencedColumnName="id")
  99.      */
  100.     protected $clone;
  101.     public function __construct()
  102.     {
  103.         $this->clones = new ArrayCollection();
  104.     }
  105.     public function __clone(): void
  106.     {
  107.         $this->setCreatedAt(new DateTime('now'));
  108.         $this->setUpdatedAt(new DateTime('now'));
  109.         if($this instanceof ValoracionesRelojesSinStock) {
  110.             $this->setRelojInventario(null);
  111.             $costes $this->getCostes();
  112.             foreach ($costes as $coste) {
  113.                 $costeClone = clone $coste;
  114.                 $this->addCoste($costeClone);
  115.             }
  116.             $referencias $this->getReferencias();
  117.             foreach ($referencias as $referencia) {
  118.                 $referenciaClone = clone $referencia;
  119.                 $this->addReferencia($referenciaClone);
  120.             }
  121.         }
  122.     }
  123.     public function __toString(): string
  124.     {
  125.         return $this->getId()??'---';
  126.     }
  127.     public function getId(): ?int
  128.     {
  129.         return $this->id;
  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 getValoracion(): ?Valoracion
  159.     {
  160.         return $this->valoracion;
  161.     }
  162.     public function setValoracion(?Valoracion $valoracion): self
  163.     {
  164.         $this->valoracion $valoracion;
  165.         return $this;
  166.     }
  167.     public function getReloj(): ?Reloj
  168.     {
  169.         return $this->reloj;
  170.     }
  171.     public function setReloj(?Reloj $reloj): self
  172.     {
  173.         $this->reloj $reloj;
  174.         return $this;
  175.     }
  176.     public function getInfoValoracion(): ?string
  177.     {
  178.         return $this->infoValoracion;
  179.     }
  180.     public function setInfoValoracion(?string $infoValoracion): self
  181.     {
  182.         $this->infoValoracion $infoValoracion;
  183.         return $this;
  184.     }
  185.     public function getIDperseo(): ?string
  186.     {
  187.         return $this->IDperseo;
  188.     }
  189.     public function setIDperseo(string $IDperseo): self
  190.     {
  191.         $this->IDperseo $IDperseo;
  192.         return $this;
  193.     }
  194.     /**
  195.      * @return Collection|Valoracion[]
  196.      */
  197.     public function getClones(): Collection
  198.     {
  199.         return $this->clones;
  200.     }
  201.     public function addClone(Valoracion $clone): self
  202.     {
  203.         if (!$this->clones->contains($clone)) {
  204.             $this->clones[] = $clone;
  205.             $clone->setClone($this);
  206.         }
  207.         return $this;
  208.     }
  209.     public function removeClone(Valoracion $clone): self
  210.     {
  211.         if ($this->clones->removeElement($clone)) {
  212.             // set the owning side to null (unless already changed)
  213.             if ($clone->getClone() === $this) {
  214.                 $clone->setClone(null);
  215.             }
  216.         }
  217.         return $this;
  218.     }
  219.     public function getClone(): ?self
  220.     {
  221.         return $this->clone;
  222.     }
  223.     public function setClone(?self $clone): self
  224.     {
  225.         $this->clone $clone;
  226.         return $this;
  227.     }
  228.     public function getRelojMarca(): ?Marca
  229.     {
  230.         if ($this instanceof ValoracionesRelojesSinStock) {
  231.             return $this->getRelojMarca();
  232.         }
  233.         if ($this instanceof ValoracionesRelojesStock) {
  234.             return $this->getReloj()?->getMarca();
  235.         }
  236.         return null;
  237.     }
  238.     public function getRelojModelo1(): ?string
  239.     {
  240.         if ($this instanceof ValoracionesRelojesSinStock) {
  241.             return $this->getRelojModelo1();
  242.         }
  243.         if ($this instanceof ValoracionesRelojesStock) {
  244.             return $this->getReloj()?->getModelo1();
  245.         }
  246.         return null;
  247.     }
  248.     public function getRelojRef1(): ?string
  249.     {
  250.         if ($this instanceof ValoracionesRelojesSinStock) {
  251.             return $this->getRelojRef1();
  252.         }
  253.         if ($this instanceof ValoracionesRelojesStock) {
  254.             return $this->getReloj()?->getRef1();
  255.         }
  256.         return null;
  257.     }
  258.     public function getMargenDeseado(): ?float
  259.     {
  260.         if ($this instanceof ValoracionesRelojesSinStock) {
  261.             return $this->getMargenDeseado();
  262.         }
  263.         if ($this instanceof ValoracionesRelojesStock) {
  264.             return $this->getReloj()?->getMargenDeseado();
  265.         }
  266.         return null;
  267.     }
  268.     public function getPrecioPagar(): ?float
  269.     {
  270.         if ($this instanceof ValoracionesRelojesSinStock) {
  271.             return $this->getprecioPagar();
  272.         }
  273.         if ($this instanceof ValoracionesRelojesStock) {
  274.             return $this->getReloj()?->getPrecioPagar();
  275.         }
  276.         return null;
  277.     }
  278. }