You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
3.4KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Model\User;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
  7. use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
  8. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  9. /**
  10. * @ORM\MappedSuperclass()
  11. *
  12. */
  13. abstract class UserMerchantModel implements FilterMerchantInterface
  14. {
  15. /**
  16. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\User\UserInterface", inversedBy="userMerchants")
  17. * @ORM\JoinColumn(nullable=false)
  18. */
  19. protected $user;
  20. /**
  21. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
  22. * @ORM\JoinColumn(nullable=false)
  23. */
  24. protected $merchant;
  25. /**
  26. * @ORM\Column(type="float", nullable=true)
  27. */
  28. protected $credit;
  29. /**
  30. * @ORM\Column(type="boolean")
  31. */
  32. protected $creditActive;
  33. /**
  34. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface", mappedBy="userMerchant", orphanRemoval=true)
  35. */
  36. protected $creditHistories;
  37. /**
  38. * @ORM\Column(type="boolean")
  39. */
  40. protected $active;
  41. public function __construct()
  42. {
  43. $this->creditHistories = new ArrayCollection();
  44. }
  45. public function getUser(): ?UserModel
  46. {
  47. return $this->user;
  48. }
  49. public function setUser(?UserModel $user): self
  50. {
  51. $this->user = $user;
  52. return $this;
  53. }
  54. public function getMerchant(): ?MerchantInterface
  55. {
  56. return $this->merchant;
  57. }
  58. public function setMerchant(?MerchantInterface $merchant): self
  59. {
  60. $this->merchant = $merchant;
  61. return $this;
  62. }
  63. public function getCredit(): ?float
  64. {
  65. return $this->credit;
  66. }
  67. public function setCredit(?float $credit): self
  68. {
  69. $this->credit = $credit;
  70. return $this;
  71. }
  72. public function getCreditActive(): ?bool
  73. {
  74. return $this->creditActive;
  75. }
  76. public function isCreditActive(): bool
  77. {
  78. return $this->creditActive;
  79. }
  80. public function setCreditActive(bool $creditActive): self
  81. {
  82. $this->creditActive = $creditActive;
  83. return $this;
  84. }
  85. /**
  86. * @return Collection|CreditHistoryInterface[]
  87. */
  88. public function getCreditHistories(): Collection
  89. {
  90. return $this->creditHistories;
  91. }
  92. public function addCreditHistory(CreditHistoryInterface $creditHistory): self
  93. {
  94. if (!$this->creditHistories->contains($creditHistory)) {
  95. $this->creditHistories[] = $creditHistory;
  96. $creditHistory->setUserMerchant($this);
  97. }
  98. return $this;
  99. }
  100. public function removeCreditHistory(CreditHistoryInterface $creditHistory): self
  101. {
  102. if ($this->creditHistories->contains($creditHistory)) {
  103. $this->creditHistories->removeElement($creditHistory);
  104. // set the owning side to null (unless already changed)
  105. if ($creditHistory->getUserMerchant() === $this) {
  106. $creditHistory->setUserMerchant(null);
  107. }
  108. }
  109. return $this;
  110. }
  111. public function getActive(): ?bool
  112. {
  113. return $this->active;
  114. }
  115. public function setActive(bool $active): self
  116. {
  117. $this->active = $active;
  118. return $this;
  119. }
  120. }