-
-
Save doctrinebot/1b32839aeca8cad7270f to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-1885 - https://github.com/doctrine/doctrine2/issues/2549
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace GlobalTreatments\ApplicationBundle\Entity; | |
use \Serializable; | |
use Doctrine\ORM\Mapping as ORM; | |
use Doctrine\Common\Collections\ArrayCollection; | |
use Symfony\Component\Security\Core\User\UserInterface; | |
use Symfony\Component\Security\Core\User\AdvancedUserInterface; | |
/** | |
* @ORM\Table(name="`User`") | |
* @ORM\Entity | |
*/ | |
class User implements AdvancedUserInterface, Serializable { | |
/** | |
* @var integer $idUser | |
* | |
* @ORM\Column(name="`IdUser`", type="integer", nullable=false) | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="SEQUENCE") | |
* @ORM\SequenceGenerator(sequenceName="User_IdUser_seq", allocationSize="1", initialValue="1") | |
*/ | |
protected $idUser; | |
/** | |
* @var string $username | |
* | |
* @ORM\Column(name="`Username`", type="string", length=50, nullable=false) | |
*/ | |
protected $username; | |
/** | |
* @var string $password | |
* | |
* @ORM\Column(name="`Password`", type="string", length=40, nullable=false) | |
*/ | |
protected $password; | |
/** | |
* @var boolean $active | |
* | |
* @ORM\Column(name="`Active`", type="boolean", nullable=false) | |
*/ | |
protected $active; | |
/** | |
*@var ArrayCollection $roles | |
* | |
* @ORM\ManyToMany(targetEntity="Role") | |
* @ORM\JoinTable( | |
* name="`UserRole`", | |
* joinColumns={@ORM\JoinColumn(name="`IdUser`", referencedColumnName="IdUser")}, | |
* inverseJoinColumns={@ORM\JoinColumn(name="`IdRole`", referencedColumnName="IdRole")} | |
* ) | |
*/ | |
protected $roles; | |
public function __construct() { | |
$this->roles = new ArrayCollection(); | |
} | |
// Serializable implementation | |
public function serialize() { | |
return serialize( | |
array( | |
'idUser' => $this->idUser, | |
'username' => $this->username, | |
'password' => $this->password, | |
'active' => $this->active | |
) | |
); | |
} | |
public function unserialize($data) { | |
$data = unserialize($data); | |
$this->idUser = $data['idUser']; | |
$this->username = $data['username']; | |
$this->password = $data['password']; | |
$this->active = $data['active']; | |
} | |
// UserInterface implementation | |
public function getRoles() { | |
$roles = array(); | |
foreach ($this->roles as $role) { | |
$roles[] = $role->getName(); | |
} | |
return $roles; | |
// return array('ROLE_USER'); | |
} | |
public function setRoles($roles) { | |
$this->roles = $roles; | |
} | |
public function getSalt() { | |
// This can return null if the password was not encoded using a salt. | |
return null; | |
} | |
public function eraseCredentials() { | |
//Note: http://stackoverflow.com/questions/7459760/remember-me-functionality-not-working-in-symfony2 | |
//Note: http://stackoverflow.com/questions/8455398/symfony-2-logout-userinterfaceerasecredentials | |
//$this->setPassword(null); | |
} | |
public function equals(UserInterface $user) { | |
return strcmp($this->username, $user->username); | |
} | |
// AdvancedUserInterface implementation | |
public function isAccountNonExpired() { | |
return true; | |
} | |
public function isAccountNonLocked() { | |
return true; | |
} | |
public function isCredentialsNonExpired() { | |
return true; | |
} | |
public function isEnabled() { | |
return $this->active; | |
} | |
// Getters and Setters | |
/** | |
* @return integer | |
*/ | |
public function getIdUser() { | |
return $this->idUser; | |
} | |
/** | |
* @param string $username | |
*/ | |
public function setUsername($username) { | |
$this->username = $username; | |
} | |
/** | |
* @return string | |
*/ | |
public function getUsername() { | |
return $this->username; | |
} | |
/** | |
* @param string $password | |
*/ | |
public function setPassword($password) { | |
$this->password = $password; | |
} | |
/** | |
* @return string | |
*/ | |
public function getPassword() { | |
return $this->password; | |
} | |
/** | |
* @param boolean $active | |
*/ | |
public function setActive($active) { | |
$this->active = $active; | |
} | |
/** | |
* @return boolean | |
*/ | |
public function getActive() { | |
return $this->active; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace GlobalTreatments\ApplicationBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Table(name="`Role`") | |
* @ORM\Entity | |
*/ | |
class Role { | |
/** | |
* @var integer $idRole | |
* | |
* @ORM\Column(name="`IdRole`", type="integer", nullable=false) | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="SEQUENCE") | |
* @ORM\SequenceGenerator(sequenceName="Role_IdRole_seq", allocationSize="1", initialValue="1") | |
*/ | |
protected $idRole; | |
/** | |
* @var string $name | |
* | |
* @ORM\Column(name="`Name`", type="string", length=50, nullable=false) | |
*/ | |
protected $name; | |
/** | |
* @var boolean $active | |
* | |
* @ORM\Column(name="`Active`", type="boolean", nullable=false) | |
*/ | |
protected $active; | |
/** | |
* @var boolean $static | |
* | |
* @ORM\Column(name="`Static`", type="boolean", nullable=false) | |
*/ | |
protected $static; | |
/** | |
* @var string $staticName | |
* | |
* @ORM\Column(name="`StaticName`", type="string", length=20, nullable=true) | |
*/ | |
protected $staticName; | |
/** | |
* @return integer | |
*/ | |
public function getIdRole() { | |
return $this->idRole; | |
} | |
/** | |
* @param string $name | |
*/ | |
public function setName($name) { | |
$this->name = $name; | |
} | |
/** | |
* @return string | |
*/ | |
public function getName() { | |
return $this->name; | |
} | |
/** | |
* @param boolean $active | |
*/ | |
public function setActive($active) { | |
$this->active = $active; | |
} | |
/** | |
* @return boolean | |
*/ | |
public function getActive() { | |
return $this->active; | |
} | |
/** | |
* @param boolean $static | |
*/ | |
public function setStatic($static) { | |
$this->static = $static; | |
} | |
/** | |
* @return boolean | |
*/ | |
public function getStatic() { | |
return $this->static; | |
} | |
/** | |
* @param string $staticName | |
*/ | |
public function setStaticName($staticName) { | |
$this->staticName = $staticName; | |
} | |
/** | |
* @return string | |
*/ | |
public function getStaticName() { | |
return $this->staticName; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment