Adding new function getRolesObj(). The getRoles() function is used as an array by other componentes

skala
Julio Montoya 13 years ago
parent 7b99deecfa
commit 45bd1f54d3
  1. 28
      main/inc/Entity/User.php

@ -238,6 +238,8 @@ class User implements AdvancedUserInterface, UserProviderInterface
*/
private $salt;
private $em;
/**
*
*/
@ -250,6 +252,15 @@ class User implements AdvancedUserInterface, UserProviderInterface
$this->salt = sha1(uniqid(null, true));
}
/**
* Needed in order to use the security component
* @param \Doctrine\ORM\EntityManager $em
*/
public function setEntityManager($em)
{
$this->em = $em;
}
/**
* @param string $username
* @return mixed
@ -257,9 +268,10 @@ class User implements AdvancedUserInterface, UserProviderInterface
*/
public function loadUserByUsername($username)
{
//var_dump($username);exit;
$q = $this
$q = $this->em
->createQueryBuilder('u')
->select('u')
->from('Entity\User', 'u')
->where('u.username = :username OR u.email = :email')
->setParameter('username', $username)
->setParameter('email', $username)
@ -267,6 +279,7 @@ class User implements AdvancedUserInterface, UserProviderInterface
try {
$user = $q->getSingleResult();
} catch (NoResultException $e) {
throw new UsernameNotFoundException(
sprintf('Unable to find an active admin User identified by "%s".', $username),
@ -275,7 +288,6 @@ class User implements AdvancedUserInterface, UserProviderInterface
$e
);
}
return $user;
}
@ -308,7 +320,15 @@ class User implements AdvancedUserInterface, UserProviderInterface
*/
public function getRoles()
{
//return $this->roles->toArray();
return $this->roles->toArray();
}
/**
*
* @return ArrayCollection
*/
public function getRolesObj()
{
return $this->roles;
}

Loading…
Cancel
Save