src/Entity/Account/Account.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Account;
  3. use App\Entity\Inquiry\InquiryInterface;
  4. use App\Entity\Traits\Inquiry\InquiryTrait;
  5. use App\Entity\Traits\ModifiedLifecycleTrait;
  6. use App\Entity\Traits\ModifiedTimeTrait;
  7. use App\Repository\Account\AccountRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. /**
  15.  * @ORM\Entity(repositoryClass=AccountRepository::class)
  16.  * @ORM\Table(name="account")
  17.  * @ORM\HasLifecycleCallbacks()
  18.  * @UniqueEntity(fields={"email"}, message="このメールアドレスはすでに登録されています")
  19.  */
  20. class Account implements UserInterfacePasswordAuthenticatedUserInterfaceInquiryInterface
  21. {
  22.     use InquiryTrait;
  23.     use ModifiedTimeTrait;
  24.     use ModifiedLifecycleTrait;
  25.     public function getMailSendConfig(): array {
  26.         return [
  27.             "to_client" => [
  28.                 "twigTextTemplate" => "mail/contact/client.txt.twig",
  29.                 "subject" => "掲載希望がありました",
  30.                 "twigAssign" => [
  31.                     "inquiry" => $this
  32.                 ]
  33. //              send to address. 未指定で global_clientに送る
  34. //              "to" => ["to addresses..."]
  35. //              cc
  36. //              "cc" => ["cc addresses"]
  37. //              bcc
  38. //              "bcc" => ["bcc addresses"]
  39. //              replyTo
  40. //              "replyTo" => "reply address"
  41. //              returnPath
  42. //              "returnPath" => "return path"
  43.             ],
  44.             "reply" => [
  45.                 "twigTextTemplate" => "mail/contact/reply.txt.twig",
  46.                 "subject" => "【自動返信】掲載希望のお申し込み",
  47.                 "to" => [$this->getEmail()],
  48.                 "twigAssign" => [
  49.                     "inquiry" => $this
  50.                 ]
  51.             ]
  52.         ];
  53.     }
  54.     /**
  55.      * @ORM\Id
  56.      * @ORM\GeneratedValue
  57.      * @ORM\Column(type="bigint")
  58.      */
  59.     private $id;
  60.     /**
  61.      * @ORM\Column(type="string", length=180, unique=true)
  62.      */
  63.     private $email;
  64.     /**
  65.      * @ORM\Column(type="json")
  66.      */
  67.     private $roles = [];
  68.     /**
  69.      * @var string The hashed password
  70.      * @ORM\Column(type="string")
  71.      */
  72.     private $password;
  73.     /**
  74.      * @ORM\OneToOne(targetEntity=Admin::class, mappedBy="Account", cascade={"persist", "remove"})
  75.      */
  76.     private $admin;
  77.     /**
  78.      * @ORM\OneToOne(targetEntity=User::class, mappedBy="Account", cascade={"persist", "remove"})
  79.      */
  80.     private $user;
  81.     /**
  82.      * @ORM\OneToMany(targetEntity=ApiToken::class, mappedBy="Account", orphanRemoval=true)
  83.      */
  84.     private $apiTokens;
  85.     /**
  86.      * @ORM\OneToOne(targetEntity=Owner::class, mappedBy="Account", cascade={"persist", "remove"})
  87.      */
  88.     private $owner;
  89.     public function __construct()
  90.     {
  91.         $this->apiTokens = new ArrayCollection();
  92.     }
  93.     public function getId(): ?int
  94.     {
  95.         return $this->id;
  96.     }
  97.     public function getEmail(): ?string
  98.     {
  99.         return $this->email;
  100.     }
  101.     public function setEmail(string $email): self
  102.     {
  103.         $this->email $email;
  104.         return $this;
  105.     }
  106.     /**
  107.      * A visual identifier that represents this user.
  108.      *
  109.      * @see UserInterface
  110.      */
  111.     public function getUserIdentifier(): string
  112.     {
  113.         return (string) $this->email;
  114.     }
  115.     /**
  116.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  117.      */
  118.     public function getUsername(): string
  119.     {
  120.         return (string) $this->email;
  121.     }
  122.     /**
  123.      * @see UserInterface
  124.      */
  125.     public function getRoles(): array
  126.     {
  127.         $roles $this->roles;
  128.         // guarantee every user at least has ROLE_USER
  129. //        $roles[] = 'ROLE_USER';
  130.         return array_unique($roles);
  131.     }
  132.     public function setRoles(array $roles): self
  133.     {
  134.         $this->roles $roles;
  135.         return $this;
  136.     }
  137.     /**
  138.      * @see PasswordAuthenticatedUserInterface
  139.      */
  140.     public function getPassword(): string
  141.     {
  142.         return $this->password;
  143.     }
  144.     public function setPassword(string $password): self
  145.     {
  146.         $this->password $password;
  147.         return $this;
  148.     }
  149.     /**
  150.      * Returning a salt is only needed, if you are not using a modern
  151.      * hashing algorithm (e.g. bcrypt or sodium) in your login.yaml.
  152.      *
  153.      * @see UserInterface
  154.      */
  155.     public function getSalt(): ?string
  156.     {
  157.         return null;
  158.     }
  159.     /**
  160.      * @see UserInterface
  161.      */
  162.     public function eraseCredentials()
  163.     {
  164.         // If you store any temporary, sensitive data on the user, clear it here
  165.         // $this->plainPassword = null;
  166.     }
  167.     public function getAdmin(): ?Admin
  168.     {
  169.         return $this->admin;
  170.     }
  171.     public function setAdmin(Admin $admin): self
  172.     {
  173.         // set the owning side of the relation if necessary
  174.         if ($admin->getAccount() !== $this) {
  175.             $admin->setAccount($this);
  176.         }
  177.         $this->admin $admin;
  178.         return $this;
  179.     }
  180.     public function getUser(): ?User
  181.     {
  182.         return $this->user;
  183.     }
  184.     public function setUser(User $user): self
  185.     {
  186.         // set the owning side of the relation if necessary
  187.         if ($user->getAccount() !== $this) {
  188.             $user->setAccount($this);
  189.         }
  190.         $this->user $user;
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return Collection|ApiToken[]
  195.      */
  196.     public function getApiTokens(): Collection
  197.     {
  198.         return $this->apiTokens;
  199.     }
  200.     public function addApiToken(ApiToken $apiToken): self
  201.     {
  202.         if (!$this->apiTokens->contains($apiToken)) {
  203.             $this->apiTokens[] = $apiToken;
  204.             $apiToken->setAccount($this);
  205.         }
  206.         return $this;
  207.     }
  208.     public function removeApiToken(ApiToken $apiToken): self
  209.     {
  210.         if ($this->apiTokens->removeElement($apiToken)) {
  211.             // set the owning side to null (unless already changed)
  212.             if ($apiToken->getAccount() === $this) {
  213.                 $apiToken->setAccount(null);
  214.             }
  215.         }
  216.         return $this;
  217.     }
  218.     public function getOwner(): ?Owner
  219.     {
  220.         return $this->owner;
  221.     }
  222.     public function setOwner(Owner $owner): self
  223.     {
  224.         // set the owning side of the relation if necessary
  225.         if ($owner->getAccount() !== $this) {
  226.             $owner->setAccount($this);
  227.         }
  228.         $this->owner $owner;
  229.         return $this;
  230.     }
  231.     public function haveRole(string $role): bool
  232.     {
  233.         return in_array($role$this->rolestrue);
  234.     }
  235. }