src/Entity/Details/Operation/DetailsOperation.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Details\Operation;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Entity\Ean\Ean;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. use Ramsey\Uuid\Doctrine\UuidGenerator;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Serializer\Annotation\SerializedName;
  13. /**
  14.  * @ApiResource(
  15.  *     attributes={
  16.  *          "force_eager"=false,
  17.  *          "normalization_context"={
  18.  *              "groups"={
  19.  *                  "DetailsOperation:output",
  20.  *                  "DetailsOperation:io"
  21.  *               },
  22.  *              "enable_max_depth"=true
  23.  *          },
  24.  *          "denormalization_context"={
  25.  *              "groups"={
  26.  *                  "DetailsOperation:output",
  27.  *                  "DetailsOperation:io"
  28.  *               },
  29.  *              "enable_max_depth"=true
  30.  *          }
  31.  *      },
  32.  *     collectionOperations={"GET"},
  33.  *     itemOperations={"GET"},
  34.  * )
  35.  * @ORM\Entity()
  36.  * @ORM\InheritanceType("SINGLE_TABLE")
  37.  * @ORM\DiscriminatorColumn(name="discr", type="string")
  38.  * @ORM\DiscriminatorMap({
  39.  *     "details_operation" = "DetailsOperation",
  40.  *     "details_puntos" = "DetailsPuntos",
  41.  *     "details_step" = "DetailsStep",
  42.  *     "details_odr" = "DetailsOdr",
  43.  *     "details_sponsorship" = "DetailsSponsorship",
  44.  *     "details_multi_offer" = "DetailsMultiOffer"
  45.  * })
  46.  */
  47. class DetailsOperation
  48. {
  49.     /**
  50.      * Hook timestampable behavior
  51.      * updates createdAt, updatedAt fields
  52.      */
  53.     use TimestampableEntity;
  54.     /**
  55.      * @ORM\Id
  56.      * @ORM\Column(type="uuid", unique=true)
  57.      * @ORM\GeneratedValue(strategy="CUSTOM")
  58.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  59.      * @SerializedName("id")
  60.      * @ApiProperty(identifier=true)
  61.      * @Groups({
  62.      *     "DetailsStep:output",
  63.      *     "DetailsOdr:output",
  64.      *     "DetailsPuntos:output",
  65.      *     "DetailsSponsorship:output",
  66.      *     "DetailsOperation:output",
  67.      *     "OperationStep:io",
  68.      *     "OperationOdr:io",
  69.      *     "OperationPuntos:io",
  70.      *     "OperationSponsorship:io",
  71.      *     "Operation:io",
  72.      *     "get_all_public_steps",
  73.      *     "get_all_public_odrs",
  74.      * })
  75.      */
  76.     protected string $id;
  77.     /**
  78.      * @ORM\OneToMany(targetEntity=Ean::class, mappedBy="detailsOperation", fetch="EAGER")
  79.      * @SerializedName("eans")
  80.      * @Groups({
  81.      *     "DetailsPuntos:io",
  82.      *     "DetailsStep:io",
  83.      *     "DetailsOdr:io",
  84.      *     "OperationPuntos:io",
  85.      *     "OperationSponsorship:io",
  86.      *     "OperationStep:io",
  87.      *     "OperationOdr:io",
  88.      *     "get_all_public_steps",
  89.      *     "get_all_public_puntos",
  90.      *     "get_all_public_odrs",
  91.      * })
  92.      */
  93.     protected Collection $eans;
  94.     public function __construct()
  95.     {
  96.         $this->eans = new ArrayCollection();
  97.     }
  98.     /**
  99.      * @return string
  100.      */
  101.     public function getId() : string
  102.     {
  103.         return $this->id;
  104.     }
  105.     /**
  106.      * @return Collection|Ean[]
  107.      */
  108.     public function getEans(): Collection
  109.     {
  110.         return $this->eans;
  111.     }
  112.     public function setEans(Collection $eans): self
  113.     {
  114.         $this->eans $eans;
  115.         return $this;
  116.     }
  117.     public function clearEans(): self
  118.     {
  119.         foreach($this->eans as $ean) {
  120.             // set the owning side to null (unless already changed)
  121.             if ($ean->getDetailsOperation() === $this) {
  122.                 $ean->setDetailsOperation(null);
  123.             }
  124.         }
  125.         $this->setEans(new ArrayCollection());
  126.         return $this;
  127.     }
  128.     public function addEan(Ean $ean): self
  129.     {
  130.         if (!$this->eans->contains($ean)) {
  131.             $this->eans[] = $ean;
  132.             $ean->setDetailsOperation($this);
  133.         }
  134.         return $this;
  135.     }
  136.     public function removeEan(Ean $ean): self
  137.     {
  138.         if ($this->eans->removeElement($ean)) {
  139.             // set the owning side to null (unless already changed)
  140.             if ($ean->getDetailsOperation() === $this) {
  141.                 $ean->setDetailsOperation(null);
  142.             }
  143.         }
  144.         return $this;
  145.     }
  146. }