src/Point/Doctrine/Entity/Wallet.php line 33

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Point\Doctrine\Entity;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use App\Point\Doctrine\Repository\WalletRepository;
  9. use DateTimeImmutable;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping\Column;
  13. use Doctrine\ORM\Mapping\Entity;
  14. use Doctrine\ORM\Mapping\GeneratedValue;
  15. use Doctrine\ORM\Mapping\Id;
  16. use Doctrine\ORM\Mapping\JoinColumn;
  17. use Doctrine\ORM\Mapping\ManyToOne;
  18. use Doctrine\ORM\Mapping\OneToMany;
  19. use Doctrine\ORM\Mapping\Table;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. #[ApiResource(
  22.     collectionOperations: ['get'],
  23.     itemOperations: ['get' => ['security' => 'is_granted("item", object)']],
  24.     normalizationContext: ['groups' => ['read']]
  25. )]
  26. #[ApiFilter(SearchFilter::class, properties: ['account' => 'exact'])]
  27. #[Entity(repositoryClassWalletRepository::class)]
  28. #[Table(name'`point_wallet`')]
  29. class Wallet
  30. {
  31.     #[Id]
  32.     #[Column(type'integer')]
  33.     #[GeneratedValue]
  34.     #[Groups('read')]
  35.     private ?int $id null;
  36.     #[ManyToOne(targetEntityAccount::class, inversedBy'wallets')]
  37.     #[JoinColumn(nullablefalseonDelete'CASCADE')]
  38.     #[Groups('read')]
  39.     #[ApiProperty(readableLinkfalsewritableLinkfalse)]
  40.     private Account $account;
  41.     #[ManyToOne(targetEntityPurchase::class)]
  42.     #[JoinColumn(nullablefalseonDelete'CASCADE')]
  43.     #[Groups('read')]
  44.     #[ApiProperty(readableLinkfalsewritableLinkfalse)]
  45.     private Purchase $purchase;
  46.     #[Column(type'integer')]
  47.     #[Groups('read')]
  48.     private int $balance 0;
  49.     #[Column(type'datetime_immutable')]
  50.     #[Groups('read')]
  51.     private DateTimeImmutable $createdAt;
  52.     #[Column(type'datetime_immutable'nullabletrue)]
  53.     #[Groups('read')]
  54.     private ?DateTimeImmutable $expiredAt;
  55.     /**
  56.      * @var Collection<int, Transaction>
  57.      */
  58.     #[OneToMany(mappedBy'wallet'targetEntityTransaction::class)]
  59.     private Collection $transactions;
  60.     public function __construct()
  61.     {
  62.         $this->createdAt = new DateTimeImmutable();
  63.         $this->transactions = new ArrayCollection();
  64.     }
  65.     public function getId(): ?int
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getAccount(): Account
  70.     {
  71.         return $this->account;
  72.     }
  73.     public function setAccount(Account $account): void
  74.     {
  75.         $this->account $account;
  76.     }
  77.     public function getPurchase(): Purchase
  78.     {
  79.         return $this->purchase;
  80.     }
  81.     public function setPurchase(Purchase $purchase): void
  82.     {
  83.         $this->purchase $purchase;
  84.     }
  85.     public function getBalance(): int
  86.     {
  87.         return $this->balance;
  88.     }
  89.     public function setBalance(int $balance): void
  90.     {
  91.         $this->balance $balance;
  92.     }
  93.     public function getCreatedAt(): DateTimeImmutable
  94.     {
  95.         return $this->createdAt;
  96.     }
  97.     public function setCreatedAt(DateTimeImmutable $createdAt): void
  98.     {
  99.         $this->createdAt $createdAt;
  100.     }
  101.     public function getExpiredAt(): ?DateTimeImmutable
  102.     {
  103.         return $this->expiredAt;
  104.     }
  105.     public function setExpiredAt(?DateTimeImmutable $expiredAt): void
  106.     {
  107.         $this->expiredAt $expiredAt;
  108.     }
  109.     /**
  110.      * @return Collection<int, Transaction>
  111.      */
  112.     public function getTransactions(): Collection
  113.     {
  114.         return $this->transactions;
  115.     }
  116.     public function isExpired(): bool
  117.     {
  118.         return null !== $this->expiredAt && $this->expiredAt < new DateTimeImmutable();
  119.     }
  120. }