vendor/xearts/taobao-daiko-bundle/src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace Xearts\Bundle\TaobaoDaikoBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use FOS\UserBundle\Model\User as BaseUser;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * User.
  12.  *
  13.  * @ORM\Table()
  14.  * @ORM\Entity(repositoryClass="Xearts\Bundle\TaobaoDaikoBundle\Repository\UserRepository")
  15.  */
  16. class User extends BaseUser
  17. {
  18.     public const ROLE_USER_API 'ROLE_USER_API';
  19.     public const ROLE_WEBHOOK 'ROLE_WEBHOOK';
  20.     /**
  21.      * @var int
  22.      *
  23.      * @ORM\Column(name="id", type="integer")
  24.      * @ORM\Id
  25.      * @ORM\GeneratedValue(strategy="AUTO")
  26.      */
  27.     protected $id;
  28.     /**
  29.      * @var Address
  30.      * @ORM\Embedded(class = "Address")
  31.      */
  32.     private $address;
  33.     /**
  34.      * @var Prefecture
  35.      *
  36.      * @ORM\ManyToOne(targetEntity="Prefecture")
  37.      * @ORM\JoinColumns({
  38.      *   @ORM\JoinColumn(name="address_prefecture_id", referencedColumnName="id")
  39.      * })
  40.      * @Assert\NotBlank(
  41.      *  message="user.prefecture.not_blank",
  42.      *  groups={"MyRegistration", "MyProfile"}
  43.      * )
  44.      */
  45.     private $addressPrefecture;
  46.     /**
  47.      * @var int チャージ金額(円)
  48.      *
  49.      * @ORM\Column(name="charge_amount", type="integer", nullable=true)
  50.      */
  51.     private $chargeAmount;
  52.     /**
  53.      * @var \DateTime
  54.      *
  55.      * @ORM\Column(name="created_at", type="datetime", nullable=false)
  56.      * @Gedmo\Timestampable(on="create")
  57.      */
  58.     private $createdAt;
  59.     /**
  60.      * @var \DateTime
  61.      *
  62.      * @ORM\Column(name="updated_at", type="datetime", nullable=false)
  63.      * @Gedmo\Timestampable(on="update")
  64.      */
  65.     private $updatedAt;
  66.     /**
  67.      * @SecurityAssert\UserPassword(
  68.      *  message = "現在のパスワードがちがいます",
  69.      *  groups={"MyPassword"}
  70.      * )
  71.      */
  72.     private $oldPassword;
  73.     /**
  74.      * One User has Many Deposit.
  75.      *
  76.      * @ORM\OneToMany(targetEntity="Xearts\Bundle\TaobaoDaikoBundle\Entity\Deposit", mappedBy="user")
  77.      * @ORM\OrderBy({"id" = "DESC"})
  78.      */
  79.     private $deposits;
  80.     /**
  81.      * @var int
  82.      *
  83.      * @ORM\Column(name="complete_count", type="integer", nullable=false, options={"default"=0})
  84.      */
  85.     private $completeCount 0;
  86.     /**
  87.      * @var int
  88.      *
  89.      * @ORM\Column(name="cancel_count", type="integer", nullable=false, options={"default"=0})
  90.      */
  91.     private $cancelCount 0;
  92.     /**
  93.      * @var arrayCollection
  94.      *                      One User has Many Estimate
  95.      * @ORM\OneToMany(targetEntity="Xearts\Bundle\TaobaoDaikoBundle\Entity\Estimate", mappedBy="user")
  96.      * @ORM\OrderBy({"id" = "DESC"})
  97.      */
  98.     private $estimates;
  99.     /**
  100.      * One User has Many ApiTokens.
  101.      *
  102.      * @var Collection
  103.      * @ORM\OneToMany(targetEntity="Xearts\Bundle\TaobaoDaikoBundle\Entity\ApiToken", mappedBy="user")
  104.      * @ORM\OrderBy({"id" = "DESC"})
  105.      */
  106.     private $apiTokens;
  107.     /**
  108.      * One User has Many WebHooks.
  109.      *
  110.      * @var Collection
  111.      * @ORM\OneToMany(targetEntity="Xearts\Bundle\TaobaoDaikoBundle\Entity\WebHook", mappedBy="user")
  112.      * @ORM\OrderBy({"id" = "DESC"})
  113.      */
  114.     private $webHooks;
  115.     /**
  116.      * @ORM\Column(type="string", length=255, nullable=true)
  117.      */
  118.     private $adminNote;
  119.     public function __construct()
  120.     {
  121.         parent::__construct();
  122.         $this->address = new Address();
  123.         $this->deposits = new ArrayCollection();
  124.         $this->estimates = new ArrayCollection();
  125.         $this->apiTokens = new ArrayCollection();
  126.         $this->webHooks = new ArrayCollection();
  127.     }
  128.     /**
  129.      * Get id.
  130.      *
  131.      * @return int
  132.      */
  133.     public function getId()
  134.     {
  135.         return $this->id;
  136.     }
  137.     public function setEmail($email)
  138.     {
  139.         parent::setUsername($email);
  140.         return parent::setEmail($email);
  141.     }
  142.     public function setEmailCanonical($emailCanonical)
  143.     {
  144.         parent::setUsernameCanonical($emailCanonical);
  145.         return parent::setEmailCanonical($emailCanonical);
  146.     }
  147.     /**
  148.      * @return Address
  149.      */
  150.     public function getAddress()
  151.     {
  152.         return $this->address;
  153.     }
  154.     /**
  155.      * @return User
  156.      */
  157.     public function setAddress(Address $address)
  158.     {
  159.         $this->address $address;
  160.         return $this;
  161.     }
  162.     /**
  163.      * @return mixed
  164.      */
  165.     public function getAddressPrefecture()
  166.     {
  167.         return $this->addressPrefecture;
  168.     }
  169.     /**
  170.      * @param mixed $addressPrefecture
  171.      *
  172.      * @return User
  173.      */
  174.     public function setAddressPrefecture($addressPrefecture)
  175.     {
  176.         $this->addressPrefecture $addressPrefecture;
  177.         return $this;
  178.     }
  179.     /**
  180.      * @return int
  181.      *
  182.      * @deprecated use deposits
  183.      */
  184.     public function getChargeAmount()
  185.     {
  186.         return $this->chargeAmount;
  187.     }
  188.     /**
  189.      * @param int $chargeAmount
  190.      *
  191.      * @return User
  192.      *
  193.      * @deprecated use deposits
  194.      */
  195.     public function setChargeAmount($chargeAmount)
  196.     {
  197.         $this->chargeAmount $chargeAmount;
  198.         return $this;
  199.     }
  200.     /**
  201.      * @return \DateTime
  202.      */
  203.     public function getCreatedAt()
  204.     {
  205.         return $this->createdAt;
  206.     }
  207.     /**
  208.      * @param \DateTime $createdAt
  209.      *
  210.      * @return User
  211.      */
  212.     public function setCreatedAt($createdAt)
  213.     {
  214.         $this->createdAt $createdAt;
  215.         return $this;
  216.     }
  217.     /**
  218.      * @return mixed
  219.      */
  220.     public function getUpdatedAt()
  221.     {
  222.         return $this->updatedAt;
  223.     }
  224.     /**
  225.      * @param mixed $updatedAt
  226.      *
  227.      * @return User
  228.      */
  229.     public function setUpdatedAt($updatedAt)
  230.     {
  231.         $this->updatedAt $updatedAt;
  232.         return $this;
  233.     }
  234.     /**
  235.      * @return string
  236.      */
  237.     public function getOldPassword()
  238.     {
  239.         return $this->oldPassword;
  240.     }
  241.     /**
  242.      * @param string $oldPassword
  243.      *
  244.      * @return User
  245.      */
  246.     public function setOldPassword($oldPassword)
  247.     {
  248.         $this->oldPassword $oldPassword;
  249.         return $this;
  250.     }
  251.     /**
  252.      * @return ArrayCollection
  253.      */
  254.     public function getDeposits()
  255.     {
  256.         return $this->deposits;
  257.     }
  258.     /**
  259.      * @param mixed $deposits
  260.      *
  261.      * @return $this
  262.      */
  263.     public function setDeposits($deposits)
  264.     {
  265.         $this->deposits $deposits;
  266.         return $this;
  267.     }
  268.     /**
  269.      * @return int
  270.      */
  271.     public function getDepositBalance()
  272.     {
  273.         /** @var Deposit $deposit */
  274.         $deposit $this->deposits->first();
  275.         if ($deposit) {
  276.             return $deposit->getBalance();
  277.         }
  278.         return 0;
  279.     }
  280.     /**
  281.      * @return int
  282.      */
  283.     public function getCompleteCount()
  284.     {
  285.         return $this->completeCount;
  286.     }
  287.     /**
  288.      * @param int $completeCount
  289.      *
  290.      * @return $this
  291.      */
  292.     public function setCompleteCount($completeCount)
  293.     {
  294.         $this->completeCount $completeCount;
  295.         return $this;
  296.     }
  297.     /**
  298.      * @return int
  299.      */
  300.     public function getCancelCount()
  301.     {
  302.         return $this->cancelCount;
  303.     }
  304.     /**
  305.      * @param int $cancelCount
  306.      *
  307.      * @return $this
  308.      */
  309.     public function setCancelCount($cancelCount)
  310.     {
  311.         $this->cancelCount $cancelCount;
  312.         return $this;
  313.     }
  314.     /**
  315.      * @return ArrayCollection
  316.      */
  317.     public function getEstimates()
  318.     {
  319.         return $this->estimates;
  320.     }
  321.     public function getApiTokens(): Collection
  322.     {
  323.         return $this->apiTokens;
  324.     }
  325.     public function setApiTokens(Collection $apiTokens): self
  326.     {
  327.         $this->apiTokens $apiTokens;
  328.         return $this;
  329.     }
  330.     public function getWebHooks(): Collection
  331.     {
  332.         if (!$this->webHooks) {
  333.             $this->webHooks = new ArrayCollection();
  334.         }
  335.         return $this->webHooks;
  336.     }
  337.     public function setWebHooks(Collection $webHooks): self
  338.     {
  339.         $this->webHooks $webHooks;
  340.         return $this;
  341.     }
  342.     public function getAdminNote(): ?string
  343.     {
  344.         return $this->adminNote;
  345.     }
  346.     public function setAdminNote(?string $adminNote): self
  347.     {
  348.         $this->adminNote $adminNote;
  349.         return $this;
  350.     }
  351.     public function getNameForAdmin(): string
  352.     {
  353.         $nameForAdmin $this->getAddress()->getName();
  354.         if ($this->adminNote) {
  355.             $adminNameFormat '%1$s【%2$s】';
  356.             $nameForAdmin sprintf($adminNameFormat$nameForAdmin$this->adminNote);
  357.         }
  358.         return $nameForAdmin;
  359.     }
  360. }