Advertisement
Guest User

Untitled

a guest
Apr 24th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.15 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Common\UserBundle\Entity;
  4.  
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Security\Core\User\AdvancedUserInterface;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\HttpFoundation\File\UploadedFile;
  10.  
  11.  
  12.  
  13. /**
  14. * @ORM\Entity(repositoryClass="Common\UserBundle\Repository\UserRepository")
  15. * @ORM\Table(name="users")
  16. * @ORM\HasLifecycleCallbacks
  17. *
  18. * @UniqueEntity(fields={"username"})
  19. * @UniqueEntity(fields={"email"})
  20. */
  21. class User implements AdvancedUserInterface, \Serializable {
  22.  
  23. /**
  24. * @ORM\Column(type="integer")
  25. * @ORM\Id
  26. * @ORM\GeneratedValue(strategy="AUTO")
  27. */
  28. private $id;
  29.  
  30. /**
  31. * @ORM\Column(name="first_name", nullable = true, type="string", length=30)
  32. */
  33. private $firtsName;
  34.  
  35. /**
  36. * @ORM\Column(name="last_name", type="string", length=30, nullable = true)
  37. */
  38. private $lastName;
  39.  
  40. /**
  41. * @ORM\Column(type="string", length=7, nullable = true, columnDefinition="ENUM('male', 'female')")
  42. */
  43. private $gender;
  44.  
  45. /**
  46. * @ORM\Column(type="string", length=30, nullable = true)
  47. */
  48. private $link;
  49.  
  50. /**
  51. * @ORM\Column(type="string", length=10, nullable = true)
  52. */
  53. private $locale;
  54.  
  55. /**
  56. * @ORM\Column(type="string", length = 20, unique = true)
  57. *
  58. * @Assert\NotBlank(
  59. * groups = {"Registration", "ChangeDetails"}
  60. * )
  61. *
  62. * @Assert\Length(
  63. * min=5,
  64. * max=20,
  65. * groups = {"Registration", "ChangeDetails"}
  66. * )
  67. */
  68. private $username;
  69.  
  70. /**
  71. * @ORM\Column(type="string", length = 120, unique = true)
  72. *
  73. * @Assert\NotBlank(
  74. * groups = {"Registration"}
  75. * )
  76. *
  77. * @Assert\Email(
  78. * groups = {"Registration"}
  79. * )
  80. *
  81. * @Assert\Length(
  82. * max = 120,
  83. * groups = {"Registration"}
  84. * )
  85. */
  86. private $email;
  87.  
  88. /**
  89. * @ORM\Column(type="string", length = 64)
  90. */
  91. private $password;
  92.  
  93. /**
  94. * @Assert\NotBlank(
  95. * groups = {"Registration", "ChangePassword"}
  96. * )
  97. *
  98. * @Assert\Length(
  99. * min = 8,
  100. * groups = {"Registration", "ChangePassword"}
  101. * )
  102. */
  103. private $plainPassword;
  104.  
  105. /**
  106. * @ORM\Column(name="account_non_expired", type="boolean")
  107. */
  108. private $accountNonExpired = true;
  109.  
  110. /**
  111. * @ORM\Column(name="account_non_locked", type="boolean")
  112. */
  113. private $accountNonLocked = true;
  114.  
  115. /**
  116. * @ORM\Column(name="credentials_non_expired", type="boolean")
  117. */
  118. private $credentialsNonExpired = true;
  119.  
  120. /**
  121. * @ORM\Column(type="boolean")
  122. */
  123. private $enabled = false;
  124.  
  125. /**
  126. * @ORM\Column(type="array")
  127. */
  128. private $roles;
  129.  
  130. /**
  131. * @ORM\Column(name="action_token", type="string", length = 20, nullable = true)
  132. */
  133. private $actionToken;
  134.  
  135. /**
  136. * @ORM\Column(name="register_date", type="datetime")
  137. */
  138. private $registerDate;
  139.  
  140. /**
  141. * @ORM\Column(type="string", length = 100, nullable = true)
  142. */
  143. private $avatar;
  144.  
  145. /**
  146. * @var UploadedFile
  147. *
  148. * @Assert\Image(
  149. * minWidth = 50,
  150. * maxWidth = 150,
  151. * minHeight = 50,
  152. * maxHeight = 150,
  153. * maxSize = "1M",
  154. * groups = {"ChangeDetails"}
  155. * )
  156. */
  157. private $avatarFile;
  158.  
  159. private $avatarTemp;
  160.  
  161. /**
  162. * @ORM\Column(type="datetime", nullable = true)
  163. */
  164. private $updateDate;
  165.  
  166.  
  167.  
  168.  
  169.  
  170. public function eraseCredentials() {
  171. $this->plainPassword = null;
  172. }
  173.  
  174. public function getPassword() {
  175. return $this->password;
  176. }
  177.  
  178. public function getRoles() {
  179. if(empty($this->roles)){
  180. return array('ROLE_USER');
  181. }
  182.  
  183. return $this->roles;
  184. }
  185.  
  186. public function getSalt() {
  187. return null;
  188. }
  189.  
  190. public function getUsername() {
  191. return $this->username;
  192. }
  193.  
  194. public function isAccountNonExpired() {
  195. return $this->accountNonExpired;
  196. }
  197.  
  198. public function isAccountNonLocked() {
  199. return $this->accountNonLocked;
  200. }
  201.  
  202. public function isCredentialsNonExpired() {
  203. return $this->credentialsNonExpired;
  204. }
  205.  
  206. public function isEnabled() {
  207. return $this->enabled;
  208. }
  209.  
  210.  
  211. function __construct() {
  212. $this->registerDate = new \DateTime();
  213. }
  214.  
  215.  
  216. /**
  217. * Get id
  218. *
  219. * @return integer
  220. */
  221. public function getId()
  222. {
  223. return $this->id;
  224. }
  225.  
  226. /**
  227. * Set firtsName
  228. *
  229. * @param string $firtsName
  230. * @return User
  231. */
  232. public function setFirtsName($firtsName)
  233. {
  234. $this->firtsName = $firtsName;
  235.  
  236. return $this;
  237. }
  238.  
  239. /**
  240. * Get firtsName
  241. *
  242. * @return string
  243. */
  244. public function getFirtsName()
  245. {
  246. return $this->firtsName;
  247. }
  248.  
  249. /**
  250. * Set lastName
  251. *
  252. * @param string $lastName
  253. * @return User
  254. */
  255. public function setLastName($lastName)
  256. {
  257. $this->lastName = $lastName;
  258.  
  259. return $this;
  260. }
  261.  
  262. /**
  263. * Get lastName
  264. *
  265. * @return string
  266. */
  267. public function getLastName()
  268. {
  269. return $this->lastName;
  270. }
  271.  
  272. /**
  273. * Set gender
  274. *
  275. * @param string $gender
  276. * @return User
  277. */
  278. public function setGender($gender)
  279. {
  280. $this->gender = $gender;
  281.  
  282. return $this;
  283. }
  284.  
  285. /**
  286. * Get gender
  287. *
  288. * @return string
  289. */
  290. public function getGender()
  291. {
  292. return $this->gender;
  293. }
  294.  
  295. /**
  296. * Set link
  297. *
  298. * @param string $link
  299. * @return User
  300. */
  301. public function setLink($link)
  302. {
  303. $this->link = $link;
  304.  
  305. return $this;
  306. }
  307.  
  308. /**
  309. * Get link
  310. *
  311. * @return string
  312. */
  313. public function getLink()
  314. {
  315. return $this->link;
  316. }
  317.  
  318. /**
  319. * Set locale
  320. *
  321. * @param string $locale
  322. * @return User
  323. */
  324. public function setLocale($locale)
  325. {
  326. $this->locale = $locale;
  327.  
  328. return $this;
  329. }
  330.  
  331. /**
  332. * Get locale
  333. *
  334. * @return string
  335. */
  336. public function getLocale()
  337. {
  338. return $this->locale;
  339. }
  340.  
  341. /**
  342. * Set username
  343. *
  344. * @param string $username
  345. * @return User
  346. */
  347. public function setUsername($username)
  348. {
  349. $this->username = $username;
  350.  
  351. return $this;
  352. }
  353.  
  354. /**
  355. * Set email
  356. *
  357. * @param string $email
  358. * @return User
  359. */
  360. public function setEmail($email)
  361. {
  362. $this->email = $email;
  363.  
  364. return $this;
  365. }
  366.  
  367. /**
  368. * Get email
  369. *
  370. * @return string
  371. */
  372. public function getEmail()
  373. {
  374. return $this->email;
  375. }
  376.  
  377. /**
  378. * Set password
  379. *
  380. * @param string $password
  381. * @return User
  382. */
  383. public function setPassword($password)
  384. {
  385. $this->password = $password;
  386.  
  387. return $this;
  388. }
  389.  
  390. /**
  391. * Set accountNonExpired
  392. *
  393. * @param boolean $accountNonExpired
  394. * @return User
  395. */
  396. public function setAccountNonExpired($accountNonExpired)
  397. {
  398. $this->accountNonExpired = $accountNonExpired;
  399.  
  400. return $this;
  401. }
  402.  
  403. /**
  404. * Get accountNonExpired
  405. *
  406. * @return boolean
  407. */
  408. public function getAccountNonExpired()
  409. {
  410. return $this->accountNonExpired;
  411. }
  412.  
  413. /**
  414. * Set accountNonLocked
  415. *
  416. * @param boolean $accountNonLocked
  417. * @return User
  418. */
  419. public function setAccountNonLocked($accountNonLocked)
  420. {
  421. $this->accountNonLocked = $accountNonLocked;
  422.  
  423. return $this;
  424. }
  425.  
  426. /**
  427. * Get accountNonLocked
  428. *
  429. * @return boolean
  430. */
  431. public function getAccountNonLocked()
  432. {
  433. return $this->accountNonLocked;
  434. }
  435.  
  436. /**
  437. * Set credentialsNonExpired
  438. *
  439. * @param boolean $credentialsNonExpired
  440. * @return User
  441. */
  442. public function setCredentialsNonExpired($credentialsNonExpired)
  443. {
  444. $this->credentialsNonExpired = $credentialsNonExpired;
  445.  
  446. return $this;
  447. }
  448.  
  449. /**
  450. * Get credentialsNonExpired
  451. *
  452. * @return boolean
  453. */
  454. public function getCredentialsNonExpired()
  455. {
  456. return $this->credentialsNonExpired;
  457. }
  458.  
  459. /**
  460. * Set enabled
  461. *
  462. * @param boolean $enabled
  463. * @return User
  464. */
  465. public function setEnabled($enabled)
  466. {
  467. $this->enabled = $enabled;
  468.  
  469. return $this;
  470. }
  471.  
  472. /**
  473. * Get enabled
  474. *
  475. * @return boolean
  476. */
  477. public function getEnabled()
  478. {
  479. return $this->enabled;
  480. }
  481.  
  482. /**
  483. * Set roles
  484. *
  485. * @param array $roles
  486. * @return User
  487. */
  488. public function setRoles($roles)
  489. {
  490. $this->roles = $roles;
  491.  
  492. return $this;
  493. }
  494.  
  495. /**
  496. * Set actionToken
  497. *
  498. * @param string $actionToken
  499. * @return User
  500. */
  501. public function setActionToken($actionToken)
  502. {
  503. $this->actionToken = $actionToken;
  504.  
  505. return $this;
  506. }
  507.  
  508. /**
  509. * Get actionToken
  510. *
  511. * @return string
  512. */
  513. public function getActionToken()
  514. {
  515. return $this->actionToken;
  516. }
  517.  
  518. /**
  519. * Set registerDate
  520. *
  521. * @param \DateTime $registerDate
  522. * @return User
  523. */
  524. public function setRegisterDate($registerDate)
  525. {
  526. $this->registerDate = $registerDate;
  527.  
  528. return $this;
  529. }
  530.  
  531. /**
  532. * Get registerDate
  533. *
  534. * @return \DateTime
  535. */
  536. public function getRegisterDate()
  537. {
  538. return $this->registerDate;
  539. }
  540.  
  541. /**
  542. * Set avatar
  543. *
  544. * @param string $avatar
  545. * @return User
  546. */
  547. public function setAvatar($avatar)
  548. {
  549. $this->avatar = $avatar;
  550.  
  551. return $this;
  552. }
  553.  
  554. /**
  555. * Get avatar
  556. *
  557. * @return string
  558. */
  559. public function getAvatar()
  560. {
  561. return $this->avatar;
  562. }
  563.  
  564. /**
  565. * Set updateDate
  566. *
  567. * @param \DateTime $updateDate
  568. * @return User
  569. */
  570. public function setUpdateDate($updateDate)
  571. {
  572. $this->updateDate = $updateDate;
  573.  
  574. return $this;
  575. }
  576.  
  577. /**
  578. * Get updateDate
  579. *
  580. * @return \DateTime
  581. */
  582. public function getUpdateDate()
  583. {
  584. return $this->updateDate;
  585. }
  586.  
  587.  
  588.  
  589.  
  590. public function serialize() {
  591. return serialize(array(
  592. $this->id,
  593. $this->username,
  594. $this->password
  595. ));
  596. }
  597.  
  598. public function unserialize($serialized) {
  599. list(
  600. $this->id,
  601. $this->username,
  602. $this->password
  603. ) = unserialize($serialized);
  604. }
  605.  
  606.  
  607.  
  608.  
  609. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement