Commit 1f284fab authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Initial commit

parents
<?php
namespace UnicaenPrivilege;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\Glob;
use Zend\Config\Factory as ConfigFactory;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$e->getApplication()->getServiceManager()->get('translator');
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
/* Active un layout spécial si la requête est de type AJAX. Valable pour TOUS les modules de l'application. */
$eventManager->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch',
function (MvcEvent $e) {
$request = $e->getRequest();
if ($request instanceof HttpRequest && $request->isXmlHttpRequest()) {
$e->getTarget()->layout('layout/ajax.phtml');
}
}
);
}
public function getConfig()
{
$configInit = [
__DIR__ . '/config/module.config.php'
];
$configFiles = ArrayUtils::merge(
$configInit,
Glob::glob(__DIR__ . '/config/merged/{,*.}{config}.php', Glob::GLOB_BRACE)
);
return ConfigFactory::fromFiles($configFiles);
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
{
"name": "unicaen/utilisateur",
"description": "Module reprenant la gestion des utilisateurs, privileges et roles",
"repositories": [
{
"type": "composer",
"url": "https://gest.unicaen.fr/packagist"
}
],
"require": {
"unicaen/app": "dev-zf-3.x",
"unicaen/auth": "dev-zf-3.x",
"unicaen/utilisateur": "dev-zf-3.x"
},
"require-dev": {
"phpunit/phpunit": ">=3.7"
},
"autoload": {
"psr-0": {
"UnicaenUtilisateur": "src/"
},
"classmap": [
"./Module.php"
]
}
}
<?php
use UnicaenPrivilege\Controller\ConfigurationController;
use UnicaenPrivilege\Controller\ConfigurationControllerFactory;
use UnicaenPrivilege\Form\CategoriePrivilege\CategoriePrivilegeForm;
use UnicaenPrivilege\Form\CategoriePrivilege\CategoriePrivilegeFormFactory;
use UnicaenPrivilege\Form\CategoriePrivilege\CategoriePrivilegeHydrator;
use UnicaenPrivilege\Form\CategoriePrivilege\CategoriePrivilegeHydratorFactory;
use UnicaenPrivilege\Form\Privilege\PrivilegeForm;
use UnicaenPrivilege\Form\Privilege\PrivilegeFormFactory;
use UnicaenPrivilege\Form\Privilege\PrivilegeHydrator;
use UnicaenPrivilege\Form\Privilege\PrivilegeHydratorFactory;
use UnicaenPrivilege\Provider\Privilege\PrivilegePrivileges;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
return [
'bjyauthorize' => [
'guards' => [
UnicaenPrivilege\Guard\PrivilegeController::class => [
[
'controller' => ConfigurationController::class,
'action' => [
'index-configuration-categorie',
'gerer-categorie',
'provider',
],
'privileges' => [
PrivilegePrivileges::PRIVILEGE_VOIR,
],
],
[
'controller' => ConfigurationController::class,
'action' => [
'creer-privilege',
'creer-categorie',
],
'privileges' => [
PrivilegePrivileges::PRIVILEGE_AJOUTER,
],
],
[
'controller' => ConfigurationController::class,
'action' => [
'modifier-privilege',
'modifier-categorie',
],
'privileges' => [
PrivilegePrivileges::PRIVILEGE_MODIFIER,
],
],
[
'controller' => ConfigurationController::class,
'action' => [
'detruire-privilege',
'detruire-categorie',
],
'privileges' => [
PrivilegePrivileges::PRIVILEGE_SUPPRIMER,
],
],
],
],
],
'navigation' => [
'default' => [
'home' => [
'pages' => [
'administration' => [
'pages' => [
'privilege' => [
'pages' => [
'privilege-configuration' => [
'label' => 'Configuration',
'route' => 'configuration-categorie',
'resource' => PrivilegePrivileges::getResourceId(PrivilegePrivileges::PRIVILEGE_AJOUTER),
'order' => 10001,
'pages' => [
'privilege-configuration' => [
'label' => 'Gérer une catégorie',
'route' => 'configuration-categorie/gerer',
'resource' => PrivilegePrivileges::getResourceId(PrivilegePrivileges::PRIVILEGE_AJOUTER),
'order' => 10001,
],
],
],
],
],
],
],
],
],
],
],
'router' => [
'routes' => [
'configuration-categorie' => [
'type' => Literal::class,
'options' => [
'route' => '/configuration-categorie',
'defaults' => [
'controller' => ConfigurationController::class,
'action' => 'index-configuration-categorie',
],
],
'may_terminate' => true,
'child_routes' => [
'creer' => [
'type' => Literal::class,
'options' => [
'route' => '/creer',
'defaults' => [
'controller' => ConfigurationController::class,
'action' => 'creer-categorie',
],
],
'may_terminate' => true,
],
'gerer' => [
'type' => Segment::class,
'options' => [
'route' => '/gerer/:categorie',
'defaults' => [
'controller' => ConfigurationController::class,
'action' => 'gerer-categorie',
],
],
'may_terminate' => true,
],
'modifier' => [
'type' => Segment::class,
'options' => [
'route' => '/modifier/:categorie',
'defaults' => [
'controller' => ConfigurationController::class,
'action' => 'modifier-categorie',
],
],
'may_terminate' => true,
],
'detruire' => [
'type' => Segment::class,
'options' => [
'route' => '/detruire/:categorie',
'defaults' => [
'controller' => ConfigurationController::class,
'action' => 'detruire-categorie',
],
],
'may_terminate' => true,
],
'provider' => [
'type' => Segment::class,
'options' => [
'route' => '/provider/:categorie',
'defaults' => [
'controller' => ConfigurationController::class,
'action' => 'provider',
],
],
'may_terminate' => true,
],
],
],
'configuration-privilege' => [
'type' => Literal::class,
'options' => [
'route' => '/configuration-privilege',
'defaults' => [
'controller' => ConfigurationController::class,
],
],
'may_terminate' => false,
'child_routes' => [
'creer' => [
'type' => Segment::class,
'options' => [
'route' => '/creer/:categorie',
'defaults' => [
'controller' => ConfigurationController::class,
'action' => 'creer-privilege',
],
],
'may_terminate' => true,
],
'modifier' => [
'type' => Segment::class,
'options' => [
'route' => '/modifier/:privilege',
'defaults' => [
'controller' => ConfigurationController::class,
'action' => 'modifier-privilege',
],
],
'may_terminate' => true,
],
'detruire' => [
'type' => Segment::class,
'options' => [
'route' => '/detruire/:privilege',
'defaults' => [
'controller' => ConfigurationController::class,
'action' => 'detruire-privilege',
],
],
'may_terminate' => true,
],
],
],
],
],
'service_manager' => [
'factories' => [],
],
'controllers' => [
'factories' => [
ConfigurationController::class => ConfigurationControllerFactory::class,
],
],
'form_elements' => [
'factories' => [
CategoriePrivilegeForm::class => CategoriePrivilegeFormFactory::class,
PrivilegeForm::class => PrivilegeFormFactory::class,
],
],
'hydrators' => [
'factories' => [
CategoriePrivilegeHydrator::class => CategoriePrivilegeHydratorFactory::class,
PrivilegeHydrator::class => PrivilegeHydratorFactory::class,
],
]
];
\ No newline at end of file
<?php
use UnicaenPrivilege\Controller\PrivilegeController;
use UnicaenPrivilege\Controller\PrivilegeControllerFactory;
use UnicaenPrivilege\Provider\Privilege\PrivilegePrivileges;
use UnicaenPrivilege\Provider\Rule\PrivilegeRuleProvider;
use UnicaenPrivilege\Provider\Rule\PrivilegeRuleProviderFactory;
use UnicaenPrivilege\Service\Privilege\PrivilegeService;
use UnicaenPrivilege\Service\Privilege\PrivilegeServiceFactory;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
return [
'bjyauthorize' => [
'guards' => [
UnicaenPrivilege\Guard\PrivilegeController::class => [
[
'controller' => PrivilegeController::class,
'action' => [
'index',
],
'privileges' => [
PrivilegePrivileges::PRIVILEGE_VOIR,
],
],
[
'controller' => PrivilegeController::class,
'action' => [
'modifier',
],
'privileges' => [
PrivilegePrivileges::PRIVILEGE_AFFECTER,
],
],
],
],
],
'controllers' => [
'invokables' => [],
'factories' => [
PrivilegeController::class => PrivilegeControllerFactory::class,
],
],
'service_manager' => [
'factories' => [
PrivilegeService::class => PrivilegeServiceFactory::class,
PrivilegeRuleProvider::class => PrivilegeRuleProviderFactory::class, //ne sert pas ...
],
],
'router' => [
'routes' => [
'privilege' => [
'type' => Literal::class,
'options' => [
'route' => '/privilege',
'defaults' => [
'controller' => PrivilegeController::class,
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
],
],
'modifier-privilege' => [
'type' => Segment::class,
'options' => [
'route' => '/modifier-privilege/:role/:privilege',
'defaults' => [
'controller' => PrivilegeController::class,
'action' => 'modifier',
],
],
],
],
],
'navigation' => [
'default' => [
'home' => [
'pages' => [
'administration' => [
'pages' => [
'privilege' => [
'label' => 'Privilège',
'route' => 'privilege',
'resource' => \UnicaenPrivilege\Guard\PrivilegeController::getResourceId(PrivilegeController::class, 'index'),
'order' => 5000,
],
],
],
],
],
],
],
];
\ No newline at end of file
<?php
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
return [
'doctrine' => [
'driver' => [
'orm_default' => [
'class' => MappingDriverChain::class,
'drivers' => [
'UnicaenPrivilege\Entity\Db' => 'orm_default_xml_driver',
],
],
'orm_default_xml_driver' => [
'class' => XmlDriver::class,
'cache' => 'apc',
'paths' => [
__DIR__ . '/../src/UnicaenPrivilege/Entity/Db/Mapping',
],
],
],
'cache' => [
'apc' => [
'namespace' => 'UNICAEN__' . __NAMESPACE__,
],
],
],
'view_manager' => [
'template_path_stack' => [
__DIR__ . '/../view',
],
],
];
TODO ...
\ No newline at end of file
<?php
namespace UnicaenPrivilege\Controller;
use UnicaenPrivilege\Entity\Db\CategoriePrivilege;
use UnicaenPrivilege\Entity\Db\Privilege;
use UnicaenPrivilege\Form\CategoriePrivilege\CategoriePrivilegeFormAwareTrait;
use UnicaenPrivilege\Form\Privilege\PrivilegeFormAwareTrait;
use UnicaenPrivilege\Service\Privilege\PrivilegeServiceAwareTrait;
use Zend\Http\Request;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class ConfigurationController extends AbstractActionController {
use PrivilegeServiceAwareTrait;
use CategoriePrivilegeFormAwareTrait;
use PrivilegeFormAwareTrait;
public function indexConfigurationCategorieAction() {
/** @var CategoriePrivilege[] $categories */
$categories = $this->getPrivilegeService()->getCategories('ordre');
return new ViewModel([
'categories' => $categories,
]);
}
public function creerCategorieAction() {
$categorie = new CategoriePrivilege();
$form = $this->getCategoriePrivilegeForm();
$form->setAttribute('action', $this->url()->fromRoute('configuration-categorie/creer', [], [], true));
$form->bind($categorie);
/** @var Request $request */
$request = $this->getRequest();
if ($request->isPost()) {
$data = $request->getPost();
$form->setData($data);
if ($form->isValid()) {
$this->getPrivilegeService()->createCategorie($categorie);
}
}
$vm = new ViewModel();
$vm->setTemplate('unicaen-privilege/default/default-form');
$vm->setVariables([
'title' => "Ajout d'une nouvelle catégorie de privilège",
'form' => $form,
]);
return $vm;
}
public function gererCategorieAction() {
$categorie = $this->getPrivilegeService()->getRequestedCategorie($this);
return new ViewModel([
'categorie' => $categorie,
]);
}
public function modifierCategorieAction() {
$categorie = $this->getPrivilegeService()->getRequestedCategorie($this);
$form = $this->getCategoriePrivilegeForm();
$form->setAttribute('action', $this->url()->fromRoute('configuration-categorie/modifier', ['categorie' => $categorie->getId()], [], true));
$form->bind($categorie);
$form->setOldLibelle($categorie->getLibelle());
$form->setOldCode($categorie->getCode());
/** @var Request $request */
$request = $this->getRequest();
if ($request->isPost()) {
$data = $request->getPost();
$form->setData($data);
if ($form->isValid()) {
$this->getPrivilegeService()->updateCategorie($categorie);
}
}
$vm = new ViewModel();
$vm->setTemplate('unicaen-privilege/default/default-form');
$vm->setVariables([
'title' => "Modification d'une catégorie de privilège",
'form' => $form,
]);
return $vm;
}
public function detruireCategorieAction() {
$categorie = $this->getPrivilegeService()->getRequestedCategorie($this);
/** @var Request $request */
$request = $this->getRequest();
if ($request->isPost()) {
$data = $request->getPost();
if ($data["reponse"] === "oui") $this->getPrivilegeService()->deleteCategorie($categorie);
//return $this->redirect()->toRoute('configuration-categorie', [], [] , true);
exit();
}
$vm = new ViewModel();
if ($categorie !== null) {
$vm->setTemplate('unicaen-privilege/default/confirmation');
$vm->setVariables([
'title' => "Suppression de la Catégorie de privilège de " . $categorie->getLibelle(),
'text' => "La suppression est définitive êtes-vous sûr&middot;e de vouloir continuer ?",
'action' => $this->url()->fromRoute('configuration-categorie/detruire', ["categorie" => $categorie->getId()], [], true),
]);
}
return $vm;
}
public function creerPrivilegeAction()
{
$categorie = $this->getPrivilegeService()->getRequestedCategorie($this);
$privilege = new Privilege();
$form = $this->getPrivilegeForm();
$form->setAttribute('action', $this->url()->fromRoute('configuration-privilege/creer', ['categorie' => $categorie->getId()], [], true));
$form->bind($privilege);
/** @var Request $request */
$request = $this->getRequest();
if ($request->isPost()) {
$data = $request->getPost();
$form->setData($data);
if ($form->isValid()) {
$privilege->setCategorie($categorie);
$this->getPrivilegeService()->createPrivilege($privilege);
}
}
$vm = new ViewModel();
$vm->setTemplate('unicaen-privilege/default/default-form');
$vm->setVariables([
'title' => "Ajout d'un nouveau privilège",
'form' => $form,
]);
return $vm;
}