<?php
namespace App\Entity\Account;
use App\Entity\Inquiry\InquiryInterface;
use App\Entity\Traits\Inquiry\InquiryTrait;
use App\Entity\Traits\ModifiedLifecycleTrait;
use App\Entity\Traits\ModifiedTimeTrait;
use App\Repository\Account\AccountRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=AccountRepository::class)
* @ORM\Table(name="account")
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity(fields={"email"}, message="このメールアドレスはすでに登録されています")
*/
class Account implements UserInterface, PasswordAuthenticatedUserInterface, InquiryInterface
{
use InquiryTrait;
use ModifiedTimeTrait;
use ModifiedLifecycleTrait;
public function getMailSendConfig(): array {
return [
"to_client" => [
"twigTextTemplate" => "mail/contact/client.txt.twig",
"subject" => "掲載希望がありました",
"twigAssign" => [
"inquiry" => $this
]
// send to address. 未指定で global_clientに送る
// "to" => ["to addresses..."]
// cc
// "cc" => ["cc addresses"]
// bcc
// "bcc" => ["bcc addresses"]
// replyTo
// "replyTo" => "reply address"
// returnPath
// "returnPath" => "return path"
],
"reply" => [
"twigTextTemplate" => "mail/contact/reply.txt.twig",
"subject" => "【自動返信】掲載希望のお申し込み",
"to" => [$this->getEmail()],
"twigAssign" => [
"inquiry" => $this
]
]
];
}
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="bigint")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\OneToOne(targetEntity=Admin::class, mappedBy="Account", cascade={"persist", "remove"})
*/
private $admin;
/**
* @ORM\OneToOne(targetEntity=User::class, mappedBy="Account", cascade={"persist", "remove"})
*/
private $user;
/**
* @ORM\OneToMany(targetEntity=ApiToken::class, mappedBy="Account", orphanRemoval=true)
*/
private $apiTokens;
/**
* @ORM\OneToOne(targetEntity=Owner::class, mappedBy="Account", cascade={"persist", "remove"})
*/
private $owner;
public function __construct()
{
$this->apiTokens = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
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;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your login.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getAdmin(): ?Admin
{
return $this->admin;
}
public function setAdmin(Admin $admin): self
{
// set the owning side of the relation if necessary
if ($admin->getAccount() !== $this) {
$admin->setAccount($this);
}
$this->admin = $admin;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(User $user): self
{
// set the owning side of the relation if necessary
if ($user->getAccount() !== $this) {
$user->setAccount($this);
}
$this->user = $user;
return $this;
}
/**
* @return Collection|ApiToken[]
*/
public function getApiTokens(): Collection
{
return $this->apiTokens;
}
public function addApiToken(ApiToken $apiToken): self
{
if (!$this->apiTokens->contains($apiToken)) {
$this->apiTokens[] = $apiToken;
$apiToken->setAccount($this);
}
return $this;
}
public function removeApiToken(ApiToken $apiToken): self
{
if ($this->apiTokens->removeElement($apiToken)) {
// set the owning side to null (unless already changed)
if ($apiToken->getAccount() === $this) {
$apiToken->setAccount(null);
}
}
return $this;
}
public function getOwner(): ?Owner
{
return $this->owner;
}
public function setOwner(Owner $owner): self
{
// set the owning side of the relation if necessary
if ($owner->getAccount() !== $this) {
$owner->setAccount($this);
}
$this->owner = $owner;
return $this;
}
public function haveRole(string $role): bool
{
return in_array($role, $this->roles, true);
}
}