src/Entity/User/ShopUser.php line 20

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\User;
  4. use App\Entity\LicenceFile;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping\MappedSuperclass;
  8. use Doctrine\ORM\Mapping\Table;
  9. use Sylius\Component\Core\Model\ShopUser as BaseShopUser;
  10. use Sylius\Component\Core\Model\ShopUserInterface;
  11. use Doctrine\ORM\Mapping as ORM;
  12. /**
  13. * @ORM\Entity()
  14. * @Table(name="sylius_shop_user")
  15. */
  16. class ShopUser extends BaseShopUser implements ShopUserInterface
  17. {
  18. /**
  19. * @ORM\OneToMany(targetEntity="App\Entity\LicenceFile", mappedBy="user", orphanRemoval=true)
  20. */
  21. private $licenceFiles;
  22. public function getUserIdentifier(): string
  23. {
  24. return $this->getUsername();
  25. }
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. $this->licenceFiles = new ArrayCollection();
  30. }
  31. /**
  32. * @return Collection|LicenceFile[]
  33. */
  34. public function getLicenceFiles(): Collection
  35. {
  36. return $this->licenceFiles;
  37. }
  38. public function addLicenceFile(LicenceFile $licenceFile): self
  39. {
  40. if (!$this->licenceFiles->contains($licenceFile)) {
  41. $this->licenceFiles[] = $licenceFile;
  42. $licenceFile->setUser($this);
  43. }
  44. return $this;
  45. }
  46. public function removeLicenceFile(LicenceFile $licenceFile): self
  47. {
  48. if ($this->licenceFiles->contains($licenceFile)) {
  49. $this->licenceFiles->removeElement($licenceFile);
  50. // set the owning side to null (unless already changed)
  51. if ($licenceFile->getUser() === $this) {
  52. $licenceFile->setUser(null);
  53. }
  54. }
  55. return $this;
  56. }
  57. }