Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Acme\MyBundle\Entity;
  4.  
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\AdvancedUserInterface;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9.  
  10. /**
  11. * @ORM\Entity
  12. * @ORM\Table(name="Users")
  13. */
  14. class User implements UserInterface, AdvancedUserInterface, \Serializable
  15. {
  16.  
  17. // Definizione campi
  18.  
  19. /**
  20. * @ORM\Id
  21. * @ORM\Column(type="integer")
  22. * @ORM\GeneratedValue(strategy="AUTO")
  23. */
  24. protected $id;
  25.  
  26. /**
  27. * @ORM\Column(type="string", unique=true)
  28. */
  29. protected $username;
  30.  
  31. /**
  32. * @ORM\Column(type="string")
  33. */
  34. protected $password;
  35.  
  36. /**
  37. * @ORM\Column(type="string")
  38. */
  39. protected $salt;
  40.  
  41. /**
  42. * @var \Doctrine\Common\Collections\Collection
  43. *
  44. * @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
  45. * @ORM\JoinTable(name="User_Role",
  46. * joinColumns={
  47. * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  48. * },
  49. * inverseJoinColumns={
  50. * @ORM\JoinColumn(name="role_id", referencedColumnName="id")
  51. * }
  52. * )
  53. */
  54. private $roles;
  55.  
  56. /**
  57. * @ORM\Column(type="integer", nullable=true)
  58. */
  59. protected $idAnagrafica;
  60.  
  61. /**
  62. * @ORM\Column(type="integer", nullable=true)
  63. */
  64. protected $idTipoVisita;
  65.  
  66. /**
  67. * @ORM\Column(type="boolean", nullable=true)
  68. */
  69. protected $attivo;
  70.  
  71.  
  72. // Definizioni delle funzioni Get
  73.  
  74. /**
  75. * @return integer
  76. */
  77. public function getId()
  78. {
  79. return $this->id;
  80. }
  81.  
  82. /**
  83. * @return string
  84. */
  85. public function getUsername()
  86. {
  87. return $this->username;
  88. }
  89.  
  90. /**
  91. * @return string
  92. */
  93. public function getPassword()
  94. {
  95. return $this->password;
  96. }
  97.  
  98. /**
  99. * @return string
  100. */
  101. public function getSalt()
  102. {
  103. if (null === $this->salt)
  104. {
  105. $this->salt = sha512(sprintf('%s_%d_%f',uniqid(),rand(0, 99999),microtime(true)));
  106. }
  107.  
  108. return $this->salt;
  109. }
  110.  
  111. /**
  112. * @return array
  113. */
  114. public function getRoles()
  115. {
  116. return $this->roles->toArray();
  117. }
  118.  
  119. /**
  120. * @return integer
  121. */
  122. public function getIdRole()
  123. {
  124. return $this->idRole;
  125. }
  126.  
  127. /**
  128. * @return integer
  129. */
  130. public function getIdAnagrafica()
  131. {
  132. return $this->idAnagrafica;
  133. }
  134.  
  135. /**
  136. * @return integer
  137. */
  138. public function getIdTipoVisita()
  139. {
  140. return $this->idTipoVisita;
  141. }
  142.  
  143. /**
  144. * @return boolean
  145. */
  146. public function getAttivo()
  147. {
  148. return $this->attivo;
  149. }
  150.  
  151. public function getUserroles()
  152. {
  153. return $this->roles;
  154. }
  155.  
  156. // Definizione delle funzioni Set
  157.  
  158. /**
  159. * @return void
  160. */
  161. public function eraseCredentials()
  162. {
  163. $this->roles = null;
  164. }
  165.  
  166. /**
  167. * Set username
  168. *
  169. * @param string $username
  170. * @return User
  171. */
  172. public function setUsername($username)
  173. {
  174. $this->username = $username;
  175. return $this;
  176. }
  177.  
  178. /**
  179. * Set password
  180. *
  181. * @param string $password
  182. * @return User
  183. */
  184. public function setPassword($password)
  185. {
  186. $this->password = $password;
  187. return $this;
  188. }
  189.  
  190. /**
  191. * Set salt
  192. *
  193. * @param string $salt
  194. * @return User
  195. */
  196. public function setSalt($salt)
  197. {
  198. $this->salt = $salt;
  199. return $this;
  200. }
  201.  
  202. /**
  203. * Set idAnagrafica
  204. *
  205. * @param integer $idAnagrafica
  206. * @return User
  207. */
  208. public function setIdAnagrafica($idAnagrafica)
  209. {
  210. $this->idAnagrafica = $idAnagrafica;
  211. return $this;
  212. }
  213.  
  214. /**
  215. * Set riferimento idTipoVisita
  216. *
  217. * @param integer $idTipoVisita
  218. * @return User
  219. */
  220. public function setIdTipoVisita($idTipoVisita)
  221. {
  222. $this->idTipoVisita = $idTipoVisita;
  223. return $this;
  224. }
  225.  
  226. /**
  227. * Set attivo
  228. *
  229. * @param boolean $attivo
  230. * @return User
  231. */
  232. public function setAttivo($attivo)
  233. {
  234. $this->attivo = $attivo;
  235. return $this;
  236. }
  237.  
  238. public function setUserroles($roles)
  239. {
  240. $this->roles = $roles;
  241. return $this;
  242. }
  243.  
  244. // Funzioni di servizio
  245.  
  246. public function __construct()
  247. {
  248. $this->roles = new ArrayCollection();
  249. }
  250.  
  251. /**
  252. * @see \Serializable::serialize()
  253. */
  254. public function serialize()
  255. {
  256. return serialize(array($this->id,));
  257. }
  258.  
  259. /**
  260. * @see \Serializable::unserialize()
  261. */
  262. public function unserialize($serialized)
  263. {
  264. list ($this->id,) = unserialize($serialized);
  265. }
  266.  
  267. // Funzioni advance user interface
  268.  
  269. public function isAccountNonExpired()
  270. {
  271. return true;
  272. }
  273.  
  274. public function isAccountNonLocked()
  275. {
  276. return true;
  277. }
  278.  
  279. public function isCredentialsNonExpired()
  280. {
  281. return true;
  282. }
  283.  
  284. public function isEnabled()
  285. {
  286. return $this->attivo;
  287. }
  288.  
  289. //Funzioni autogenerate
  290.  
  291. /**
  292. * Add roles
  293. *
  294. * @param \Acme\MyBundle\Entity\Role $roles
  295. * @return User
  296. */
  297. public function addRole(\Acme\MyBundle\Entity\Role $roles)
  298. {
  299. $this->roles[] = $roles;
  300.  
  301. return $this;
  302. }
  303.  
  304. /**
  305. * Remove roles
  306. *
  307. * @param \Acme\MyBundle\Entity\Role $roles
  308. */
  309. public function removeRole(\Acme\MyBundle\Entity\Role $roles)
  310. {
  311. $this->roles->removeElement($roles);
  312. }
  313.  
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement