src/Entity/Participation/Coupon.php line 64

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Participation;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Dto\ParticipationStatus;
  5. use App\Repository\Participation\CouponRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use App\Controller\Api\Participation\Coupon\GetNbParticipationCouponByOperationId;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * @ApiResource(
  13.  *      messenger=true,
  14.  *      shortName="participation-coupon",
  15.  *      attributes={
  16.  *          "normalization_context"={
  17.  *              "groups"={
  18.  *                  "ParticipationCoupon:io",
  19.  *                  "ParticipationCoupon:output"
  20.  *              }
  21.  *          },
  22.  *          "denormalization_context"={
  23.  *              "groups"={
  24.  *                  "ParticipationCoupon:io",
  25.  *                  "ParticipationCoupon:input"
  26.  *              }
  27.  *          }
  28.  *      },
  29.  *     collectionOperations={
  30.  *          "post"={
  31.  *              "method"="POST",
  32.  *              "access_control"="is_granted('ROLE_USER')"
  33.  *          },
  34.  *          "get"={
  35.  *              "method"="GET",
  36.  *              "access_control"="is_granted('ROLE_USER')",
  37.  *          },
  38.  *     },
  39.  *     itemOperations={
  40.  *          "get"={
  41.  *              "method"="GET",
  42.  *              "access_control"="is_granted('ROLE_USER')",
  43.  *          },
  44.  *          "burn-coupon"={
  45.  *             "method"="PUT",
  46.  *             "input"=ParticipationStatus::class,
  47.  *             "path"="/participation-coupons/burn/{id}",
  48.  *         },
  49.  *         "public-get-nbr-participation-coupon"={
  50.  *             "method"="GET",
  51.  *             "access_control"="is_granted('ROLE_PUBLIC')",
  52.  *             "path"="/public/get-nb-participation-coupon/{id}",
  53.  *             "controller"=GetNbParticipationCouponByOperationId::class,
  54.  *             "defaults"={"_api_receive"=false},
  55.  *          }
  56.  *     }
  57.  * )
  58.  * @ORM\Entity(repositoryClass=CouponRepository::class)
  59.  * @Gedmo\Loggable
  60.  */
  61. class Coupon extends Participation
  62. {
  63.     const CHANNEL_EMAIL "email";
  64.     const CHANNEL_PRINT "print";
  65.     const CHANNELS = [
  66.         self::CHANNEL_EMAIL,
  67.         self::CHANNEL_PRINT
  68.     ];
  69.     //status
  70.     const STATUS_NEW "new";
  71.     const STATUS_SENT_BY_EMAIL "sentByEmail";
  72.     const STATUS_WAIT_FOR_PRINT "waitForPrint";
  73.     const STATUS_PRINTED "printed";
  74.     const STATUS_UNLOCK_PRINT "unlockPrinted";
  75.     // all status list
  76.     const STATUS = [
  77.         self::STATUS_NEW,
  78.         self::STATUS_PRINTED,
  79.         self::STATUS_SENT_BY_EMAIL,
  80.         self::STATUS_WAIT_FOR_PRINT,
  81.         self::STATUS_UNLOCK_PRINT,
  82.     ];
  83.     //status that mark coupon as printed
  84.     const PRINTED_STATUS = [
  85.         self::STATUS_SENT_BY_EMAIL,
  86.         self::STATUS_WAIT_FOR_PRINT,
  87.         self::STATUS_PRINTED,
  88.     ];
  89.     /**
  90.      * @ORM\Column(type="string", length=255, nullable=true)
  91.      * @Groups({"ParticipationCoupon:io"})
  92.      */
  93.     private $printUrl;
  94.     /**
  95.      * @ORM\Column(type="string", length=10)
  96.      * @Groups({"ParticipationCoupon:io"})
  97.      * @Assert\NotBlank()
  98.      */
  99.     private ?string $emitterCode null;
  100.     /**
  101.      * @ORM\Column(type="string", length=10)
  102.      * @Groups({"ParticipationCoupon:io"})
  103.      * @Assert\NotBlank()
  104.      * @Assert\Choice(choices=self::CHANNELS, message="Choose a valid channel.")
  105.      */
  106.     private string $channel;
  107.     /**
  108.      * @ORM\Column(type="string", length=15)
  109.      * @Groups({"ParticipationCoupon:output"})
  110.      * @Gedmo\Versioned
  111.      */
  112.     //@todo use symfony/workflow
  113.     private string $status "new";
  114.     /**
  115.      * @return mixed
  116.      */
  117.     public function getPrintUrl()
  118.     {
  119.         return $this->printUrl;
  120.     }
  121.     /**
  122.      * @param mixed $printUrl
  123.      * @return Coupon
  124.      */
  125.     public function setPrintUrl($printUrl)
  126.     {
  127.         $this->printUrl $printUrl;
  128.         return $this;
  129.     }
  130.     public function getEmitterCode(): ?string
  131.     {
  132.         return $this->emitterCode;
  133.     }
  134.     public function setEmitterCode(string $emitterCode): self
  135.     {
  136.         $this->emitterCode $emitterCode;
  137.         return $this;
  138.     }
  139.     /**
  140.      * @return string
  141.      */
  142.     public function getChannel(): string
  143.     {
  144.         return $this->channel;
  145.     }
  146.     /**
  147.      * @param string $channel
  148.      * @return Coupon
  149.      */
  150.     public function setChannel(string $channel): Coupon
  151.     {
  152.         $this->channel $channel;
  153.         return $this;
  154.     }
  155.     public function getStatus(): ?string
  156.     {
  157.         return $this->status;
  158.     }
  159.     public function setStatus(string $status): self
  160.     {
  161.         $this->status $status;
  162.         return $this;
  163.     }
  164. }