Advertisement
Guest User

Untitled

a guest
Oct 5th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.82 KB | None | 0 0
  1. class Usuario implements AdvancedUserInterface
  2. {
  3. /**
  4. * @var int
  5. *
  6. * @ORMColumn(name="id", type="integer")
  7. * @ORMId
  8. * @ORMGeneratedValue(strategy="AUTO")
  9. */
  10. private $id;
  11.  
  12. /**
  13. * @var string
  14. *
  15. * @ORMColumn(name="username", type="string", length=255, unique=true)
  16. */
  17. private $username;
  18.  
  19. /**
  20. * @var string
  21. *
  22. * @ORMColumn(name="password", type="string", length=255)
  23. */
  24. private $password;
  25.  
  26. /**
  27. * @var string
  28. *
  29. * @ORMColumn(name="estado", type="boolean")
  30. */
  31. private $estado;
  32.  
  33. /**
  34. * @var string
  35. *
  36. * @ORMColumn(name="salt", type="string", length=255)
  37. */
  38. private $salt;
  39.  
  40. /**
  41. * @ORMManyToMany(targetEntity="Rol", inversedBy="usuarios")
  42. * @ORMJoinTable(name="usuario_rol")
  43. */
  44. private $rolesUsuario;
  45.  
  46. /**
  47. * @ORMOneToOne(targetEntity="Persona")
  48. * @ORMJoinColumn(name="persona_id", referencedColumnName="id")
  49. */
  50. private $persona;
  51.  
  52. public function getAttributes()
  53. {
  54. return get_class_vars(__CLASS__);
  55. }
  56.  
  57. /**
  58. * Get id
  59. *
  60. * @return int
  61. */
  62. public function getId()
  63. {
  64. return $this->id;
  65. }
  66.  
  67. /**
  68. * Set username
  69. *
  70. * @param string $username
  71. *
  72. * @return Usuario
  73. */
  74. public function setUsername($username)
  75. {
  76. $this->username = $username;
  77.  
  78. return $this;
  79. }
  80.  
  81. /**
  82. * Get username
  83. *
  84. * @return string
  85. */
  86. public function getUsername()
  87. {
  88. return $this->username;
  89. }
  90.  
  91. /**
  92. * Set password
  93. *
  94. * @param string $password
  95. *
  96. * @return Usuario
  97. */
  98. public function setPassword($password)
  99. {
  100. $this->password = $password;
  101.  
  102. return $this;
  103. }
  104.  
  105. /**
  106. * Get password
  107. *
  108. * @return string
  109. */
  110. public function getPassword()
  111. {
  112. return $this->password;
  113. }
  114.  
  115. /**
  116. * Set estado
  117. *
  118. * @param string $estado
  119. *
  120. * @return Usuario
  121. */
  122. public function setEstado($estado)
  123. {
  124. $this->estado = $estado;
  125.  
  126. return $this;
  127. }
  128.  
  129. /**
  130. * Get estado
  131. *
  132. * @return string
  133. */
  134. public function getEstado()
  135. {
  136. return $this->estado;
  137. }
  138.  
  139. /**
  140. * Checks whether the user's account has expired.
  141. *
  142. * Internally, if this method returns false, the authentication system
  143. * will throw an AccountExpiredException and prevent login.
  144. *
  145. * @return bool true if the user's account is non expired, false otherwise
  146. *
  147. * @see AccountExpiredException
  148. */
  149. public function isAccountNonExpired()
  150. {
  151. return true;
  152. }
  153.  
  154. /**
  155. * Checks whether the user is locked.
  156. *
  157. * Internally, if this method returns false, the authentication system
  158. * will throw a LockedException and prevent login.
  159. *
  160. * @return bool true if the user is not locked, false otherwise
  161. *
  162. * @see LockedException
  163. */
  164. public function isAccountNonLocked()
  165. {
  166. return true;
  167. }
  168.  
  169. /**
  170. * Checks whether the user's credentials (password) has expired.
  171. *
  172. * Internally, if this method returns false, the authentication system
  173. * will throw a CredentialsExpiredException and prevent login.
  174. *
  175. * @return bool true if the user's credentials are non expired, false otherwise
  176. *
  177. * @see CredentialsExpiredException
  178. */
  179. public function isCredentialsNonExpired()
  180. {
  181. return true;
  182. }
  183.  
  184. /**
  185. * Checks whether the user is enabled.
  186. *
  187. * Internally, if this method returns false, the authentication system
  188. * will throw a DisabledException and prevent login.
  189. *
  190. * @return bool true if the user is enabled, false otherwise
  191. *
  192. * @see DisabledException
  193. */
  194. public function isEnabled()
  195. {
  196. if($this->estado == true){
  197. return true;
  198. }else{
  199. return false;
  200. }
  201. }
  202.  
  203. /**
  204. * Returns the roles granted to the user.
  205. *
  206. * <code>
  207. * public function getRoles()
  208. * {
  209. * return array('ROLE_USER');
  210. * }
  211. * </code>
  212. *
  213. * Alternatively, the roles might be stored on a ``roles`` property,
  214. * and populated in any number of different ways when the user object
  215. * is created.
  216. *
  217. * @return (Role|string)[] The user roles
  218. */
  219.  
  220. public function getRolesUsuario()
  221. {
  222. return $this->rolesUsuario;
  223. }
  224.  
  225.  
  226. public function getRoles()
  227. {
  228. $r = array();
  229. foreach ($this->rolesUsuario as $roles){
  230. $r[] = $roles->getNombre();
  231. }
  232. return $r;
  233. }
  234.  
  235. /**
  236. * Returns the salt that was originally used to encode the password.
  237. *
  238. * This can return null if the password was not encoded using a salt.
  239. *
  240. * @return string|null The salt
  241. */
  242. public function getSalt()
  243. {
  244. return $this->salt;
  245. }
  246.  
  247. /**
  248. * Removes sensitive data from the user.
  249. *
  250. * This is important if, at any given point, sensitive information like
  251. * the plain-text password is stored on this object.
  252. */
  253. public function eraseCredentials()
  254. {
  255. return false;
  256. }
  257. /**
  258. * Constructor
  259. */
  260. public function __construct()
  261. {
  262. $this->rolesUsuario = new DoctrineCommonCollectionsArrayCollection();
  263. }
  264.  
  265. /**
  266. * Set salt
  267. *
  268. * @param string $salt
  269. *
  270. * @return Usuario
  271. */
  272. public function setSalt($salt)
  273. {
  274. $this->salt = $salt;
  275.  
  276. return $this;
  277. }
  278.  
  279. /**
  280. * Add role
  281. *
  282. * @param CECMEDSeguridadBundleEntityRol $role
  283. *
  284. * @return Usuario
  285. */
  286. public function addRole(CECMEDSeguridadBundleEntityRol $role)
  287. {
  288. $this->rolesUsuario[] = $role;
  289.  
  290. return $this;
  291. }
  292.  
  293. /**
  294. * Remove role
  295. *
  296. * @param CECMEDSeguridadBundleEntityRol $role
  297. */
  298. public function removeRole(CECMEDSeguridadBundleEntityRol $role)
  299. {
  300. $this->rolesUsuario->removeElement($role);
  301. }
  302.  
  303. /**
  304. * Set persona
  305. *
  306. * @param CECMEDSeguridadBundleEntitypersona $persona
  307. *
  308. * @return Usuario
  309. */
  310. public function setPersona(CECMEDSeguridadBundleEntitypersona $persona = null)
  311. {
  312. $this->persona = $persona;
  313.  
  314. return $this;
  315. }
  316.  
  317. /**
  318. * Get persona
  319. *
  320. * @return CECMEDSeguridadBundleEntitypersona
  321. */
  322. public function getPersona()
  323. {
  324. return $this->persona;
  325. }
  326.  
  327. /**
  328. * @return string
  329. */
  330. public function __toString()
  331. {
  332. return $this->getUsername();
  333. }
  334.  
  335. /**
  336. * Add rolesUsuario
  337. *
  338. * @param CECMEDSeguridadBundleEntityRol $rolesUsuario
  339. *
  340. * @return Usuario
  341. */
  342. public function addRolesUsuario(CECMEDSeguridadBundleEntityRol $rolesUsuario)
  343. {
  344. $this->rolesUsuario[] = $rolesUsuario;
  345.  
  346. return $this;
  347. }
  348.  
  349. /**
  350. * Remove rolesUsuario
  351. *
  352. * @param CECMEDSeguridadBundleEntityRol $rolesUsuario
  353. */
  354. public function removeRolesUsuario(CECMEDSeguridadBundleEntityRol $rolesUsuario)
  355. {
  356. $this->rolesUsuario->removeElement($rolesUsuario);
  357. }
  358. }
  359.  
  360. class Rol
  361. {
  362. /**
  363. * @var int
  364. *
  365. * @ORMColumn(name="id", type="integer")
  366. * @ORMId
  367. * @ORMGeneratedValue(strategy="AUTO")
  368. */
  369. private $id;
  370.  
  371. /**
  372. * @var string
  373. *
  374. * @ORMColumn(name="nombre", type="string", length=255, unique=true)
  375. */
  376. private $nombre;
  377.  
  378. /**
  379. * @var string
  380. *
  381. * @ORMColumn(name="descripcion", type="string", length=255)
  382. */
  383. private $descripcion;
  384.  
  385. /**
  386. * @ORMManyToMany(targetEntity="Funcionalidad", inversedBy="rolesUsuario")
  387. * @ORMJoinTable(name="rol_funcionalidad")
  388. */
  389. private $funcionalidades;
  390.  
  391. /**
  392. * @ORMManyToMany(targetEntity="Usuario", mappedBy="rolesUsuario")
  393. */
  394. private $usuarios;
  395.  
  396.  
  397. public function getAttributes()
  398. {
  399. return get_class_vars(__CLASS__);
  400. }
  401.  
  402. /**
  403. * Get id
  404. *
  405. * @return int
  406. */
  407. public function getId()
  408. {
  409. return $this->id;
  410. }
  411.  
  412. /**
  413. * Set nombre
  414. *
  415. * @param string $nombre
  416. *
  417. * @return Rol
  418. */
  419. public function setNombre($nombre)
  420. {
  421. $this->nombre = $nombre;
  422.  
  423. return $this;
  424. }
  425.  
  426. /**
  427. * Get nombre
  428. *
  429. * @return string
  430. */
  431. public function getNombre()
  432. {
  433. return $this->nombre;
  434. }
  435.  
  436. /**
  437. * Set descripcion
  438. *
  439. * @param string $descripcion
  440. *
  441. * @return Rol
  442. */
  443. public function setDescripcion($descripcion)
  444. {
  445. $this->descripcion = $descripcion;
  446.  
  447. return $this;
  448. }
  449.  
  450. /**
  451. * Get descripcion
  452. *
  453. * @return string
  454. */
  455. public function getDescripcion()
  456. {
  457. return $this->descripcion;
  458. }
  459.  
  460. /**
  461. * @return string
  462. */
  463. public function __toString()
  464. {
  465. return $this->getNombre();
  466. }
  467. /**
  468. * Constructor
  469. */
  470. public function __construct()
  471. {
  472. $this->funcionalidades = new DoctrineCommonCollectionsArrayCollection();
  473. $this->usuarios = new DoctrineCommonCollectionsArrayCollection();
  474. }
  475.  
  476. /**
  477. * Add funcionalidade
  478. *
  479. * @param CECMEDSeguridadBundleEntityRol $funcionalidade
  480. *
  481. * @return Rol
  482. */
  483. public function addFuncionalidade(CECMEDSeguridadBundleEntityRol $funcionalidade)
  484. {
  485. $this->funcionalidades[] = $funcionalidade;
  486.  
  487. return $this;
  488. }
  489.  
  490. /**
  491. * Remove funcionalidade
  492. *
  493. * @param CECMEDSeguridadBundleEntityRol $funcionalidade
  494. */
  495. public function removeFuncionalidade(CECMEDSeguridadBundleEntityRol $funcionalidade)
  496. {
  497. $this->funcionalidades->removeElement($funcionalidade);
  498. }
  499.  
  500. /**
  501. * Get funcionalidades
  502. *
  503. * @return DoctrineCommonCollectionsCollection
  504. */
  505. public function getFuncionalidades()
  506. {
  507. return $this->funcionalidades;
  508. }
  509.  
  510. /**
  511. * Add usuario
  512. *
  513. * @param CECMEDSeguridadBundleEntityUsuario $usuario
  514. *
  515. * @return Rol
  516. */
  517. public function addUsuario(CECMEDSeguridadBundleEntityUsuario $usuario)
  518. {
  519. $usuario->addRolesUsuario($this);
  520. $this->usuarios[] = '$usuario';
  521.  
  522. return $this;
  523. }
  524.  
  525. /**
  526. * Remove usuario
  527. *
  528. * @param CECMEDSeguridadBundleEntityUsuario $usuario
  529. */
  530. public function removeUsuario(CECMEDSeguridadBundleEntityUsuario $usuario)
  531. {
  532. $this->usuarios->removeElement($usuario);
  533. }
  534.  
  535. /**
  536. * Get usuarios
  537. *
  538. * @return DoctrineCommonCollectionsCollection
  539. */
  540. public function getUsuarios()
  541. {
  542. return $this->usuarios;
  543. }
  544. }
  545.  
  546. public function addUsuario(CECMEDSeguridadBundleEntityUsuario $usuario)
  547. {
  548. $usuario->addRolesUsuario($this);
  549. $this->usuarios[] = '$usuario';
  550.  
  551. return $this;
  552. }
  553.  
  554. public function addUsuario(CECMEDSeguridadBundleEntityUsuario $usuario)
  555. {
  556. $usuario->addRolesUsuario($this);
  557. $this->usuarios[] = $usuario;
  558.  
  559. return $this;
  560. }
  561.  
  562. <?php
  563. /** @Entity */
  564. class User
  565. {
  566. // ...
  567.  
  568. /**
  569. * @ORMManyToMany(targetEntity="Group", inversedBy="users")
  570. * @ORMJoinTable(name="users_groups",
  571. * joinColumns={@ORMJoinColumn(name="user_id", referencedColumnName="id")},
  572. * inverseJoinColumns={@ORMJoinColumn(name="group_id", referencedColumnName="id")}
  573. * )
  574. */
  575. private $groups;
  576.  
  577. public function __construct() {
  578. $this->groups = new DoctrineCommonCollectionsArrayCollection();
  579. }
  580.  
  581. // ...
  582. }
  583.  
  584. /** @Entity */
  585. class Group
  586. {
  587. // ...
  588. /**
  589. * @ORMManyToMany(targetEntity="User", mappedBy="groups")
  590. */
  591. private $users;
  592.  
  593. public function __construct() {
  594. $this->users = new DoctrineCommonCollectionsArrayCollection();
  595. }
  596.  
  597. // ...
  598. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement