<?php
namespace App\Entity\Participation;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Dto\ParticipationStatus;
use App\Repository\Participation\CouponRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use App\Controller\Api\Participation\Coupon\GetNbParticipationCouponByOperationId;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource(
* messenger=true,
* shortName="participation-coupon",
* attributes={
* "normalization_context"={
* "groups"={
* "ParticipationCoupon:io",
* "ParticipationCoupon:output"
* }
* },
* "denormalization_context"={
* "groups"={
* "ParticipationCoupon:io",
* "ParticipationCoupon:input"
* }
* }
* },
* collectionOperations={
* "post"={
* "method"="POST",
* "access_control"="is_granted('ROLE_USER')"
* },
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_USER')",
* },
* },
* itemOperations={
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_USER')",
* },
* "burn-coupon"={
* "method"="PUT",
* "input"=ParticipationStatus::class,
* "path"="/participation-coupons/burn/{id}",
* },
* "public-get-nbr-participation-coupon"={
* "method"="GET",
* "access_control"="is_granted('ROLE_PUBLIC')",
* "path"="/public/get-nb-participation-coupon/{id}",
* "controller"=GetNbParticipationCouponByOperationId::class,
* "defaults"={"_api_receive"=false},
* }
* }
* )
* @ORM\Entity(repositoryClass=CouponRepository::class)
* @Gedmo\Loggable
*/
class Coupon extends Participation
{
const CHANNEL_EMAIL = "email";
const CHANNEL_PRINT = "print";
const CHANNELS = [
self::CHANNEL_EMAIL,
self::CHANNEL_PRINT
];
//status
const STATUS_NEW = "new";
const STATUS_SENT_BY_EMAIL = "sentByEmail";
const STATUS_WAIT_FOR_PRINT = "waitForPrint";
const STATUS_PRINTED = "printed";
const STATUS_UNLOCK_PRINT = "unlockPrinted";
// all status list
const STATUS = [
self::STATUS_NEW,
self::STATUS_PRINTED,
self::STATUS_SENT_BY_EMAIL,
self::STATUS_WAIT_FOR_PRINT,
self::STATUS_UNLOCK_PRINT,
];
//status that mark coupon as printed
const PRINTED_STATUS = [
self::STATUS_SENT_BY_EMAIL,
self::STATUS_WAIT_FOR_PRINT,
self::STATUS_PRINTED,
];
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"ParticipationCoupon:io"})
*/
private $printUrl;
/**
* @ORM\Column(type="string", length=10)
* @Groups({"ParticipationCoupon:io"})
* @Assert\NotBlank()
*/
private ?string $emitterCode = null;
/**
* @ORM\Column(type="string", length=10)
* @Groups({"ParticipationCoupon:io"})
* @Assert\NotBlank()
* @Assert\Choice(choices=self::CHANNELS, message="Choose a valid channel.")
*/
private string $channel;
/**
* @ORM\Column(type="string", length=15)
* @Groups({"ParticipationCoupon:output"})
* @Gedmo\Versioned
*/
//@todo use symfony/workflow
private string $status = "new";
/**
* @return mixed
*/
public function getPrintUrl()
{
return $this->printUrl;
}
/**
* @param mixed $printUrl
* @return Coupon
*/
public function setPrintUrl($printUrl)
{
$this->printUrl = $printUrl;
return $this;
}
public function getEmitterCode(): ?string
{
return $this->emitterCode;
}
public function setEmitterCode(string $emitterCode): self
{
$this->emitterCode = $emitterCode;
return $this;
}
/**
* @return string
*/
public function getChannel(): string
{
return $this->channel;
}
/**
* @param string $channel
* @return Coupon
*/
public function setChannel(string $channel): Coupon
{
$this->channel = $channel;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
}