<?php
namespace App\Entity\Details\Operation;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Ean\Ean;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Ramsey\Uuid\Doctrine\UuidGenerator;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
/**
* @ApiResource(
* attributes={
* "force_eager"=false,
* "normalization_context"={
* "groups"={
* "DetailsOperation:output",
* "DetailsOperation:io"
* },
* "enable_max_depth"=true
* },
* "denormalization_context"={
* "groups"={
* "DetailsOperation:output",
* "DetailsOperation:io"
* },
* "enable_max_depth"=true
* }
* },
* collectionOperations={"GET"},
* itemOperations={"GET"},
* )
* @ORM\Entity()
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({
* "details_operation" = "DetailsOperation",
* "details_puntos" = "DetailsPuntos",
* "details_step" = "DetailsStep",
* "details_odr" = "DetailsOdr",
* "details_sponsorship" = "DetailsSponsorship",
* "details_multi_offer" = "DetailsMultiOffer"
* })
*/
class DetailsOperation
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @SerializedName("id")
* @ApiProperty(identifier=true)
* @Groups({
* "DetailsStep:output",
* "DetailsOdr:output",
* "DetailsPuntos:output",
* "DetailsSponsorship:output",
* "DetailsOperation:output",
* "OperationStep:io",
* "OperationOdr:io",
* "OperationPuntos:io",
* "OperationSponsorship:io",
* "Operation:io",
* "get_all_public_steps",
* "get_all_public_odrs",
* })
*/
protected string $id;
/**
* @ORM\OneToMany(targetEntity=Ean::class, mappedBy="detailsOperation", fetch="EAGER")
* @SerializedName("eans")
* @Groups({
* "DetailsPuntos:io",
* "DetailsStep:io",
* "DetailsOdr:io",
* "OperationPuntos:io",
* "OperationSponsorship:io",
* "OperationStep:io",
* "OperationOdr:io",
* "get_all_public_steps",
* "get_all_public_puntos",
* "get_all_public_odrs",
* })
*/
protected Collection $eans;
public function __construct()
{
$this->eans = new ArrayCollection();
}
/**
* @return string
*/
public function getId() : string
{
return $this->id;
}
/**
* @return Collection|Ean[]
*/
public function getEans(): Collection
{
return $this->eans;
}
public function setEans(Collection $eans): self
{
$this->eans = $eans;
return $this;
}
public function clearEans(): self
{
foreach($this->eans as $ean) {
// set the owning side to null (unless already changed)
if ($ean->getDetailsOperation() === $this) {
$ean->setDetailsOperation(null);
}
}
$this->setEans(new ArrayCollection());
return $this;
}
public function addEan(Ean $ean): self
{
if (!$this->eans->contains($ean)) {
$this->eans[] = $ean;
$ean->setDetailsOperation($this);
}
return $this;
}
public function removeEan(Ean $ean): self
{
if ($this->eans->removeElement($ean)) {
// set the owning side to null (unless already changed)
if ($ean->getDetailsOperation() === $this) {
$ean->setDetailsOperation(null);
}
}
return $this;
}
}