Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Usuario implements AdvancedUserInterface
- {
- /**
- * @var int
- *
- * @ORMColumn(name="id", type="integer")
- * @ORMId
- * @ORMGeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- *
- * @ORMColumn(name="username", type="string", length=255, unique=true)
- */
- private $username;
- /**
- * @var string
- *
- * @ORMColumn(name="password", type="string", length=255)
- */
- private $password;
- /**
- * @var string
- *
- * @ORMColumn(name="estado", type="boolean")
- */
- private $estado;
- /**
- * @var string
- *
- * @ORMColumn(name="salt", type="string", length=255)
- */
- private $salt;
- /**
- * @ORMManyToMany(targetEntity="Rol", inversedBy="usuarios")
- * @ORMJoinTable(name="usuario_rol")
- */
- private $rolesUsuario;
- /**
- * @ORMOneToOne(targetEntity="Persona")
- * @ORMJoinColumn(name="persona_id", referencedColumnName="id")
- */
- private $persona;
- public function getAttributes()
- {
- return get_class_vars(__CLASS__);
- }
- /**
- * Get id
- *
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set username
- *
- * @param string $username
- *
- * @return Usuario
- */
- public function setUsername($username)
- {
- $this->username = $username;
- return $this;
- }
- /**
- * Get username
- *
- * @return string
- */
- public function getUsername()
- {
- return $this->username;
- }
- /**
- * Set password
- *
- * @param string $password
- *
- * @return Usuario
- */
- public function setPassword($password)
- {
- $this->password = $password;
- return $this;
- }
- /**
- * Get password
- *
- * @return string
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * Set estado
- *
- * @param string $estado
- *
- * @return Usuario
- */
- public function setEstado($estado)
- {
- $this->estado = $estado;
- return $this;
- }
- /**
- * Get estado
- *
- * @return string
- */
- public function getEstado()
- {
- return $this->estado;
- }
- /**
- * Checks whether the user's account has expired.
- *
- * Internally, if this method returns false, the authentication system
- * will throw an AccountExpiredException and prevent login.
- *
- * @return bool true if the user's account is non expired, false otherwise
- *
- * @see AccountExpiredException
- */
- public function isAccountNonExpired()
- {
- return true;
- }
- /**
- * Checks whether the user is locked.
- *
- * Internally, if this method returns false, the authentication system
- * will throw a LockedException and prevent login.
- *
- * @return bool true if the user is not locked, false otherwise
- *
- * @see LockedException
- */
- public function isAccountNonLocked()
- {
- return true;
- }
- /**
- * Checks whether the user's credentials (password) has expired.
- *
- * Internally, if this method returns false, the authentication system
- * will throw a CredentialsExpiredException and prevent login.
- *
- * @return bool true if the user's credentials are non expired, false otherwise
- *
- * @see CredentialsExpiredException
- */
- public function isCredentialsNonExpired()
- {
- return true;
- }
- /**
- * Checks whether the user is enabled.
- *
- * Internally, if this method returns false, the authentication system
- * will throw a DisabledException and prevent login.
- *
- * @return bool true if the user is enabled, false otherwise
- *
- * @see DisabledException
- */
- public function isEnabled()
- {
- if($this->estado == true){
- return true;
- }else{
- return false;
- }
- }
- /**
- * Returns the roles granted to the user.
- *
- * <code>
- * public function getRoles()
- * {
- * return array('ROLE_USER');
- * }
- * </code>
- *
- * Alternatively, the roles might be stored on a ``roles`` property,
- * and populated in any number of different ways when the user object
- * is created.
- *
- * @return (Role|string)[] The user roles
- */
- public function getRolesUsuario()
- {
- return $this->rolesUsuario;
- }
- public function getRoles()
- {
- $r = array();
- foreach ($this->rolesUsuario as $roles){
- $r[] = $roles->getNombre();
- }
- return $r;
- }
- /**
- * Returns the salt that was originally used to encode the password.
- *
- * This can return null if the password was not encoded using a salt.
- *
- * @return string|null The salt
- */
- public function getSalt()
- {
- return $this->salt;
- }
- /**
- * Removes sensitive data from the user.
- *
- * This is important if, at any given point, sensitive information like
- * the plain-text password is stored on this object.
- */
- public function eraseCredentials()
- {
- return false;
- }
- /**
- * Constructor
- */
- public function __construct()
- {
- $this->rolesUsuario = new DoctrineCommonCollectionsArrayCollection();
- }
- /**
- * Set salt
- *
- * @param string $salt
- *
- * @return Usuario
- */
- public function setSalt($salt)
- {
- $this->salt = $salt;
- return $this;
- }
- /**
- * Add role
- *
- * @param CECMEDSeguridadBundleEntityRol $role
- *
- * @return Usuario
- */
- public function addRole(CECMEDSeguridadBundleEntityRol $role)
- {
- $this->rolesUsuario[] = $role;
- return $this;
- }
- /**
- * Remove role
- *
- * @param CECMEDSeguridadBundleEntityRol $role
- */
- public function removeRole(CECMEDSeguridadBundleEntityRol $role)
- {
- $this->rolesUsuario->removeElement($role);
- }
- /**
- * Set persona
- *
- * @param CECMEDSeguridadBundleEntitypersona $persona
- *
- * @return Usuario
- */
- public function setPersona(CECMEDSeguridadBundleEntitypersona $persona = null)
- {
- $this->persona = $persona;
- return $this;
- }
- /**
- * Get persona
- *
- * @return CECMEDSeguridadBundleEntitypersona
- */
- public function getPersona()
- {
- return $this->persona;
- }
- /**
- * @return string
- */
- public function __toString()
- {
- return $this->getUsername();
- }
- /**
- * Add rolesUsuario
- *
- * @param CECMEDSeguridadBundleEntityRol $rolesUsuario
- *
- * @return Usuario
- */
- public function addRolesUsuario(CECMEDSeguridadBundleEntityRol $rolesUsuario)
- {
- $this->rolesUsuario[] = $rolesUsuario;
- return $this;
- }
- /**
- * Remove rolesUsuario
- *
- * @param CECMEDSeguridadBundleEntityRol $rolesUsuario
- */
- public function removeRolesUsuario(CECMEDSeguridadBundleEntityRol $rolesUsuario)
- {
- $this->rolesUsuario->removeElement($rolesUsuario);
- }
- }
- class Rol
- {
- /**
- * @var int
- *
- * @ORMColumn(name="id", type="integer")
- * @ORMId
- * @ORMGeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- *
- * @ORMColumn(name="nombre", type="string", length=255, unique=true)
- */
- private $nombre;
- /**
- * @var string
- *
- * @ORMColumn(name="descripcion", type="string", length=255)
- */
- private $descripcion;
- /**
- * @ORMManyToMany(targetEntity="Funcionalidad", inversedBy="rolesUsuario")
- * @ORMJoinTable(name="rol_funcionalidad")
- */
- private $funcionalidades;
- /**
- * @ORMManyToMany(targetEntity="Usuario", mappedBy="rolesUsuario")
- */
- private $usuarios;
- public function getAttributes()
- {
- return get_class_vars(__CLASS__);
- }
- /**
- * Get id
- *
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set nombre
- *
- * @param string $nombre
- *
- * @return Rol
- */
- public function setNombre($nombre)
- {
- $this->nombre = $nombre;
- return $this;
- }
- /**
- * Get nombre
- *
- * @return string
- */
- public function getNombre()
- {
- return $this->nombre;
- }
- /**
- * Set descripcion
- *
- * @param string $descripcion
- *
- * @return Rol
- */
- public function setDescripcion($descripcion)
- {
- $this->descripcion = $descripcion;
- return $this;
- }
- /**
- * Get descripcion
- *
- * @return string
- */
- public function getDescripcion()
- {
- return $this->descripcion;
- }
- /**
- * @return string
- */
- public function __toString()
- {
- return $this->getNombre();
- }
- /**
- * Constructor
- */
- public function __construct()
- {
- $this->funcionalidades = new DoctrineCommonCollectionsArrayCollection();
- $this->usuarios = new DoctrineCommonCollectionsArrayCollection();
- }
- /**
- * Add funcionalidade
- *
- * @param CECMEDSeguridadBundleEntityRol $funcionalidade
- *
- * @return Rol
- */
- public function addFuncionalidade(CECMEDSeguridadBundleEntityRol $funcionalidade)
- {
- $this->funcionalidades[] = $funcionalidade;
- return $this;
- }
- /**
- * Remove funcionalidade
- *
- * @param CECMEDSeguridadBundleEntityRol $funcionalidade
- */
- public function removeFuncionalidade(CECMEDSeguridadBundleEntityRol $funcionalidade)
- {
- $this->funcionalidades->removeElement($funcionalidade);
- }
- /**
- * Get funcionalidades
- *
- * @return DoctrineCommonCollectionsCollection
- */
- public function getFuncionalidades()
- {
- return $this->funcionalidades;
- }
- /**
- * Add usuario
- *
- * @param CECMEDSeguridadBundleEntityUsuario $usuario
- *
- * @return Rol
- */
- public function addUsuario(CECMEDSeguridadBundleEntityUsuario $usuario)
- {
- $usuario->addRolesUsuario($this);
- $this->usuarios[] = '$usuario';
- return $this;
- }
- /**
- * Remove usuario
- *
- * @param CECMEDSeguridadBundleEntityUsuario $usuario
- */
- public function removeUsuario(CECMEDSeguridadBundleEntityUsuario $usuario)
- {
- $this->usuarios->removeElement($usuario);
- }
- /**
- * Get usuarios
- *
- * @return DoctrineCommonCollectionsCollection
- */
- public function getUsuarios()
- {
- return $this->usuarios;
- }
- }
- public function addUsuario(CECMEDSeguridadBundleEntityUsuario $usuario)
- {
- $usuario->addRolesUsuario($this);
- $this->usuarios[] = '$usuario';
- return $this;
- }
- public function addUsuario(CECMEDSeguridadBundleEntityUsuario $usuario)
- {
- $usuario->addRolesUsuario($this);
- $this->usuarios[] = $usuario;
- return $this;
- }
- <?php
- /** @Entity */
- class User
- {
- // ...
- /**
- * @ORMManyToMany(targetEntity="Group", inversedBy="users")
- * @ORMJoinTable(name="users_groups",
- * joinColumns={@ORMJoinColumn(name="user_id", referencedColumnName="id")},
- * inverseJoinColumns={@ORMJoinColumn(name="group_id", referencedColumnName="id")}
- * )
- */
- private $groups;
- public function __construct() {
- $this->groups = new DoctrineCommonCollectionsArrayCollection();
- }
- // ...
- }
- /** @Entity */
- class Group
- {
- // ...
- /**
- * @ORMManyToMany(targetEntity="User", mappedBy="groups")
- */
- private $users;
- public function __construct() {
- $this->users = new DoctrineCommonCollectionsArrayCollection();
- }
- // ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement