src/Entity/User/Wallet.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity\User;
  3. use App\Entity\BaseEntity;
  4. use App\Entity\User;
  5. use App\Repository\User\WalletRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10.  * @ORM\Entity(repositoryClass=WalletRepository::class)
  11.  * @ORM\HasLifecycleCallbacks()
  12.  */
  13. class Wallet extends BaseEntity
  14. {
  15.     /**
  16.      * @ORM\Column(type="float")
  17.      */
  18.     private $balance;
  19.     
  20.     /**
  21.      * @ORM\Column(type="float")
  22.      * Montant in pending withdraw
  23.      */
  24.     private $pending;
  25.     
  26.     /**
  27.      * @ORM\Column(type="float")
  28.      */
  29.     private $incoming;
  30.     /**
  31.      * @ORM\OneToOne(targetEntity=User::class, inversedBy="wallet", cascade={"persist", "remove"})
  32.      * @ORM\JoinColumn(nullable=false)
  33.      */
  34.     private $user;
  35.     /**
  36.      * @ORM\OneToMany(targetEntity=Transaction::class, mappedBy="wallet")
  37.      */
  38.     private $transactions;
  39.     public function __construct()
  40.     {
  41.         parent::__construct();
  42.         $this->balance 0;
  43.         $this->pending 0;
  44.         $this->incoming 0;
  45.         $this->transactions = new ArrayCollection();
  46.     }
  47.     public function getBalance(): ?float
  48.     {
  49.         return $this->balance;
  50.     }
  51.     public function setBalance(float $balance): self
  52.     {
  53.         $this->balance $balance;
  54.         return $this;
  55.     }
  56.     public function getPending(): ?float
  57.     {
  58.         return $this->pending;
  59.     }
  60.     public function setPending(float $pending): self
  61.     {
  62.         $this->pending $pending;
  63.         return $this;
  64.     }
  65.     public function getIncoming(): ?float
  66.     {
  67.         return $this->incoming;
  68.     }
  69.     public function setIncoming(float $incoming): self
  70.     {
  71.         $this->incoming $incoming;
  72.         return $this;
  73.     }
  74.     public function getUser(): ?User
  75.     {
  76.         return $this->user;
  77.     }
  78.     public function setUser(User $user): self
  79.     {
  80.         $this->user $user;
  81.         return $this;
  82.     }
  83.     /**
  84.      * @return Collection|Transaction[]
  85.      */
  86.     public function getTransactions(): Collection
  87.     {
  88.         return $this->transactions;
  89.     }
  90.     public function addTransaction(Transaction $transaction): self
  91.     {
  92.         if (!$this->transactions->contains($transaction)) {
  93.             $this->transactions[] = $transaction;
  94.             $transaction->setWallet($this);
  95.         }
  96.         return $this;
  97.     }
  98.     public function removeTransaction(Transaction $transaction): self
  99.     {
  100.         if ($this->transactions->removeElement($transaction)) {
  101.             // set the owning side to null (unless already changed)
  102.             if ($transaction->getWallet() === $this) {
  103.                 $transaction->setWallet(null);
  104.             }
  105.         }
  106.         return $this;
  107.     }
  108. }