Commit 48d5fa7f authored by Bertrand Gauthier's avatar Bertrand Gauthier

Work in progress.

parent c10c0124
......@@ -2,8 +2,6 @@
namespace UnicaenAuth\Controller;
use UnicaenAuth\Entity\Db\Privilege;
use UnicaenAuth\Entity\Db\Role;
use UnicaenAuth\Form\Droits\Traits\RoleFormAwareTrait;
use UnicaenAuth\Service\Traits\PrivilegeServiceAwareTrait;
use UnicaenAuth\Service\Traits\RoleServiceAwareTrait;
......
<?php
namespace UnicaenAuth\Entity\Db;
use BjyAuthorize\Acl\HierarchicalRoleInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* Role entity abstract mother class.
*
* @ORM\MappedSuperclass
*/
abstract class AbstractRole implements HierarchicalRoleInterface
{
/**
* @var int
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(name="role_id", type="string", length=255, unique=true, nullable=false)
*/
protected $roleId;
/**
* @var boolean
* @ORM\Column(name="is_default", type="boolean", nullable=true)
*/
protected $isDefault = false;
/**
* @var Role
* @ORM\ManyToOne(targetEntity="Role")
*/
protected $parent;
/**
* @var string
* @ORM\Column(name="ldap_filter", type="string", length=255, unique=true, nullable=true)
*/
protected $ldapFilter;
/**
* @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.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set the id.
*
* @param int $id
*
* @return self
*/
public function setId($id)
{
$this->id = (int)$id;
return $this;
}
/**
* Get the role id.
*
* @return string
*/
public function getRoleId()
{
return $this->roleId;
}
/**
* Set the role id.
*
* @param string $roleId
*
* @return self
*/
public function setRoleId($roleId)
{
$this->roleId = (string)$roleId;
return $this;
}
/**
* Is this role the default one ?
*
* @return boolean
*/
public function getIsDefault()
{
return $this->isDefault;
}
/**
* Set this role as the default one.
*
* @param boolean $isDefault
*
* @return self
*/
public function setIsDefault($isDefault)
{
$this->isDefault = (boolean)$isDefault;
return $this;
}
/**
* Get the parent role
*
* @return Role
*/
public function getParent()
{
return $this->parent;
}
/**
* Set the parent role.
*
* @param Role $role
*
* @return self
*/
public function setParent(Role $parent)
{
$this->parent = $parent;
return $this;
}
/**
* @return string
*/
public function getLdapFilter()
{
return $this->ldapFilter;
}
/**
* @param string $ldapFilter
*
* @return Role
*/
public function setLdapFilter($ldapFilter)
{
$this->ldapFilter = $ldapFilter;
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;
}
/**
*
* @return string
*/
public function __toString()
{
return $this->getRoleId();
}
}
\ No newline at end of file
......@@ -6,7 +6,6 @@ use BjyAuthorize\Provider\Role\ProviderInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use ZfcUser\Entity\UserInterface;
/**
* User entity abstract mother class.
......
......@@ -12,225 +12,12 @@ use BjyAuthorize\Acl\HierarchicalRoleInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* An example entity that represents a role.
* User entity class.
*
* @ORM\Entity
* @ORM\Table(name="user_role")
* @ORM\Table(name="`role`")
*/
class Role implements HierarchicalRoleInterface
class Role extends AbstractRole
{
/**
* @var int
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(name="role_id", type="string", length=255, unique=true, nullable=false)
*/
protected $roleId;
/**
* @var boolean
* @ORM\Column(name="is_default", type="boolean", nullable=true)
*/
protected $isDefault = false;
/**
* @var Role
* @ORM\ManyToOne(targetEntity="Role")
*/
protected $parent;
/**
* @var string
* @ORM\Column(name="ldap_filter", type="string", length=255, unique=true, nullable=true)
*/
protected $ldapFilter;
/**
* @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.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set the id.
*
* @param int $id
*
* @return self
*/
public function setId($id)
{
$this->id = (int)$id;
return $this;
}
/**
* Get the role id.
*
* @return string
*/
public function getRoleId()
{
return $this->roleId;
}
/**
* Set the role id.
*
* @param string $roleId
*
* @return self
*/
public function setRoleId($roleId)
{
$this->roleId = (string)$roleId;
return $this;
}
/**
* Is this role the default one ?
*
* @return boolean
*/
public function getIsDefault()
{
return $this->isDefault;
}
/**
* Set this role as the default one.
*
* @param boolean $isDefault
*
* @return self
*/
public function setIsDefault($isDefault)
{
$this->isDefault = (boolean)$isDefault;
return $this;
}
/**
* Get the parent role
*
* @return Role
*/
public function getParent()
{
return $this->parent;
}
/**
* Set the parent role.
*
* @param Role $role
*
* @return self
*/
public function setParent(Role $parent)
{
$this->parent = $parent;
return $this;
}
/**
* @return string
*/
public function getLdapFilter()
{
return $this->ldapFilter;
}
/**
* @param string $ldapFilter
*
* @return Role
*/
public function setLdapFilter($ldapFilter)
{
$this->ldapFilter = $ldapFilter;
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;
}
/**
*
* @return string
*/
public function __toString()
{
return $this->getRoleId();
}
}
\ No newline at end of file
<?php
namespace UnicaenAuth\Entity\Db;
use BjyAuthorize\Acl\HierarchicalRoleInterface;
use ZfcUser\Entity\UserInterface;
interface RoleInterface extends HierarchicalRoleInterface
{
/**
* @param int $id
* @return self
*/
public function setId($id);
/**
* @return int
*/
public function getId();
/**
* @return string
*/
public function getRoleId();
/**
* @param string $roleId
* @return self
*/
public function setRoleId($roleId);
/**
* @return boolean
*/
public function getIsDefault();
/**
* @param boolean $isDefault
* @return self
*/
public function setIsDefault($isDefault);
/**
* @return RoleInterface|null
*/
public function getParent();
/**
* @param RoleInterface|null $parent
* @return self
*/
public function setParent(RoleInterface $parent = null);
/**
* @return string
*/
public function getLdapFilter();
/**
* @param string $ldapFilter
* @return self
*/
public function setLdapFilter($ldapFilter);
/**
* @return UserInterface[]
*/
public function getUsers();
/**
* @param UserInterface $user
* @return self
*/
public function addUser(UserInterface $user);
/**
* @return string
*/
public function __toString();
}
\ No newline at end of file
<?php
namespace UnicaenAuth\Entity\Db;
use Doctrine\Common\Collections\Collection;
interface UserInterface extends \ZfcUser\Entity\UserInterface
{
/**
* @return int
*/
public function getId();
/**
* @param int $id
* @return self
*/
public function setId($id);
/**
* @return string
*/
public function getUsername();
/**
* @param string $username
* @return self
*/
public function setUsername($username);
/**
* @return string
*/
public function getEmail();
/**
* @param string $email
* @return self
*/
public function setEmail($email);
/**
* @return string
*/
public function getDisplayName();
/**
* @param string $displayName
* @return self
*/
public function setDisplayName($displayName);
/**
* Get password.
*
* @return string
*/
public function getPassword();
/**
* @param string $password
* @return self
*/
public function setPassword($password);
/**
* @return int
*/
public function getState();
/**
* @param int $state
* @return self
*/
public function setState($state);
/**
* @return Collection
*/
public function getRoles();
/**
* @param Role $role
* @return self
*/
public function addRole(Role $role);
/**
* @return string
*/
public function __toString();
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">