src/Entity/Participation/Puntos.php line 79

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Participation;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Controller\Api\Participation\Puntos\GetAvailablePuntosByUser;
  5. use App\Controller\Api\Participation\Puntos\GetParticipationPuntosByUser;
  6. use App\Controller\Api\Participation\Puntos\GetTotalPuntosByUser;
  7. use App\Entity\Details\Participation\DetailsParticipationPuntos;
  8. use App\Entity\Ean\Participation\EanPuntos;
  9. use App\Entity\MediaObject\MediaProduct;
  10. use App\Entity\Product;
  11. use App\Repository\Participation\PuntosRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use JMS\Serializer\Annotation as Serializer;
  16. use JMS\Serializer\Annotation\ExclusionPolicy;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. use Symfony\Component\Serializer\Annotation\SerializedName;
  19. /**
  20.  * @ORM\Entity(repositoryClass=PuntosRepository::class)
  21.  * @ExclusionPolicy("all")
  22.  * @ApiResource(
  23.  *     messenger=true,
  24.  *     shortName="participation-puntos",
  25.  *     attributes={
  26.  *          "force_eager"=false,
  27.  *          "normalization_context"={
  28.  *              "groups"={
  29.  *                  "ParticipationPuntos:output",
  30.  *                  "ParticipationPuntos:io",
  31.  *               },
  32.  *              "enable_max_depth"=true
  33.  *          },
  34.  *          "denormalization_context"={
  35.  *              "groups"={
  36.  *                  "ParticipationPuntos:input",
  37.  *                  "ParticipationPuntos:io",
  38.  *              },
  39.  *              "enable_max_depth"=true
  40.  *          }
  41.  *      },
  42.  *     collectionOperations={
  43.  *          "get",
  44.  *          "post",
  45.  *          "get-by-user"={
  46.  *              "method"="GET",
  47.  *              "path"="/participation-puntos/user",
  48.  *              "access_control"="is_granted('ROLE_USER')",
  49.  *              "validation_groups"={"get_participation-puntos_by_user"},
  50.  *              "controller"=GetParticipationPuntosByUser::class,
  51.  *              "defaults"={"_api_receive"=false},
  52.  *          },
  53.  *          "get-total-puntos-by-user"={
  54.  *              "method"="GET",
  55.  *              "path"="/puntos/total/user",
  56.  *              "access_control"="is_granted('ROLE_USER')",
  57.  *              "controller"=GetTotalPuntosByUser::class,
  58.  *              "defaults"={"_api_receive"=false},
  59.  *          },
  60.  *          "get-available-puntos-by-user"={
  61.  *              "method"="GET",
  62.  *              "path"="/puntos/available/user",
  63.  *              "access_control"="is_granted('ROLE_USER')",
  64.  *              "controller"=GetAvailablePuntosByUser::class,
  65.  *              "defaults"={"_api_receive"=false},
  66.  *          },
  67.  *     },
  68.  *     itemOperations={
  69.  *          "get",
  70.  *          "put"={
  71.  *              "validation_groups"={"Default", "Edit"}
  72.  *          },
  73.  *     },
  74.  * )
  75.  */
  76. class Puntos extends Participation
  77. {
  78.     /**
  79.      * @ORM\Column(name="code", type="string", nullable=true)
  80.      * @SerializedName("code")
  81.      * @Groups({
  82.      *     "ParticipationPuntos:io",
  83.      * })
  84.      */
  85.     private ?string $code null;
  86.     /**
  87.      * @ORM\Column(name="amount", type="float")
  88.      * @SerializedName("amount")
  89.      * @Groups({
  90.      *     "ParticipationPuntos:io",
  91.      *     "get_steps_by_user_department",
  92.      * })
  93.      */
  94.     private ?float $amount null;
  95.     /**
  96.      * @ORM\OneToMany(targetEntity=MediaProduct::class, mappedBy="participation")
  97.      * @SerializedName("products")
  98.      * @Groups({
  99.      *     "Participation:output",
  100.      *     "ParticipationPuntos:io",
  101.      * })
  102.      */
  103.     protected Collection $products;
  104.     /**
  105.      * @ORM\OneToOne(targetEntity=DetailsParticipationPuntos::class, mappedBy="participation", cascade={"persist", "remove"})
  106.      * @SerializedName("details_participation_puntos")
  107.      * @Groups({
  108.      *     "ParticipationPuntos:io",
  109.      *     "get_puntos_by_user_department",
  110.      * })
  111.      */
  112.     private ?DetailsParticipationPuntos $details null;
  113.     /**
  114.      * @ORM\OneToMany(targetEntity=EanPuntos::class, mappedBy="participation")
  115.      *
  116.      * @SerializedName("ean_puntos")
  117.      * @Groups({
  118.      *     "ParticipationPuntos:io",
  119.      *     "get_steps_by_user_department",
  120.      * })
  121.      */
  122.     private $eanParticipations;
  123.     /**
  124.      * @ORM\Column(type="boolean", options={"default": 0})
  125.      */
  126.     private bool $mailSuccess false;
  127.     public function __construct()
  128.     {
  129.         parent::__construct();
  130.         $this->products = new ArrayCollection();
  131.         $this->eanParticipations = new ArrayCollection();
  132.     }
  133.     public function getCode(): ?string
  134.     {
  135.         return $this->code;
  136.     }
  137.     public function setCode(?string $code)
  138.     {
  139.         $this->code $code;
  140.         return $this;
  141.     }
  142.     /**
  143.      * @return float|null
  144.      */
  145.     public function getAmount() : ?float
  146.     {
  147.         return $this->amount;
  148.     }
  149.     /**
  150.      * @param float|null $amount
  151.      *
  152.      * @return Puntos
  153.      */
  154.     public function setAmount(?float $amount) : Puntos
  155.     {
  156.         $this->amount $amount;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return Collection|MediaProduct[]
  161.      */
  162.     public function getProducts() : Collection
  163.     {
  164.         return $this->products;
  165.     }
  166.     public function addProduct(MediaProduct $product): self
  167.     {
  168.         if (!$this->products->contains($product)) {
  169.             $this->products[] = $product;
  170.         }
  171.         return $this;
  172.     }
  173.     public function removeProduct(MediaProduct $product): self
  174.     {
  175.         $this->products->removeElement($product);
  176.         return $this;
  177.     }
  178.     /**
  179.      * @return Collection|EanPuntos[]
  180.      */
  181.     public function getEanParticipations(): Collection
  182.     {
  183.         return $this->eanParticipations;
  184.     }
  185.     public function addEanParticipations(EanPuntos $eanPuntos): self
  186.     {
  187.         if (!$this->eanParticipations->contains($eanPuntos)) {
  188.             $this->eanParticipations[] = $eanPuntos;
  189.             $eanPuntos->setParticipation($this);
  190.         }
  191.         return $this;
  192.     }
  193.     public function removeEanParticipations(EanPuntos $eanPuntos): self
  194.     {
  195.         if ($this->eanParticipations->removeElement($eanPuntos)) {
  196.             // set the owning side to null (unless already changed)
  197.             if ($eanPuntos->getParticipation() === $this) {
  198.                 $eanPuntos->setParticipation(null);
  199.             }
  200.         }
  201.         return $this;
  202.     }
  203.     public function getDetails(): ?DetailsParticipationPuntos
  204.     {
  205.         return $this->details;
  206.     }
  207.     public function setDetails(?DetailsParticipationPuntos $details): self
  208.     {
  209.         $this->details $details;
  210.         return $this;
  211.     }
  212.     /**
  213.      * @Serializer\VirtualProperty
  214.      * @Serializer\Groups({"shannon"})
  215.      * @Serializer\SerializedName("participation_id")
  216.      * @return string
  217.      */
  218.     public function getParticipationId(): string
  219.     {
  220.         return $this->id;
  221.     }
  222.     /**
  223.      * Get opt-in RGPD.
  224.      *
  225.      * @Serializer\VirtualProperty
  226.      * @Serializer\Groups({"shannon"})
  227.      * @Serializer\SerializedName("optin_rgpd")
  228.      * @return int
  229.      */
  230.     public function intOptInRGPD(): int
  231.     {
  232.         return true;
  233.     }
  234.     /**
  235.      * @Serializer\VirtualProperty
  236.      * @Serializer\Groups({"shannon"})
  237.      * @Serializer\SerializedName("action")
  238.      * @return string
  239.      */
  240.     public function getAction(): string
  241.     {
  242.         return 'create';
  243.     }
  244.     /**
  245.      * @Serializer\VirtualProperty
  246.      * @Serializer\Groups({"shannon"})
  247.      * @Serializer\SerializedName("channel")
  248.      * @return string
  249.      */
  250.     public function getChannel(): string
  251.     {
  252.         return 'FW';
  253.     }
  254.     /**
  255.      * @Serializer\VirtualProperty
  256.      * @Serializer\Groups({"shannon"})
  257.      * @Serializer\SerializedName("date_participation")
  258.      * @return string
  259.      */
  260.     public function getDateParticipation(): string
  261.     {
  262.         return $this->getCreatedAt()->format('Y-m-d H:i:s');
  263.     }
  264.     public function getMailSuccess(): bool
  265.     {
  266.         return (bool) $this->mailSuccess;
  267.     }
  268.     public function setMailSuccess(bool $mailSuccess): self
  269.     {
  270.         $this->mailSuccess $mailSuccess;
  271.         return $this;
  272.     }
  273.     public function getApiCode()
  274.     {
  275.         return $this->getValidationExport() instanceof ValidationExport $this->getValidationExport()->getAPIParticpationId() : null;
  276.     }
  277. }