<?php
namespace App\Entity\Participation;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\Api\Participation\Puntos\GetAvailablePuntosByUser;
use App\Controller\Api\Participation\Puntos\GetParticipationPuntosByUser;
use App\Controller\Api\Participation\Puntos\GetTotalPuntosByUser;
use App\Entity\Details\Participation\DetailsParticipationPuntos;
use App\Entity\Ean\Participation\EanPuntos;
use App\Entity\MediaObject\MediaProduct;
use App\Entity\Product;
use App\Repository\Participation\PuntosRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\ExclusionPolicy;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
/**
* @ORM\Entity(repositoryClass=PuntosRepository::class)
* @ExclusionPolicy("all")
* @ApiResource(
* messenger=true,
* shortName="participation-puntos",
* attributes={
* "force_eager"=false,
* "normalization_context"={
* "groups"={
* "ParticipationPuntos:output",
* "ParticipationPuntos:io",
* },
* "enable_max_depth"=true
* },
* "denormalization_context"={
* "groups"={
* "ParticipationPuntos:input",
* "ParticipationPuntos:io",
* },
* "enable_max_depth"=true
* }
* },
* collectionOperations={
* "get",
* "post",
* "get-by-user"={
* "method"="GET",
* "path"="/participation-puntos/user",
* "access_control"="is_granted('ROLE_USER')",
* "validation_groups"={"get_participation-puntos_by_user"},
* "controller"=GetParticipationPuntosByUser::class,
* "defaults"={"_api_receive"=false},
* },
* "get-total-puntos-by-user"={
* "method"="GET",
* "path"="/puntos/total/user",
* "access_control"="is_granted('ROLE_USER')",
* "controller"=GetTotalPuntosByUser::class,
* "defaults"={"_api_receive"=false},
* },
* "get-available-puntos-by-user"={
* "method"="GET",
* "path"="/puntos/available/user",
* "access_control"="is_granted('ROLE_USER')",
* "controller"=GetAvailablePuntosByUser::class,
* "defaults"={"_api_receive"=false},
* },
* },
* itemOperations={
* "get",
* "put"={
* "validation_groups"={"Default", "Edit"}
* },
* },
* )
*/
class Puntos extends Participation
{
/**
* @ORM\Column(name="code", type="string", nullable=true)
* @SerializedName("code")
* @Groups({
* "ParticipationPuntos:io",
* })
*/
private ?string $code = null;
/**
* @ORM\Column(name="amount", type="float")
* @SerializedName("amount")
* @Groups({
* "ParticipationPuntos:io",
* "get_steps_by_user_department",
* })
*/
private ?float $amount = null;
/**
* @ORM\OneToMany(targetEntity=MediaProduct::class, mappedBy="participation")
* @SerializedName("products")
* @Groups({
* "Participation:output",
* "ParticipationPuntos:io",
* })
*/
protected Collection $products;
/**
* @ORM\OneToOne(targetEntity=DetailsParticipationPuntos::class, mappedBy="participation", cascade={"persist", "remove"})
* @SerializedName("details_participation_puntos")
* @Groups({
* "ParticipationPuntos:io",
* "get_puntos_by_user_department",
* })
*/
private ?DetailsParticipationPuntos $details = null;
/**
* @ORM\OneToMany(targetEntity=EanPuntos::class, mappedBy="participation")
*
* @SerializedName("ean_puntos")
* @Groups({
* "ParticipationPuntos:io",
* "get_steps_by_user_department",
* })
*/
private $eanParticipations;
/**
* @ORM\Column(type="boolean", options={"default": 0})
*/
private bool $mailSuccess = false;
public function __construct()
{
parent::__construct();
$this->products = new ArrayCollection();
$this->eanParticipations = new ArrayCollection();
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code)
{
$this->code = $code;
return $this;
}
/**
* @return float|null
*/
public function getAmount() : ?float
{
return $this->amount;
}
/**
* @param float|null $amount
*
* @return Puntos
*/
public function setAmount(?float $amount) : Puntos
{
$this->amount = $amount;
return $this;
}
/**
* @return Collection|MediaProduct[]
*/
public function getProducts() : Collection
{
return $this->products;
}
public function addProduct(MediaProduct $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
}
return $this;
}
public function removeProduct(MediaProduct $product): self
{
$this->products->removeElement($product);
return $this;
}
/**
* @return Collection|EanPuntos[]
*/
public function getEanParticipations(): Collection
{
return $this->eanParticipations;
}
public function addEanParticipations(EanPuntos $eanPuntos): self
{
if (!$this->eanParticipations->contains($eanPuntos)) {
$this->eanParticipations[] = $eanPuntos;
$eanPuntos->setParticipation($this);
}
return $this;
}
public function removeEanParticipations(EanPuntos $eanPuntos): self
{
if ($this->eanParticipations->removeElement($eanPuntos)) {
// set the owning side to null (unless already changed)
if ($eanPuntos->getParticipation() === $this) {
$eanPuntos->setParticipation(null);
}
}
return $this;
}
public function getDetails(): ?DetailsParticipationPuntos
{
return $this->details;
}
public function setDetails(?DetailsParticipationPuntos $details): self
{
$this->details = $details;
return $this;
}
/**
* @Serializer\VirtualProperty
* @Serializer\Groups({"shannon"})
* @Serializer\SerializedName("participation_id")
* @return string
*/
public function getParticipationId(): string
{
return $this->id;
}
/**
* Get opt-in RGPD.
*
* @Serializer\VirtualProperty
* @Serializer\Groups({"shannon"})
* @Serializer\SerializedName("optin_rgpd")
* @return int
*/
public function intOptInRGPD(): int
{
return true;
}
/**
* @Serializer\VirtualProperty
* @Serializer\Groups({"shannon"})
* @Serializer\SerializedName("action")
* @return string
*/
public function getAction(): string
{
return 'create';
}
/**
* @Serializer\VirtualProperty
* @Serializer\Groups({"shannon"})
* @Serializer\SerializedName("channel")
* @return string
*/
public function getChannel(): string
{
return 'FW';
}
/**
* @Serializer\VirtualProperty
* @Serializer\Groups({"shannon"})
* @Serializer\SerializedName("date_participation")
* @return string
*/
public function getDateParticipation(): string
{
return $this->getCreatedAt()->format('Y-m-d H:i:s');
}
public function getMailSuccess(): bool
{
return (bool) $this->mailSuccess;
}
public function setMailSuccess(bool $mailSuccess): self
{
$this->mailSuccess = $mailSuccess;
return $this;
}
public function getApiCode()
{
return $this->getValidationExport() instanceof ValidationExport ? $this->getValidationExport()->getAPIParticpationId() : null;
}
}