Commit 452f1e59 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Amélioration doc + AffectationService

parent 0f7f0950
Loading
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -3,9 +3,10 @@
use UnicaenPrivilege\Controller\AffectationController;
use UnicaenPrivilege\Controller\AffectationControllerFactory;

use UnicaenPrivilege\Controller\ConfigurationController;
use UnicaenPrivilege\Controller\ConfigurationControllerFactory;
use UnicaenPrivilege\Guard\PrivilegeController;
use UnicaenPrivilege\Provider\Privilege\PrivilegePrivileges;
use UnicaenPrivilege\Service\Affectation\AffectationService;
use UnicaenPrivilege\Service\Affectation\AffectationServiceFactory;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;

@@ -38,7 +39,7 @@ return [
                            'privilege' => [
                                'label' => 'Privilège',
                                'route' => 'unicaen-privilege/affectation',
                                'resource' => \UnicaenPrivilege\Guard\PrivilegeController::getResourceId(AffectationController::class, 'index'),
                                'resource' => PrivilegeController::getResourceId(AffectationController::class, 'index'),
                                'order'    => 5000,
                            ],
                        ],
@@ -83,7 +84,9 @@ return [
    ],

    'service_manager' => [
        'factories' => [],
        'factories' => [
            AffectationService::class => AffectationServiceFactory::class,
        ],
    ],
    'controllers'     => [
        'factories' => [
+5 −12
Original line number Diff line number Diff line
@@ -2,16 +2,16 @@

namespace UnicaenPrivilege\Controller;

use UnicaenPrivilege\Entity\Db\Privilege;
use UnicaenPrivilege\Service\Affectation\AffectationServiceAwareTrait;
use UnicaenPrivilege\Service\Categorie\CategorieServiceAwareTrait;
use UnicaenPrivilege\Service\Privilege\PrivilegeServiceAwareTrait;
use UnicaenUtilisateur\Entity\Db\Role;
use UnicaenUtilisateur\Service\Role\RoleServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;

class AffectationController extends AbstractActionController {
    use AffectationServiceAwareTrait;
    use CategorieServiceAwareTrait;
    use RoleServiceAwareTrait;
    use PrivilegeServiceAwareTrait;
@@ -33,17 +33,10 @@ class AffectationController extends AbstractActionController {

    public function modifierAction() : JsonModel
    {
        $privilegeId = $this->params()->fromRoute("privilege");
        $roleId = $this->params()->fromRoute("role");
        /**
         * @var Privilege $privilege
         * @var Role $role
         */
        $privilege = $this->getPrivilegeService()->getRequestedPrivilege($this);
        $role = $this->getRoleService()->getRequestedRole($this);

        $privilege = $this->getPrivilegeService()->getPrivilege($privilegeId);
        $role = $this->getPrivilegeService()->getRole($roleId);

        $value = $this->getPrivilegeService()->toggle($role,$privilege);
        $value = $this->getAffectationService()->toggle($role,$privilege);

        return new JsonModel([
            'value' => $value,
+4 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace UnicaenPrivilege\Controller;

use Interop\Container\ContainerInterface;
use UnicaenPrivilege\Service\Affectation\AffectationService;
use UnicaenPrivilege\Service\Categorie\CategorieService;
use UnicaenPrivilege\Service\Privilege\PrivilegeService;
use UnicaenUtilisateur\Service\Role\RoleService;
@@ -12,16 +13,19 @@ class AffectationControllerFactory {
    public function __invoke(ContainerInterface $container) : AffectationController
    {
        /**
         * @var AffectationService $affectationService
         * @var CategorieService $categorieService
         * @var PrivilegeService $privilegeService
         * @var RoleService $roleService
         */
        $affectationService = $container->get(AffectationService::class);
        $categorieService = $container->get(CategorieService::class);
        $privilegeService = $container->get(PrivilegeService::class);
        $roleService = $container->get(RoleService::class);

        /** @var AffectationController $controller*/
        $controller = new AffectationController();
        $controller->setAffectationService($affectationService);
        $controller->setCategorieService($categorieService);
        $controller->setPrivilegeService($privilegeService);
        $controller->setRoleService($roleService);
+0 −1
Original line number Diff line number Diff line
@@ -74,7 +74,6 @@ class PrivilegeController extends AbstractActionController {

    public function supprimerAction() {
        $privilege = $this->getPrivilegeService()->getRequestedPrivilege($this);
        $categorie = $privilege->getCategorie();

        /** @var Request $request */
        $request = $this->getRequest();
+22 −44
Original line number Diff line number Diff line
@@ -2,7 +2,10 @@

namespace UnicaenPrivilege\Entity\Db;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use UnicaenPrivilege\Provider\Privilege\Privileges;
use UnicaenUtilisateur\Entity\Db\RoleInterface;
use Zend\Permissions\Acl\Resource\ResourceInterface;


@@ -62,17 +65,14 @@ abstract class AbstractPrivilege implements PrivilegeInterface, ResourceInterfac
     */
    public function __construct()
    {
        $this->role = new \Doctrine\Common\Collections\ArrayCollection();
        $this->role = new ArrayCollection();
    }

    /**
     * Set code
     *
     * @param string $code
     *
     * @return Privilege
     */
    public function setCode($code)
    public function setCode(string $code) : PrivilegeInterface
    {
        $this->code = $code;

@@ -80,28 +80,23 @@ abstract class AbstractPrivilege implements PrivilegeInterface, ResourceInterfac
    }

    /**
     * Get code
     *
     * @return string
     */
    public function getCode()
    public function getCode() : string
    {
        return $this->code;
    }

    public function getFullCode()
    public function getFullCode() : string
    {
        return $this->getCategorie()->getCode() . '-' . $this->getCode();
    }

    /**
     * Set libelle
     *
     * @param string $libelle
     *
     * @return Privilege
     */
    public function setLibelle($libelle)
    public function setLibelle(string $libelle) : PrivilegeInterface
    {
        $this->libelle = $libelle;

@@ -110,30 +105,26 @@ abstract class AbstractPrivilege implements PrivilegeInterface, ResourceInterfac

    /**
     * Get libelle
     *
     * @return string
     */
    public function getLibelle()
    public function getLibelle() : string
    {
        return $this->libelle;
    }

    /**
     *
     * @return integer
     */
    function getOrdre()
    function getOrdre() : int
    {
        return $this->ordre;
    }

    /**
     *
     * @param integer $ordre
     *
     * @return self
     */
    function setOrdre($ordre)
    function setOrdre(int $ordre) : PrivilegeInterface
    {
        $this->ordre = $ordre;

@@ -141,23 +132,18 @@ abstract class AbstractPrivilege implements PrivilegeInterface, ResourceInterfac
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    public function getId() : int
    {
        return $this->id;
    }

    /**
     * Set categorie
     *
     * @param Categorie $categorie
     *
     * @param Categorie|null $categorie
     * @return self
     */
    public function setCategorie(Categorie $categorie = null)
    public function setCategorie(?Categorie $categorie = null) : PrivilegeInterface
    {
        $this->categorie = $categorie;

@@ -165,45 +151,37 @@ abstract class AbstractPrivilege implements PrivilegeInterface, ResourceInterfac
    }

    /**
     * Get categorie
     *
     * @return Categorie
     */
    public function getCategorie()
    public function getCategorie() : Categorie
    {
        return $this->categorie;
    }

    /**
     * Add role
     *
     * @param RoleInterface $role
     *
     * @return self
     */
    public function addRole(RoleInterface $role)
    public function addRole(RoleInterface $role) : PrivilegeInterface
    {
        $this->role->add($role);

        return $this;
    }

    /**
     * Remove role
     *
     * @param RoleInterface $role
     * @return self
     */
    public function removeRole(RoleInterface $role)
    public function removeRole(RoleInterface $role) : PrivilegeInterface
    {
        $this->role->removeElement($role);
        return $this;
    }

    /**
     * Get role
     *
     * @return Collection
     */
    public function getRole()
    public function getRole() : Collection
    {
        return $this->role;
    }
@@ -211,7 +189,7 @@ abstract class AbstractPrivilege implements PrivilegeInterface, ResourceInterfac
    /**
     * @return string
     */
    public function __toString()
    public function __toString() : string
    {
        return $this->getLibelle();
    }
@@ -219,7 +197,7 @@ abstract class AbstractPrivilege implements PrivilegeInterface, ResourceInterfac
    /**
     * @return string
     */
    public function getResourceId()
    public function getResourceId() : string
    {
        return Privileges::getResourceId($this);
    }
Loading