|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
-
- namespace Lc\CaracoleBundle\Model\User;
-
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Collection;
- use Doctrine\ORM\Mapping as ORM;
- use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
- use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
- use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
- use Lc\CaracoleBundle\Model\Section\SectionInterface;
- use Lc\SovBundle\Doctrine\EntityInterface;
-
- /**
- * @ORM\MappedSuperclass()
- *
- */
- abstract class UserMerchantModel implements FilterMerchantInterface, EntityInterface, UserMerchantInterface
- {
- /**
- * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\UserInterface", inversedBy="userMerchants")
- * @ORM\JoinColumn(nullable=false)
- */
- protected $user;
-
- /**
- * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
- * @ORM\JoinColumn(nullable=false)
- */
- protected $merchant;
-
- /**
- * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
- */
- protected $currentAdminSection;
-
- /**
- * @ORM\Column(type="float", nullable=true)
- */
- protected $credit;
-
- /**
- * @ORM\Column(type="boolean")
- */
- protected $creditActive = false;
-
- /**
- * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface", mappedBy="userMerchant")
- */
- protected $creditHistories;
-
- /**
- * @ORM\Column(type="boolean")
- */
- protected $active = true;
-
- /**
- * @ORM\Column(type="json")
- */
- protected $roles = [];
-
- public function __construct()
- {
- $this->creditHistories = new ArrayCollection();
- }
-
- public function getUser(): ?UserModel
- {
- return $this->user;
- }
-
- public function setUser(?UserModel $user): self
- {
- $this->user = $user;
-
- return $this;
- }
-
- public function getMerchant(): ?MerchantInterface
- {
- return $this->merchant;
- }
-
- public function setMerchant(?MerchantInterface $merchant): self
- {
- $this->merchant = $merchant;
-
- return $this;
- }
-
- public function getCurrentAdminSection(): ?SectionInterface
- {
- return $this->currentAdminSection;
- }
-
- public function setCurrentAdminSection(?SectionInterface $currentAdminSection): self
- {
- $this->currentAdminSection = $currentAdminSection;
-
- return $this;
- }
-
- public function getCredit(): ?float
- {
- return $this->credit;
- }
-
- public function setCredit(?float $credit): self
- {
- $this->credit = $credit;
-
- return $this;
- }
-
- public function getCreditActive(): ?bool
- {
- return $this->creditActive;
- }
-
- public function isCreditActive(): bool
- {
- return $this->creditActive;
- }
-
- public function setCreditActive(bool $creditActive): self
- {
- $this->creditActive = $creditActive;
-
- return $this;
- }
-
- /**
- * @return Collection|CreditHistoryInterface[]
- */
- public function getCreditHistories(): Collection
- {
- return $this->creditHistories;
- }
-
- public function addCreditHistory(CreditHistoryInterface $creditHistory): self
- {
- if (!$this->creditHistories->contains($creditHistory)) {
- $this->creditHistories[] = $creditHistory;
- $creditHistory->setUserMerchant($this);
- }
-
- return $this;
- }
-
- public function removeCreditHistory(CreditHistoryInterface $creditHistory): self
- {
- if ($this->creditHistories->contains($creditHistory)) {
- $this->creditHistories->removeElement($creditHistory);
- // set the owning side to null (unless already changed)
- if ($creditHistory->getUserMerchant() === $this) {
- $creditHistory->setUserMerchant(null);
- }
- }
-
- return $this;
- }
-
- public function getActive(): ?bool
- {
- return $this->active;
- }
-
- public function setActive(bool $active): self
- {
- $this->active = $active;
-
- return $this;
- }
-
-
- public function getRoles(): array
- {
- $roles = $this->roles;
- // guarantee every user at least has ROLE_USER
- $roles[] = 'ROLE_USER';
-
- return array_unique($roles);
- }
-
- public function setRoles(array $roles): self
- {
- $this->roles = $roles;
-
- return $this;
- }
-
- public function hasRole($role)
- {
- return in_array(strtoupper($role), $this->getRoles(), true);
- }
- }
|