Commit 68a72222 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Création d'une classe mère abstraite pour l'entité "User" (annotation...

Création d'une classe mère abstraite pour l'entité "User" (annotation @ORM\MappedSupperclass) destinée à être étendue dans les applis.
Entité "Role" : AJout de l'associations to-many vers User.
parent 8e24f16a
<?php
namespace UnicaenAuth\Entity\Db;
use BjyAuthorize\Provider\Role\ProviderInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use ZfcUser\Entity\UserInterface;
/**
* User entity abstract mother class.
*
* @ORM\MappedSuperclass
*/
abstract class AbstractUser implements UserInterface, ProviderInterface
{
/**
* @var int
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(type="string", length=255, unique=true, nullable=true)
*/
protected $username;
/**
* @var string
* @ORM\Column(type="string", unique=true, length=255)
*/
protected $email;
/**
* @var string
* @ORM\Column(name="display_name", type="string", length=50, nullable=false)
*/
protected $displayName;
/**
* @var string
* @ORM\Column(type="string", length=128)
*/
protected $password;
/**
* @var int
* @ORM\Column(type="smallint")
*/
protected $state;
/**
* @var \Doctrine\Common\Collections\Collection
* @ORM\ManyToMany(targetEntity="UnicaenAuth\Entity\Db\Role")
* @ORM\JoinTable(name="user_role_linker",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
*/
protected $roles;
/**
* Initialies the roles variable.
*/
public function __construct()
{
$this->roles = new ArrayCollection();
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set id.
*
* @param int $id
*
* @return void
*/
public function setId($id)
{
$this->id = (int) $id;
}
/**
* Get username.
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set username.
*
* @param string $username
*
* @return void
*/
public function setUsername($username)
{
$this->username = $username;
}
/**
* Get email.
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set email.
*
* @param string $email
*
* @return void
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* Get displayName.
*
* @return string
*/
public function getDisplayName()
{
return $this->displayName;
}
/**
* Set displayName.
*
* @param string $displayName
*
* @return void
*/
public function setDisplayName($displayName)
{
$this->displayName = $displayName;
}
/**
* Get password.
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set password.
*
* @param string $password
*
* @return void
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
* Get state.
*
* @return int
*/
public function getState()
{
return $this->state;
}
/**
* Set state.
*
* @param int $state
*
* @return void
*/
public function setState($state)
{
$this->state = $state;
}
/**
* Get role.
*
* @return array
*/
public function getRoles()
{
return $this->roles->getValues();
}
/**
* Add a role to the user.
*
* @param Role $role
*
* @return void
*/
public function addRole($role)
{
$this->roles[] = $role;
}
/**
*
* @return string
*/
public function __toString()
{
return $this->getDisplayName();
}
}
\ No newline at end of file
......@@ -45,6 +45,16 @@ class Role implements HierarchicalRoleInterface
*/
protected $parent;
/**
* @var \Doctrine\Common\Collections\Collection
* @ORM\ManyToMany(targetEntity="UnicaenAuth\Entity\Db\User")
* @ORM\JoinTable(name="user_role_linker",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
*/
protected $users;
/**
* Get the id.
*
......@@ -136,6 +146,28 @@ class Role implements HierarchicalRoleInterface
$this->parent = $parent;
return $this;
}
/**
* Get users.
*
* @return array
*/
public function getUsers()
{
return $this->users->getValues();
}
/**
* Add a user to the role.
*
* @param User $user
*
* @return void
*/
public function addUser($user)
{
$this->users[] = $user;
}
/**
*
......
<?php
/**
* BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize)
*
* @link https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace UnicaenAuth\Entity\Db;
use BjyAuthorize\Provider\Role\ProviderInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use ZfcUser\Entity\UserInterface;
/**
* An example of how to implement a role aware user entity.
* User entity class.
*
* @ORM\Entity
* @ORM\Table(name="user")
*/
class User implements UserInterface, ProviderInterface
class User extends AbstractUser
{
/**
* @var int
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(type="string", length=255, unique=true, nullable=true)
*/
protected $username;
/**
* @var string
* @ORM\Column(type="string", unique=true, length=255)
*/
protected $email;
/**
* @var string
* @ORM\Column(name="display_name", type="string", length=50, nullable=false)
*/
protected $displayName;
/**
* @var string
* @ORM\Column(type="string", length=128)
*/
protected $password;
/**
* @var int
* @ORM\Column(type="smallint")
*/
protected $state;
/**
* @var \Doctrine\Common\Collections\Collection
* @ORM\ManyToMany(targetEntity="UnicaenAuth\Entity\Db\Role")
* @ORM\JoinTable(name="user_role_linker",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
*/
protected $roles;
/**
* Initialies the roles variable.
*/
public function __construct()
{
$this->roles = new ArrayCollection();
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set id.
*
* @param int $id
*
* @return void
*/
public function setId($id)
{
$this->id = (int) $id;
}
/**
* Get username.
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set username.
*
* @param string $username
*
* @return void
*/
public function setUsername($username)
{
$this->username = $username;
}
/**
* Get email.
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set email.
*
* @param string $email
*
* @return void
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* Get displayName.
*
* @return string
*/
public function getDisplayName()
{
return $this->displayName;
}
/**
* Set displayName.
*
* @param string $displayName
*
* @return void
*/
public function setDisplayName($displayName)
{
$this->displayName = $displayName;
}
/**
* Get password.
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set password.
*
* @param string $password
*
* @return void
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
* Get state.
*
* @return int
*/
public function getState()
{
return $this->state;
}
/**
* Set state.
*
* @param int $state
*
* @return void
*/
public function setState($state)
{
$this->state = $state;
}
/**
* Get role.
*
* @return array
*/
public function getRoles()
{
return $this->roles->getValues();
}
/**
* Add a role to the user.
*
* @param Role $role
*
* @return void
*/
public function addRole($role)
{
$this->roles[] = $role;
}
/**
*
* @return string
*/
public function __toString()
{
return $this->getDisplayName();
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment