<?php
namespace Xearts\Bundle\TaobaoDaikoBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert;
use Symfony\Component\Validator\Constraints as Assert;
/**
* User.
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Xearts\Bundle\TaobaoDaikoBundle\Repository\UserRepository")
*/
class User extends BaseUser
{
public const ROLE_USER_API = 'ROLE_USER_API';
public const ROLE_WEBHOOK = 'ROLE_WEBHOOK';
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var Address
* @ORM\Embedded(class = "Address")
*/
private $address;
/**
* @var Prefecture
*
* @ORM\ManyToOne(targetEntity="Prefecture")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="address_prefecture_id", referencedColumnName="id")
* })
* @Assert\NotBlank(
* message="user.prefecture.not_blank",
* groups={"MyRegistration", "MyProfile"}
* )
*/
private $addressPrefecture;
/**
* @var int チャージ金額(円)
*
* @ORM\Column(name="charge_amount", type="integer", nullable=true)
*/
private $chargeAmount;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime", nullable=false)
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=false)
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @SecurityAssert\UserPassword(
* message = "現在のパスワードがちがいます",
* groups={"MyPassword"}
* )
*/
private $oldPassword;
/**
* One User has Many Deposit.
*
* @ORM\OneToMany(targetEntity="Xearts\Bundle\TaobaoDaikoBundle\Entity\Deposit", mappedBy="user")
* @ORM\OrderBy({"id" = "DESC"})
*/
private $deposits;
/**
* @var int
*
* @ORM\Column(name="complete_count", type="integer", nullable=false, options={"default"=0})
*/
private $completeCount = 0;
/**
* @var int
*
* @ORM\Column(name="cancel_count", type="integer", nullable=false, options={"default"=0})
*/
private $cancelCount = 0;
/**
* @var arrayCollection
* One User has Many Estimate
* @ORM\OneToMany(targetEntity="Xearts\Bundle\TaobaoDaikoBundle\Entity\Estimate", mappedBy="user")
* @ORM\OrderBy({"id" = "DESC"})
*/
private $estimates;
/**
* One User has Many ApiTokens.
*
* @var Collection
* @ORM\OneToMany(targetEntity="Xearts\Bundle\TaobaoDaikoBundle\Entity\ApiToken", mappedBy="user")
* @ORM\OrderBy({"id" = "DESC"})
*/
private $apiTokens;
/**
* One User has Many WebHooks.
*
* @var Collection
* @ORM\OneToMany(targetEntity="Xearts\Bundle\TaobaoDaikoBundle\Entity\WebHook", mappedBy="user")
* @ORM\OrderBy({"id" = "DESC"})
*/
private $webHooks;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $adminNote;
public function __construct()
{
parent::__construct();
$this->address = new Address();
$this->deposits = new ArrayCollection();
$this->estimates = new ArrayCollection();
$this->apiTokens = new ArrayCollection();
$this->webHooks = new ArrayCollection();
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
public function setEmail($email)
{
parent::setUsername($email);
return parent::setEmail($email);
}
public function setEmailCanonical($emailCanonical)
{
parent::setUsernameCanonical($emailCanonical);
return parent::setEmailCanonical($emailCanonical);
}
/**
* @return Address
*/
public function getAddress()
{
return $this->address;
}
/**
* @return User
*/
public function setAddress(Address $address)
{
$this->address = $address;
return $this;
}
/**
* @return mixed
*/
public function getAddressPrefecture()
{
return $this->addressPrefecture;
}
/**
* @param mixed $addressPrefecture
*
* @return User
*/
public function setAddressPrefecture($addressPrefecture)
{
$this->addressPrefecture = $addressPrefecture;
return $this;
}
/**
* @return int
*
* @deprecated use deposits
*/
public function getChargeAmount()
{
return $this->chargeAmount;
}
/**
* @param int $chargeAmount
*
* @return User
*
* @deprecated use deposits
*/
public function setChargeAmount($chargeAmount)
{
$this->chargeAmount = $chargeAmount;
return $this;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*
* @return User
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return mixed
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @param mixed $updatedAt
*
* @return User
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return string
*/
public function getOldPassword()
{
return $this->oldPassword;
}
/**
* @param string $oldPassword
*
* @return User
*/
public function setOldPassword($oldPassword)
{
$this->oldPassword = $oldPassword;
return $this;
}
/**
* @return ArrayCollection
*/
public function getDeposits()
{
return $this->deposits;
}
/**
* @param mixed $deposits
*
* @return $this
*/
public function setDeposits($deposits)
{
$this->deposits = $deposits;
return $this;
}
/**
* @return int
*/
public function getDepositBalance()
{
/** @var Deposit $deposit */
$deposit = $this->deposits->first();
if ($deposit) {
return $deposit->getBalance();
}
return 0;
}
/**
* @return int
*/
public function getCompleteCount()
{
return $this->completeCount;
}
/**
* @param int $completeCount
*
* @return $this
*/
public function setCompleteCount($completeCount)
{
$this->completeCount = $completeCount;
return $this;
}
/**
* @return int
*/
public function getCancelCount()
{
return $this->cancelCount;
}
/**
* @param int $cancelCount
*
* @return $this
*/
public function setCancelCount($cancelCount)
{
$this->cancelCount = $cancelCount;
return $this;
}
/**
* @return ArrayCollection
*/
public function getEstimates()
{
return $this->estimates;
}
public function getApiTokens(): Collection
{
return $this->apiTokens;
}
public function setApiTokens(Collection $apiTokens): self
{
$this->apiTokens = $apiTokens;
return $this;
}
public function getWebHooks(): Collection
{
if (!$this->webHooks) {
$this->webHooks = new ArrayCollection();
}
return $this->webHooks;
}
public function setWebHooks(Collection $webHooks): self
{
$this->webHooks = $webHooks;
return $this;
}
public function getAdminNote(): ?string
{
return $this->adminNote;
}
public function setAdminNote(?string $adminNote): self
{
$this->adminNote = $adminNote;
return $this;
}
public function getNameForAdmin(): string
{
$nameForAdmin = $this->getAddress()->getName();
if ($this->adminNote) {
$adminNameFormat = '%1$s【%2$s】';
$nameForAdmin = sprintf($adminNameFormat, $nameForAdmin, $this->adminNote);
}
return $nameForAdmin;
}
}