User.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\UserBundle\Model;
  11. use FOS\UserBundle\Entity\User as AbstractedUser;
  12. /**
  13. * Represents a User model.
  14. */
  15. abstract class User extends AbstractedUser implements UserInterface
  16. {
  17. /**
  18. * @var \DateTime
  19. */
  20. protected $createdAt;
  21. /**
  22. * @var \DateTime
  23. */
  24. protected $updatedAt;
  25. /**
  26. * @var string
  27. */
  28. protected $twoStepVerificationCode;
  29. /**
  30. * @var \DateTime
  31. */
  32. protected $dateOfBirth;
  33. /**
  34. * @var string
  35. */
  36. protected $firstname;
  37. /**
  38. * @var string
  39. */
  40. protected $lastname;
  41. /**
  42. * @var string
  43. */
  44. protected $website;
  45. /**
  46. * @var string
  47. */
  48. protected $biography;
  49. /**
  50. * @var string
  51. */
  52. protected $gender = UserInterface::GENDER_UNKNOWN; // set the default to unknown
  53. /**
  54. * @var string
  55. */
  56. protected $locale;
  57. /**
  58. * @var string
  59. */
  60. protected $timezone;
  61. /**
  62. * @var string
  63. */
  64. protected $phone;
  65. /**
  66. * @var string
  67. */
  68. protected $facebookUid;
  69. /**
  70. * @var string
  71. */
  72. protected $facebookName;
  73. /**
  74. * @var string
  75. */
  76. protected $facebookData;
  77. /**
  78. * @var string
  79. */
  80. protected $twitterUid;
  81. /**
  82. * @var string
  83. */
  84. protected $twitterName;
  85. /**
  86. * @var string
  87. */
  88. protected $twitterData;
  89. /**
  90. * @var string
  91. */
  92. protected $gplusUid;
  93. /**
  94. * @var string
  95. */
  96. protected $gplusName;
  97. /**
  98. * @var string
  99. */
  100. protected $gplusData;
  101. /**
  102. * @var string
  103. */
  104. protected $token;
  105. /**
  106. * Returns a string representation.
  107. *
  108. * @return string
  109. */
  110. public function __toString()
  111. {
  112. return $this->getUsername() ?: '-';
  113. }
  114. /**
  115. * Sets the creation date.
  116. *
  117. * @param \DateTime|null $createdAt
  118. *
  119. * @return User
  120. */
  121. public function setCreatedAt(\DateTime $createdAt = null)
  122. {
  123. $this->createdAt = $createdAt;
  124. return $this;
  125. }
  126. /**
  127. * Returns the creation date.
  128. *
  129. * @return \DateTime|null
  130. */
  131. public function getCreatedAt()
  132. {
  133. return $this->createdAt;
  134. }
  135. /**
  136. * Sets the last update date.
  137. *
  138. * @param \DateTime|null $updatedAt
  139. *
  140. * @return User
  141. */
  142. public function setUpdatedAt(\DateTime $updatedAt = null)
  143. {
  144. $this->updatedAt = $updatedAt;
  145. return $this;
  146. }
  147. /**
  148. * Returns the last update date.
  149. *
  150. * @return \DateTime|null
  151. */
  152. public function getUpdatedAt()
  153. {
  154. return $this->updatedAt;
  155. }
  156. /**
  157. * Returns the expiration date.
  158. *
  159. * @return \DateTime|null
  160. */
  161. public function getExpiresAt()
  162. {
  163. return $this->expiresAt;
  164. }
  165. /**
  166. * Set expiration date.
  167. *
  168. * @param \DateTime|null $date
  169. *
  170. * @return User
  171. */
  172. public function setExpiresAt(\DateTime $date = null)
  173. {
  174. $this->expiresAt = $date;
  175. return $this;
  176. }
  177. /**
  178. * Returns the credentials expiration date.
  179. *
  180. * @return \DateTime
  181. */
  182. public function getCredentialsExpireAt()
  183. {
  184. return $this->credentialsExpireAt;
  185. }
  186. /**
  187. * Sets the credentials expiration date.
  188. *
  189. * @param \DateTime|null $date
  190. *
  191. * @return User
  192. */
  193. public function setCredentialsExpireAt(\DateTime $date = null)
  194. {
  195. $this->credentialsExpireAt = $date;
  196. return $this;
  197. }
  198. /**
  199. * Sets the user groups.
  200. *
  201. * @param array $groups
  202. *
  203. * @return User
  204. */
  205. public function setGroups($groups)
  206. {
  207. foreach ($groups as $group) {
  208. $this->addGroup($group);
  209. }
  210. return $this;
  211. }
  212. /**
  213. * Sets the two-step verification code.
  214. *
  215. * @param string $twoStepVerificationCode
  216. *
  217. * @return User
  218. */
  219. public function setTwoStepVerificationCode($twoStepVerificationCode)
  220. {
  221. $this->twoStepVerificationCode = $twoStepVerificationCode;
  222. return $this;
  223. }
  224. /**
  225. * Returns the two-step verification code.
  226. *
  227. * @return string
  228. */
  229. public function getTwoStepVerificationCode()
  230. {
  231. return $this->twoStepVerificationCode;
  232. }
  233. /**
  234. * @param string $biography
  235. *
  236. * @return User
  237. */
  238. public function setBiography($biography)
  239. {
  240. $this->biography = $biography;
  241. return $this;
  242. }
  243. /**
  244. * @return string
  245. */
  246. public function getBiography()
  247. {
  248. return $this->biography;
  249. }
  250. /**
  251. * @param \DateTime $dateOfBirth
  252. *
  253. * @return User
  254. */
  255. public function setDateOfBirth($dateOfBirth)
  256. {
  257. $this->dateOfBirth = $dateOfBirth;
  258. return $this;
  259. }
  260. /**
  261. * @return \DateTime
  262. */
  263. public function getDateOfBirth()
  264. {
  265. return $this->dateOfBirth;
  266. }
  267. /**
  268. * @param string $facebookData
  269. *
  270. * @return User
  271. */
  272. public function setFacebookData($facebookData)
  273. {
  274. $this->facebookData = $facebookData;
  275. return $this;
  276. }
  277. /**
  278. * @return string
  279. */
  280. public function getFacebookData()
  281. {
  282. return $this->facebookData;
  283. }
  284. /**
  285. * @param string $facebookName
  286. *
  287. * @return User
  288. */
  289. public function setFacebookName($facebookName)
  290. {
  291. $this->facebookName = $facebookName;
  292. return $this;
  293. }
  294. /**
  295. * @return string
  296. */
  297. public function getFacebookName()
  298. {
  299. return $this->facebookName;
  300. }
  301. /**
  302. * @param string $facebookUid
  303. *
  304. * @return User
  305. */
  306. public function setFacebookUid($facebookUid)
  307. {
  308. $this->facebookUid = $facebookUid;
  309. return $this;
  310. }
  311. /**
  312. * @return string
  313. */
  314. public function getFacebookUid()
  315. {
  316. return $this->facebookUid;
  317. }
  318. /**
  319. * @param string $firstname
  320. *
  321. * @return User
  322. */
  323. public function setFirstname($firstname)
  324. {
  325. $this->firstname = $firstname;
  326. return $this;
  327. }
  328. /**
  329. * @return string
  330. */
  331. public function getFirstname()
  332. {
  333. return $this->firstname;
  334. }
  335. /**
  336. * @param string $gender
  337. *
  338. * @return User
  339. */
  340. public function setGender($gender)
  341. {
  342. $this->gender = $gender;
  343. return $this;
  344. }
  345. /**
  346. * @return string
  347. */
  348. public function getGender()
  349. {
  350. return $this->gender;
  351. }
  352. /**
  353. * @param string $gplusData
  354. *
  355. * @return User
  356. */
  357. public function setGplusData($gplusData)
  358. {
  359. $this->gplusData = $gplusData;
  360. return $this;
  361. }
  362. /**
  363. * @return string
  364. */
  365. public function getGplusData()
  366. {
  367. return $this->gplusData;
  368. }
  369. /**
  370. * @param string $gplusName
  371. *
  372. * @return User
  373. */
  374. public function setGplusName($gplusName)
  375. {
  376. $this->gplusName = $gplusName;
  377. return $this;
  378. }
  379. /**
  380. * @return string
  381. */
  382. public function getGplusName()
  383. {
  384. return $this->gplusName;
  385. }
  386. /**
  387. * @param string $gplusUid
  388. *
  389. * @return User
  390. */
  391. public function setGplusUid($gplusUid)
  392. {
  393. $this->gplusUid = $gplusUid;
  394. return $this;
  395. }
  396. /**
  397. * @return string
  398. */
  399. public function getGplusUid()
  400. {
  401. return $this->gplusUid;
  402. }
  403. /**
  404. * @param string $lastname
  405. *
  406. * @return User
  407. */
  408. public function setLastname($lastname)
  409. {
  410. $this->lastname = $lastname;
  411. return $this;
  412. }
  413. /**
  414. * @return string
  415. */
  416. public function getLastname()
  417. {
  418. return $this->lastname;
  419. }
  420. /**
  421. * @param string $locale
  422. *
  423. * @return User
  424. */
  425. public function setLocale($locale)
  426. {
  427. $this->locale = $locale;
  428. return $this;
  429. }
  430. /**
  431. * @return string
  432. */
  433. public function getLocale()
  434. {
  435. return $this->locale;
  436. }
  437. /**
  438. * @param string $phone
  439. *
  440. * @return User
  441. */
  442. public function setPhone($phone)
  443. {
  444. $this->phone = $phone;
  445. return $this;
  446. }
  447. /**
  448. * @return string
  449. */
  450. public function getPhone()
  451. {
  452. return $this->phone;
  453. }
  454. /**
  455. * @param string $timezone
  456. *
  457. * @return User
  458. */
  459. public function setTimezone($timezone)
  460. {
  461. $this->timezone = $timezone;
  462. return $this;
  463. }
  464. /**
  465. * @return string
  466. */
  467. public function getTimezone()
  468. {
  469. return $this->timezone;
  470. }
  471. /**
  472. * @param string $twitterData
  473. *
  474. * @return User
  475. */
  476. public function setTwitterData($twitterData)
  477. {
  478. $this->twitterData = $twitterData;
  479. return $this;
  480. }
  481. /**
  482. * @return string
  483. */
  484. public function getTwitterData()
  485. {
  486. return $this->twitterData;
  487. }
  488. /**
  489. * @param string $twitterName
  490. *
  491. * @return User
  492. */
  493. public function setTwitterName($twitterName)
  494. {
  495. $this->twitterName = $twitterName;
  496. return $this;
  497. }
  498. /**
  499. * @return string
  500. */
  501. public function getTwitterName()
  502. {
  503. return $this->twitterName;
  504. }
  505. /**
  506. * @param string $twitterUid
  507. *
  508. * @return User
  509. */
  510. public function setTwitterUid($twitterUid)
  511. {
  512. $this->twitterUid = $twitterUid;
  513. return $this;
  514. }
  515. /**
  516. * @return string
  517. */
  518. public function getTwitterUid()
  519. {
  520. return $this->twitterUid;
  521. }
  522. /**
  523. * @param string $website
  524. *
  525. * @return User
  526. */
  527. public function setWebsite($website)
  528. {
  529. $this->website = $website;
  530. return $this;
  531. }
  532. /**
  533. * @return string
  534. */
  535. public function getWebsite()
  536. {
  537. return $this->website;
  538. }
  539. /**
  540. * @param string $token
  541. *
  542. * @return User
  543. */
  544. public function setToken($token)
  545. {
  546. $this->token = $token;
  547. return $this;
  548. }
  549. /**
  550. * @return string
  551. */
  552. public function getToken()
  553. {
  554. return $this->token;
  555. }
  556. /**
  557. * @return string
  558. */
  559. public function getFullname()
  560. {
  561. return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
  562. }
  563. /**
  564. * @return array
  565. */
  566. public function getRealRoles()
  567. {
  568. return $this->roles;
  569. }
  570. /**
  571. * @param array $roles
  572. *
  573. * @return User
  574. */
  575. public function setRealRoles(array $roles)
  576. {
  577. $this->setRoles($roles);
  578. return $this;
  579. }
  580. }