src/Eccube/Entity/Member.php line 22

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of EC-CUBE
  4. *
  5. * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6. *
  7. * http://www.ec-cube.co.jp/
  8. *
  9. * For the full copyright and license information, please view the LICENSE
  10. * file that was distributed with this source code.
  11. */
  12. namespace Eccube\Entity;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  15. use Symfony\Component\Security\Core\User\UserInterface;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use Symfony\Component\Validator\Mapping\ClassMetadata;
  18. if (!class_exists('\Eccube\Entity\Member')) {
  19. /**
  20. * Member
  21. *
  22. * @ORM\Table(name="dtb_member")
  23. * @ORM\InheritanceType("SINGLE_TABLE")
  24. * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
  25. * @ORM\HasLifecycleCallbacks()
  26. * @ORM\Entity(repositoryClass="Eccube\Repository\MemberRepository")
  27. */
  28. class Member extends \Eccube\Entity\AbstractEntity implements UserInterface, \Serializable
  29. {
  30. public static function loadValidatorMetadata(ClassMetadata $metadata)
  31. {
  32. $metadata->addConstraint(new UniqueEntity([
  33. 'fields' => 'login_id',
  34. 'message' => 'form_error.member_already_exists',
  35. ]));
  36. }
  37. /**
  38. * @return string
  39. */
  40. public function __toString()
  41. {
  42. return (string) $this->getName();
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function getRoles()
  48. {
  49. return ['ROLE_ADMIN'];
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function getUsername()
  55. {
  56. return $this->login_id;
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function eraseCredentials()
  62. {
  63. }
  64. /**
  65. * @var int
  66. *
  67. * @ORM\Column(name="id", type="integer", options={"unsigned":true})
  68. * @ORM\Id
  69. * @ORM\GeneratedValue(strategy="IDENTITY")
  70. */
  71. private $id;
  72. /**
  73. * @var string|null
  74. *
  75. * @ORM\Column(name="name", type="string", length=255, nullable=true)
  76. */
  77. private $name;
  78. /**
  79. * @var string|null
  80. *
  81. * @ORM\Column(name="department", type="string", length=255, nullable=true)
  82. */
  83. private $department;
  84. /**
  85. * @var string
  86. *
  87. * @ORM\Column(name="login_id", type="string", length=255)
  88. */
  89. private $login_id;
  90. /**
  91. * @Assert\NotBlank()
  92. * @Assert\Length(max=4096)
  93. */
  94. private $plainPassword;
  95. /**
  96. * @var string
  97. *
  98. * @ORM\Column(name="password", type="string", length=255)
  99. */
  100. private $password;
  101. /**
  102. * @var string
  103. *
  104. * @ORM\Column(name="salt", type="string", length=255, nullable=true)
  105. */
  106. private $salt;
  107. /**
  108. * @var int
  109. *
  110. * @ORM\Column(name="sort_no", type="smallint", options={"unsigned":true})
  111. */
  112. private $sort_no;
  113. /**
  114. * @var string
  115. *
  116. * @ORM\Column(name="two_factor_auth_key",type="string",length=255,nullable=true,options={"fixed":false})
  117. */
  118. private $two_factor_auth_key;
  119. /**
  120. * @ORM\Column(name="two_factor_auth_enabled",type="boolean",nullable=false,options={"default":false})
  121. *
  122. * @var integer
  123. */
  124. private $two_factor_auth_enabled = false;
  125. /**
  126. * @var \DateTime
  127. *
  128. * @ORM\Column(name="create_date", type="datetimetz")
  129. */
  130. private $create_date;
  131. /**
  132. * @var \DateTime
  133. *
  134. * @ORM\Column(name="update_date", type="datetimetz")
  135. */
  136. private $update_date;
  137. /**
  138. * @var \DateTime|null
  139. *
  140. * @ORM\Column(name="login_date", type="datetimetz", nullable=true)
  141. */
  142. private $login_date;
  143. /**
  144. * @var \Eccube\Entity\Master\Work
  145. *
  146. * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Work")
  147. * @ORM\JoinColumns({
  148. * @ORM\JoinColumn(name="work_id", referencedColumnName="id")
  149. * })
  150. */
  151. private $Work;
  152. /**
  153. * @var \Eccube\Entity\Master\Authority
  154. *
  155. * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Authority")
  156. * @ORM\JoinColumns({
  157. * @ORM\JoinColumn(name="authority_id", referencedColumnName="id")
  158. * })
  159. */
  160. private $Authority;
  161. /**
  162. * @var \Eccube\Entity\Member
  163. *
  164. * @ORM\ManyToOne(targetEntity="Eccube\Entity\Member")
  165. * @ORM\JoinColumns({
  166. * @ORM\JoinColumn(name="creator_id", referencedColumnName="id")
  167. * })
  168. */
  169. private $Creator;
  170. /**
  171. * Get id.
  172. *
  173. * @return int
  174. */
  175. public function getId()
  176. {
  177. return $this->id;
  178. }
  179. /**
  180. * Set name.
  181. *
  182. * @param string|null $name
  183. *
  184. * @return Member
  185. */
  186. public function setName($name = null)
  187. {
  188. $this->name = $name;
  189. return $this;
  190. }
  191. /**
  192. * Get name.
  193. *
  194. * @return string|null
  195. */
  196. public function getName()
  197. {
  198. return $this->name;
  199. }
  200. /**
  201. * Set department.
  202. *
  203. * @param string|null $department
  204. *
  205. * @return Member
  206. */
  207. public function setDepartment($department = null)
  208. {
  209. $this->department = $department;
  210. return $this;
  211. }
  212. /**
  213. * Get department.
  214. *
  215. * @return string|null
  216. */
  217. public function getDepartment()
  218. {
  219. return $this->department;
  220. }
  221. /**
  222. * Set loginId.
  223. *
  224. * @param string $loginId
  225. *
  226. * @return Member
  227. */
  228. public function setLoginId($loginId)
  229. {
  230. $this->login_id = $loginId;
  231. return $this;
  232. }
  233. /**
  234. * Get loginId.
  235. *
  236. * @return string
  237. */
  238. public function getLoginId()
  239. {
  240. return $this->login_id;
  241. }
  242. /**
  243. * @return string|null
  244. */
  245. public function getPlainPassword(): ?string
  246. {
  247. return $this->plainPassword;
  248. }
  249. /**
  250. * @param string $password
  251. *
  252. * @return $this
  253. */
  254. public function setPlainPassword(?string $password): self
  255. {
  256. $this->plainPassword = $password;
  257. return $this;
  258. }
  259. /**
  260. * Set password.
  261. *
  262. * @param string $password
  263. *
  264. * @return Member
  265. */
  266. public function setPassword($password)
  267. {
  268. $this->password = $password;
  269. return $this;
  270. }
  271. /**
  272. * Get password.
  273. *
  274. * @return string
  275. */
  276. public function getPassword()
  277. {
  278. return $this->password;
  279. }
  280. /**
  281. * Set salt.
  282. *
  283. * @param string $salt
  284. *
  285. * @return Member
  286. */
  287. public function setSalt($salt)
  288. {
  289. $this->salt = $salt;
  290. return $this;
  291. }
  292. /**
  293. * Get salt.
  294. *
  295. * @return string
  296. */
  297. public function getSalt()
  298. {
  299. return $this->salt;
  300. }
  301. /**
  302. * Set sortNo.
  303. *
  304. * @param int $sortNo
  305. *
  306. * @return Member
  307. */
  308. public function setSortNo($sortNo)
  309. {
  310. $this->sort_no = $sortNo;
  311. return $this;
  312. }
  313. /**
  314. * Get sortNo.
  315. *
  316. * @return int
  317. */
  318. public function getSortNo()
  319. {
  320. return $this->sort_no;
  321. }
  322. /**
  323. * Set twoFactorAuthKey.
  324. *
  325. * @param string $two_factor_auth_key
  326. *
  327. * @return Member
  328. */
  329. public function setTwoFactorAuthKey($two_factor_auth_key)
  330. {
  331. $this->two_factor_auth_key = $two_factor_auth_key;
  332. return $this;
  333. }
  334. /**
  335. * Get twoFactorAuthKey.
  336. *
  337. * @return string
  338. */
  339. public function getTwoFactorAuthKey()
  340. {
  341. return $this->two_factor_auth_key;
  342. }
  343. /**
  344. * Set twoFactorAuthEnabled.
  345. *
  346. * @param boolean $two_factor_auth_enabled
  347. *
  348. * @return Member
  349. */
  350. public function setTwoFactorAuthEnabled($two_factor_auth_enabled)
  351. {
  352. $this->two_factor_auth_enabled = $two_factor_auth_enabled;
  353. return $this;
  354. }
  355. /**
  356. * Get twoFactorAuthEnabled.
  357. *
  358. * @return boolean
  359. */
  360. public function isTwoFactorAuthEnabled()
  361. {
  362. return $this->two_factor_auth_enabled;
  363. }
  364. /**
  365. * Set createDate.
  366. *
  367. * @param \DateTime $createDate
  368. *
  369. * @return Member
  370. */
  371. public function setCreateDate($createDate)
  372. {
  373. $this->create_date = $createDate;
  374. return $this;
  375. }
  376. /**
  377. * Get createDate.
  378. *
  379. * @return \DateTime
  380. */
  381. public function getCreateDate()
  382. {
  383. return $this->create_date;
  384. }
  385. /**
  386. * Set updateDate.
  387. *
  388. * @param \DateTime $updateDate
  389. *
  390. * @return Member
  391. */
  392. public function setUpdateDate($updateDate)
  393. {
  394. $this->update_date = $updateDate;
  395. return $this;
  396. }
  397. /**
  398. * Get updateDate.
  399. *
  400. * @return \DateTime
  401. */
  402. public function getUpdateDate()
  403. {
  404. return $this->update_date;
  405. }
  406. /**
  407. * Set loginDate.
  408. *
  409. * @param \DateTime|null $loginDate
  410. *
  411. * @return Member
  412. */
  413. public function setLoginDate($loginDate = null)
  414. {
  415. $this->login_date = $loginDate;
  416. return $this;
  417. }
  418. /**
  419. * Get loginDate.
  420. *
  421. * @return \DateTime|null
  422. */
  423. public function getLoginDate()
  424. {
  425. return $this->login_date;
  426. }
  427. /**
  428. * Set Work
  429. *
  430. * @param \Eccube\Entity\Master\Work
  431. *
  432. * @return Member
  433. */
  434. public function setWork(Master\Work $work = null)
  435. {
  436. $this->Work = $work;
  437. return $this;
  438. }
  439. /**
  440. * Get work.
  441. *
  442. * @return \Eccube\Entity\Master\Work|null
  443. */
  444. public function getWork()
  445. {
  446. return $this->Work;
  447. }
  448. /**
  449. * Set authority.
  450. *
  451. * @param \Eccube\Entity\Master\Authority|null $authority
  452. *
  453. * @return Member
  454. */
  455. public function setAuthority(Master\Authority $authority = null)
  456. {
  457. $this->Authority = $authority;
  458. return $this;
  459. }
  460. /**
  461. * Get authority.
  462. *
  463. * @return \Eccube\Entity\Master\Authority|null
  464. */
  465. public function getAuthority()
  466. {
  467. return $this->Authority;
  468. }
  469. /**
  470. * Set creator.
  471. *
  472. * @param \Eccube\Entity\Member|null $creator
  473. *
  474. * @return Member
  475. */
  476. public function setCreator(Member $creator = null)
  477. {
  478. $this->Creator = $creator;
  479. return $this;
  480. }
  481. /**
  482. * Get creator.
  483. *
  484. * @return \Eccube\Entity\Member|null
  485. */
  486. public function getCreator()
  487. {
  488. return $this->Creator;
  489. }
  490. /**
  491. * String representation of object
  492. *
  493. * @see http://php.net/manual/en/serializable.serialize.php
  494. *
  495. * @return string the string representation of the object or null
  496. *
  497. * @since 5.1.0
  498. */
  499. public function serialize()
  500. {
  501. // see https://symfony.com/doc/2.7/security/entity_provider.html#create-your-user-entity
  502. // MemberRepository::loadUserByUsername() で Work をチェックしているため、ここでは不要
  503. return serialize([
  504. $this->id,
  505. $this->login_id,
  506. $this->password,
  507. $this->salt,
  508. ]);
  509. }
  510. /**
  511. * Constructs the object
  512. *
  513. * @see http://php.net/manual/en/serializable.unserialize.php
  514. *
  515. * @param string $serialized <p>
  516. * The string representation of the object.
  517. * </p>
  518. *
  519. * @return void
  520. *
  521. * @since 5.1.0
  522. */
  523. public function unserialize($serialized)
  524. {
  525. list(
  526. $this->id,
  527. $this->login_id,
  528. $this->password,
  529. $this->salt) = unserialize($serialized);
  530. }
  531. }
  532. }