Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

UserMerchantModel.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  10. use Lc\SovBundle\Doctrine\EntityInterface;
  11. /**
  12. * @ORM\MappedSuperclass()
  13. *
  14. */
  15. abstract class UserMerchantModel implements FilterMerchantInterface, EntityInterface
  16. {
  17. /**
  18. * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface", inversedBy="userMerchants")
  19. * @ORM\JoinColumn(nullable=false)
  20. */
  21. protected $user;
  22. /**
  23. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
  24. * @ORM\JoinColumn(nullable=false)
  25. */
  26. protected $merchant;
  27. /**
  28. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
  29. */
  30. protected $currentAdminSection;
  31. /**
  32. * @ORM\Column(type="float", nullable=true)
  33. */
  34. protected $credit;
  35. /**
  36. * @ORM\Column(type="boolean")
  37. */
  38. protected $creditActive;
  39. /**
  40. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface", mappedBy="userMerchant", orphanRemoval=true)
  41. */
  42. protected $creditHistories;
  43. /**
  44. * @ORM\Column(type="boolean")
  45. */
  46. protected $active;
  47. /**
  48. * @ORM\Column(type="json")
  49. */
  50. protected $roles = [];
  51. public function __construct()
  52. {
  53. $this->creditHistories = new ArrayCollection();
  54. }
  55. public function getUser(): ?UserModel
  56. {
  57. return $this->user;
  58. }
  59. public function setUser(?UserModel $user): self
  60. {
  61. $this->user = $user;
  62. return $this;
  63. }
  64. public function getMerchant(): ?MerchantInterface
  65. {
  66. return $this->merchant;
  67. }
  68. public function setMerchant(?MerchantInterface $merchant): self
  69. {
  70. $this->merchant = $merchant;
  71. return $this;
  72. }
  73. public function getCurrentAdminSection(): ?SectionInterface
  74. {
  75. return $this->currentAdminSection;
  76. }
  77. public function setCurrentAdminSection(?SectionInterface $currentAdminSection): self
  78. {
  79. $this->currentAdminSection = $currentAdminSection;
  80. return $this;
  81. }
  82. public function getCredit(): ?float
  83. {
  84. return $this->credit;
  85. }
  86. public function setCredit(?float $credit): self
  87. {
  88. $this->credit = $credit;
  89. return $this;
  90. }
  91. public function getCreditActive(): ?bool
  92. {
  93. return $this->creditActive;
  94. }
  95. public function isCreditActive(): bool
  96. {
  97. return $this->creditActive;
  98. }
  99. public function setCreditActive(bool $creditActive): self
  100. {
  101. $this->creditActive = $creditActive;
  102. return $this;
  103. }
  104. /**
  105. * @return Collection|CreditHistoryInterface[]
  106. */
  107. public function getCreditHistories(): Collection
  108. {
  109. return $this->creditHistories;
  110. }
  111. public function addCreditHistory(CreditHistoryInterface $creditHistory): self
  112. {
  113. if (!$this->creditHistories->contains($creditHistory)) {
  114. $this->creditHistories[] = $creditHistory;
  115. $creditHistory->setUserMerchant($this);
  116. }
  117. return $this;
  118. }
  119. public function removeCreditHistory(CreditHistoryInterface $creditHistory): self
  120. {
  121. if ($this->creditHistories->contains($creditHistory)) {
  122. $this->creditHistories->removeElement($creditHistory);
  123. // set the owning side to null (unless already changed)
  124. if ($creditHistory->getUserMerchant() === $this) {
  125. $creditHistory->setUserMerchant(null);
  126. }
  127. }
  128. return $this;
  129. }
  130. public function getActive(): ?bool
  131. {
  132. return $this->active;
  133. }
  134. public function setActive(bool $active): self
  135. {
  136. $this->active = $active;
  137. return $this;
  138. }
  139. public function getRoles(): array
  140. {
  141. $roles = $this->roles;
  142. // guarantee every user at least has ROLE_USER
  143. $roles[] = 'ROLE_USER';
  144. return array_unique($roles);
  145. }
  146. public function setRoles(array $roles): self
  147. {
  148. $this->roles = $roles;
  149. return $this;
  150. }
  151. public function hasRole($role)
  152. {
  153. return in_array(strtoupper($role), $this->getRoles(), true);
  154. }
  155. }