Guest User

Untitled

a guest
Oct 17th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.61 KB | None | 0 0
  1. <?php
  2.  
  3. namespace MySchool\AdminBundle\Entity;
  4.  
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Symfony\Component\Security\Core\User\UserInterface as BaseUser;
  8.  
  9. /**
  10. * My\AdminBundle\Entity\User
  11. *
  12. * @ORM\Table()
  13. * @ORM\Entity(repositoryClass="MySchool\AdminBundle\Repository\UserRepository")
  14. */
  15. class User implements BaseUser, \Serializable
  16. {
  17. /**
  18. * @var integer $id
  19. *
  20. * @ORM\Column(name="id", type="integer")
  21. * @ORM\Id
  22. * @ORM\GeneratedValue(strategy="AUTO")
  23. */
  24. private $id;
  25.  
  26. /**
  27. * @var string $name
  28. *
  29. * @ORM\Column(name="name", type="string", length=32)
  30. */
  31. private $name;
  32.  
  33. /**
  34. * @var string $firstName
  35. *
  36. * @ORM\Column(name="firstName", type="string", length=32)
  37. */
  38. private $firstName;
  39.  
  40. /**
  41. * @var string $userName
  42. *
  43. * @ORM\Column(name="userName", type="string", length=16, unique="TRUE")
  44. */
  45. private $userName;
  46.  
  47. /**
  48. * @var string $password
  49. *
  50. * @ORM\Column(name="password", type="string", length=64)
  51. */
  52. private $password;
  53.  
  54. /**
  55. * @var string $email
  56. *
  57. * @ORM\Column(name="email", type="string", length=128, nullable=TRUE)
  58. */
  59. private $email;
  60.  
  61.  
  62. /**
  63. * Get id
  64. *
  65. * @return integer $id
  66. */
  67. public function getId()
  68. {
  69. return $this->id;
  70. }
  71.  
  72. /**
  73. * Set name
  74. *
  75. * @param string $name
  76. */
  77. public function setName($name)
  78. {
  79. $this->name = $name;
  80. }
  81.  
  82. /**
  83. * Get name
  84. *
  85. * @return string $name
  86. */
  87. public function getName()
  88. {
  89. return $this->name;
  90. }
  91.  
  92. /**
  93. * Set firstName
  94. *
  95. * @param string $firstName
  96. */
  97. public function setFirstName($firstName)
  98. {
  99. $this->firstName = $firstName;
  100. }
  101.  
  102. /**
  103. * Get firstName
  104. *
  105. * @return string $firstName
  106. */
  107. public function getFirstName()
  108. {
  109. return $this->firstName;
  110. }
  111.  
  112. /**
  113. * Set password
  114. *
  115. * @param string $password
  116. */
  117. public function setPassword($password)
  118. {
  119. $this->password = $password;
  120. }
  121.  
  122. /**
  123. * Get password
  124. *
  125. * @return string $password
  126. */
  127. public function getPassword()
  128. {
  129. return $this->password;
  130. }
  131.  
  132. /**
  133. * Set email
  134. *
  135. * @param string $email
  136. */
  137. public function setEmail($email)
  138. {
  139. $this->email = $email;
  140. }
  141.  
  142. /**
  143. * Get email
  144. *
  145. * @return string $email
  146. */
  147. public function getEmail()
  148. {
  149. return $this->email;
  150. }
  151.  
  152. /**
  153. * @ORM\OneToMany(targetEntity="MySchool\UserBundle\Entity\Message", mappedBy="user")
  154. */
  155. protected $senders;
  156.  
  157. /**
  158. * @ORM\OneToMany(targetEntity="MySchool\UserBundle\Entity\Message", mappedBy="user")
  159. */
  160. protected $receivers;
  161.  
  162. /**
  163. * @ORM\OneToOne(targetEntity="Child", mappedBy="user")
  164. */
  165. protected $child;
  166.  
  167. /**
  168. * @ORM\OneToOne(targetEntity="Adult", mappedBy="user")
  169. */
  170. protected $adult;
  171.  
  172. public function __construct()
  173. {
  174. $this->senders = new ArrayCollection();
  175. $this->receivers = new ArrayCollection();
  176. }
  177.  
  178. public function getRoles()
  179. {
  180. return array('ROLE_ADMIN');
  181. }
  182.  
  183. public function getSalt()
  184. {
  185. return '';
  186. }
  187.  
  188. public function eraseCredentials()
  189. {
  190. return '';
  191. }
  192.  
  193. public function equals (BaseUser $user)
  194. {
  195. if (!$user instanceof User)
  196. return FALSE;
  197. if ($this->password != $user->getPassword())
  198. return FALSE;
  199. if ($this->userName != $user->getUsername())
  200. return FALSE;
  201. return TRUE;
  202. }
  203.  
  204. /**
  205. * Add senders
  206. *
  207. * @param MySchool\UserBundle\Entity\Message $senders
  208. */
  209. public function addSenders(\MySchool\UserBundle\Entity\Message $senders)
  210. {
  211. $this->senders[] = $senders;
  212. }
  213.  
  214. /**
  215. * Get senders
  216. *
  217. * @return Doctrine\Common\Collections\Collection $senders
  218. */
  219. public function getSenders()
  220. {
  221. return $this->senders;
  222. }
  223.  
  224. /**
  225. * Add receivers
  226. *
  227. * @param MySchool\UserBundle\Entity\Message $receivers
  228. */
  229. public function addReceivers(\MySchool\UserBundle\Entity\Message $receivers)
  230. {
  231. $this->receivers[] = $receivers;
  232. }
  233.  
  234. /**
  235. * Get receivers
  236. *
  237. * @return Doctrine\Common\Collections\Collection $receivers
  238. */
  239. public function getReceivers()
  240. {
  241. return $this->receivers;
  242. }
  243.  
  244. /**
  245. * Set child
  246. *
  247. * @param MySchool\AdminBundle\Entity\Child $child
  248. */
  249. public function setChild(\MySchool\AdminBundle\Entity\Child $child)
  250. {
  251. $this->child = $child;
  252. }
  253.  
  254. /**
  255. * Get child
  256. *
  257. * @return MySchool\AdminBundle\Entity\Child $child
  258. */
  259. public function getChild()
  260. {
  261. return $this->child;
  262. }
  263.  
  264. /**
  265. * Set adult
  266. *
  267. * @param MySchool\AdminBundle\Entity\Adult $adult
  268. */
  269. public function setAdult(\MySchool\AdminBundle\Entity\Adult $adult)
  270. {
  271. $this->adult = $adult;
  272. }
  273.  
  274. /**
  275. * Get adult
  276. *
  277. * @return MySchool\AdminBundle\Entity\Adult $adult
  278. */
  279. public function getAdult()
  280. {
  281. return $this->adult;
  282. }
  283.  
  284. /**
  285. * Set userName
  286. *
  287. * @param string $userName
  288. */
  289. public function setUserName()
  290. {
  291. $this->userName = strtolower(substr($this->name, 0, 6) . '_' . substr($this->firstName, 0, 1));
  292. }
  293.  
  294. /**
  295. * Get userName
  296. *
  297. * @return string $userName
  298. */
  299. public function getUserName()
  300. {
  301. return $this->userName;
  302. }
  303.  
  304. /**
  305. * Get name & firstName
  306. *
  307. * @return string $nameFirstName
  308. */
  309. public function getNameFirstName()
  310. {
  311. return $this->name . ' ' . $this->firstName;
  312. }
  313.  
  314. public function serialize() {
  315. $data = array(
  316. 'id' => $this->id,
  317. 'userName' => $this->userName,
  318. 'email' => $this->email,
  319. 'password' => $this->password,
  320. 'name' => $this->name,
  321. 'firstName' => $this->firstName,
  322. );
  323. }
  324.  
  325. public function unserialize($serialized)
  326. {
  327. $data = unserialize($serialized);
  328. $this->id = $data['id'];
  329. $this->userName = $data['userName'];
  330. $this->email = $data['email'];
  331. $this->password = $data['password'];
  332. $this->name = $data['name'];
  333. $this->firstName = $data['firstName'];
  334. }
  335. }
Add Comment
Please, Sign In to add comment