src/Entity/Purse/Item.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Purse;
  3. use App\Entity\Ean\Ean;
  4. use App\Entity\Participation\Participation;
  5. use App\Repository\Purse\ItemRepository;
  6. use DateInterval;
  7. use DateTime;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use ApiPlatform\Core\Annotation\ApiResource;
  12. use ApiPlatform\Core\Annotation\ApiProperty;
  13. /**
  14.  * @ApiResource(
  15.  *      attributes={
  16.  *          "normalization_context"={"groups"={"Purse:io","Purse:output"}},
  17.  *          "denormalization_context"={"groups"={"Purse:io","Purse:input"}}
  18.  *      },
  19.  *     collectionOperations={
  20.  *          "get"={
  21.  *              "method"="GET",
  22.  *              "access_control"="is_granted('ROLE_USER')",
  23.  *          },
  24.  *     },
  25.  *     itemOperations={
  26.  *          "get"={
  27.  *              "method"="GET",
  28.  *              "access_control"="is_granted('ROLE_USER')",
  29.  *          },
  30.  *      }
  31.  * )
  32.  * @ORM\Entity(repositoryClass=ItemRepository::class)
  33.  * @ORM\InheritanceType("SINGLE_TABLE")
  34.  * @ORM\DiscriminatorColumn(name="discr", type="string")
  35.  * @ORM\DiscriminatorMap({
  36.  *     "item" = "Item",
  37.  *     "puntos" = "ItemPuntos",
  38.  *     "step" = "ItemStep"
  39.  * })
  40.  */
  41. class Item
  42. {
  43.     const STATUS_NEW 'new';
  44.     const STATUS_AVAILABLE 'available';
  45.     const STATUS_EXPIRED 'expired';
  46.     const STATUS_EXPIRING 'purse_expiring';
  47.     const STATUS_REFUND_ASKED 'refund_asked';
  48.     const STATUS_REFUND_PURSE_EXPIRING_ASK 'refund_purse_expiring_asked';
  49.     const STATUS_REFUND_SENT 'refund_sent';
  50.     const STATUS_REFUNDED 'refunded';
  51.     const STATUS_BURNED 'burned';
  52.     const DEFAULT_CONFIG_ITEM_DURATION_IN_DAYS 365;
  53.     /**
  54.      * Hook timestampable behavior
  55.      * updates createdAt, updatedAt fields
  56.      */
  57.     use TimestampableEntity;
  58.     /**
  59.      * @ORM\Id
  60.      * @ApiProperty(identifier=true)
  61.      * @Groups({"Purse:output"})
  62.      * @ORM\GeneratedValue
  63.      * @ORM\Column(type="integer")
  64.      */
  65.     private $id;
  66.     /**
  67.      * @ORM\Column(type="float")
  68.      * @Groups({"Purse:output"})
  69.      * @Groups({
  70.      *     "Order:output",
  71.      * })
  72.      */
  73.     private $amount;
  74.     /**
  75.      * @ORM\ManyToOne(targetEntity=Participation::class)
  76.      * @ORM\JoinColumn(nullable=true)
  77.      */
  78.     private $participation;
  79.     /**
  80.      * @ORM\ManyToOne(targetEntity=Ean::class)
  81.      * @ORM\JoinColumn(nullable=true)
  82.      */
  83.     private $ean;
  84.     /**
  85.      * @ORM\Column(type="string", length=30)
  86.      * @Groups({"Purse:output"})
  87.      */
  88.     private $status;
  89.     /**
  90.      * @ORM\ManyToOne(targetEntity=Purse::class, inversedBy="items")
  91.      * @ORM\JoinColumn(nullable=false)
  92.      */
  93.     private $purse;
  94.     /**
  95.      * @ORM\Column(type="integer")
  96.      * @Groups({"Purse:output"})
  97.      */
  98.     private int $percentApplied 100;
  99.     /**
  100.      * @ORM\Column(type="float")
  101.      * @Groups({"Purse:output"})
  102.      */
  103.     private $originalAmount;
  104.     /**
  105.      * @var DateTime
  106.      * @ORM\Column(type="datetime", nullable=false, options={"default":"CURRENT_TIMESTAMP"})
  107.      * @Groups({"Purse:output"})
  108.      */
  109.     private $dueDate;
  110.     /**
  111.      * @ORM\Column(type="boolean", nullable=true)
  112.      * @Groups({"Purse:output"})
  113.      */
  114.     private ?bool $isClone;
  115.     /**
  116.      * Item constructor.
  117.      * @throws \Exception
  118.      */
  119.     public function __construct()
  120.     {
  121.         $dateIntervalFormat sprintf("P%sD"$_ENV['CONFIG_ITEM_DURATION_IN_DAYS'] ?? self::DEFAULT_CONFIG_ITEM_DURATION_IN_DAYS);
  122.         $this->dueDate = (new DateTime())->add(new DateInterval($dateIntervalFormat));
  123.     }
  124.     public function getId(): ?int
  125.     {
  126.         return $this->id;
  127.     }
  128.     public function getAmount(): ?float
  129.     {
  130.         return $this->amount;
  131.     }
  132.     public function setAmount(float $amount): self
  133.     {
  134.         $this->amount $amount;
  135.         return $this;
  136.     }
  137.     public function getParticipation(): ?Participation
  138.     {
  139.         return $this->participation;
  140.     }
  141.     public function setParticipation(?Participation $participation): self
  142.     {
  143.         $this->participation $participation;
  144.         return $this;
  145.     }
  146.     public function getEan(): ?Ean
  147.     {
  148.         return $this->ean;
  149.     }
  150.     public function setEan(?Ean $ean): self
  151.     {
  152.         $this->ean $ean;
  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.     public function getPurse(): ?Purse
  165.     {
  166.         return $this->purse;
  167.     }
  168.     public function setPurse(?Purse $purse): self
  169.     {
  170.         $this->purse $purse;
  171.         return $this;
  172.     }
  173.     public function getPercentApplied(): ?int
  174.     {
  175.         return $this->percentApplied;
  176.     }
  177.     public function setPercentApplied(int $percentApplied): self
  178.     {
  179.         $this->percentApplied $percentApplied;
  180.         return $this;
  181.     }
  182.     public function getOriginalAmount(): ?float
  183.     {
  184.         return $this->originalAmount;
  185.     }
  186.     public function setOriginalAmount(float $originalAmount): self
  187.     {
  188.         $this->originalAmount $originalAmount;
  189.         return $this;
  190.     }
  191.     /**
  192.      * @return \DateTimeInterface
  193.      */
  194.     public function getDueDate(): ?\DateTimeInterface
  195.     {
  196.         return $this->dueDate;
  197.     }
  198.     /**
  199.      * @param \DateTimeInterface $dueDate
  200.      * @return Item
  201.      */
  202.     public function setDueDate(\DateTimeInterface $dueDate): Item
  203.     {
  204.         $this->dueDate $dueDate;
  205.         return $this;
  206.     }
  207.     /**
  208.      * @return bool|null
  209.      */
  210.     public function getIsClone(): ?bool
  211.     {
  212.         return $this->isClone;
  213.     }
  214.     /**
  215.      * @param bool|null $isClone
  216.      *
  217.      * @return Item
  218.      */
  219.     public function setIsClone(?bool $isClone): Item
  220.     {
  221.         $this->isClone $isClone;
  222.         return $this;
  223.     }
  224. }