Skip to content
Snippets Groups Projects
Commit 5ee55b27 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Merge remote-tracking branch 'origin/BS5' into main

parents c821563b 16d58de9
No related branches found
No related tags found
No related merge requests found
Pipeline #19182 passed
Showing
with 167 additions and 198 deletions
.idea
\ No newline at end of file
......@@ -2,11 +2,11 @@
namespace UnicaenParametre;
use Zend\Config\Factory as ConfigFactory;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\Glob;
use Laminas\Config\Factory as ConfigFactory;
use Laminas\Mvc\ModuleRouteListener;
use Laminas\Mvc\MvcEvent;
use Laminas\Stdlib\ArrayUtils;
use Laminas\Stdlib\Glob;
class Module
{
......@@ -35,7 +35,7 @@ class Module
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'Laminas\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
......
{
"name": "unicaen/parametre",
"description": "Module de gestion de parametre",
"description": "Module de gestion de paramètres",
"repositories": [
{
"type": "composer",
......@@ -8,8 +8,7 @@
}
],
"require": {
"unicaen/app": "^3.0",
"unicaen/privilege": "dev-master"
"unicaen/privilege": "^5"
},
"autoload": {
"psr-0": {
......
......@@ -3,8 +3,8 @@
namespace UnicaenParametre;
use UnicaenPrivilege\Guard\PrivilegeController;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
use Laminas\Router\Http\Literal;
use Laminas\Router\Http\Segment;
return [
'bjyauthorize' => [
......
......@@ -12,8 +12,8 @@ use UnicaenParametre\Provider\Privilege\ParametrecategoriePrivileges;
use UnicaenParametre\Service\Categorie\CategorieService;
use UnicaenParametre\Service\Categorie\CategorieServiceFactory;
use UnicaenPrivilege\Guard\PrivilegeController;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
use Laminas\Router\Http\Literal;
use Laminas\Router\Http\Segment;
return [
'bjyauthorize' => [
......@@ -51,27 +51,7 @@ return [
],
],
'navigation' => [
'default' => [
'home' => [
'pages' => [
'administration' => [
'pages' => [
'parametre' => [
'label' => 'Paramètres',
'route' => 'parametre/index',
// 'resource' => PrivilegeController::getResourceId(CategorieController::class, 'index'),
'resource' => ParametrecategoriePrivileges::getResourceId(ParametrecategoriePrivileges::PARAMETRECATEGORIE_INDEX),
'order' => 7020,
'pages' => [],
'icon' => 'fas fa-angle-right',
],
],
],
],
],
],
],
'router' => [
'routes' => [
......
......@@ -10,8 +10,8 @@ use UnicaenParametre\Provider\Privilege\ParametrePrivileges;
use UnicaenParametre\Service\Parametre\ParametreService;
use UnicaenParametre\Service\Parametre\ParametreServiceFactory;
use UnicaenPrivilege\Guard\PrivilegeController;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
use Laminas\Router\Http\Literal;
use Laminas\Router\Http\Segment;
return [
'bjyauthorize' => [
......
<?php
namespace UnicaenParametre;
use UnicaenParametre\Provider\Privilege\ParametrecategoriePrivileges;
return [
'navigation' => [
'default' => [
'home' => [
'pages' => [
'administration' => [
'pages' => [
'parametre' => [
'label' => 'Paramètres',
'route' => 'parametre/index',
// 'resource' => PrivilegeController::getResourceId(CategorieController::class, 'index'),
'resource' => ParametrecategoriePrivileges::getResourceId(ParametrecategoriePrivileges::PARAMETRECATEGORIE_INDEX),
'order' => 7020,
'pages' => [],
'icon' => 'fas fa-angle-right',
],
],
],
],
],
],
],
];
\ No newline at end of file
UnicaenParametre
============
UnicaenParametre est une biltiothèque de gestion de catégories de paramètre et de paramètres.
UnicaenParametre est une bibliothèque de gestion de paramètres.
Les paramètres sont désignés par une catégorie et un code.
Route d'accès
-------------
- */parametre/index* donne accès aux paramètres de toutes les catégories
- */parametre/index/categorieId* donne accès aux paramètres de la catégorie *categorieId*
Le module fournit un menu d'administration permettant la déclaration des paramètres et de leur catégorie,
ainsi que l'affectation de leur valeur.
Récupération de la valeur d'un paramètre
----------------------------------------
```php
$this->getParametreService()->getParametreByCode('ma_categorie','mon_parametre')->getValeur();
$this->getParametreService()->getValeurForParametre('ma_categorie','mon_parametre');
```
**N.B.:** Il n'y a pas d'historisation des paramètres ou de leur catégorie. Est-ce bien nécessaire ?
Si le paramètre n'est pas trouvé alors une exception ```ParametreNotFoundException``` est lancée.
Si le paramètre n'est pas typé correctement alors une exception ```ParametreMalTypeException``` est lancée.
***TODO*** À propos du typage :
- Étendre le typage
- Modifier le formulaire pour exploiter les types "déclarés"
Bonnes pratiques
----------------
Afin de mieux référencer les catégories et les paramètres, il est recommandé de mettre en place un provider de parametres déclarant en constante : la catégorie et les paramètres.
```php
<?php
namespace Formation\Provider\Parametre;
class FormationParametres {
const CATEGORIE = 'FORMATION';
const NB_PLACE_PRINCIPALE = 'NB_PLACE_PRINCIPALE';
const NB_PLACE_COMPLEMENTAIRE = 'NB_PLACE_COMPLEMENTAIRE';
}
```
- - - - - - - - - - - - -
Installation
============
Dans le répertoire **doc** du module, on retrouve le fichier *database.sql* qui permet de construire la table associée au
module et d'ajouter les privilèges associés.
Le module s'attend à avoir un menu **Administration** pour mettre un menu secondaire **Paramètres**.
Pensez à l'ajouter s'il n'existe pas ou à modifier la naviguation dans *categorie.config.php*.
La navigation est fourni par le fichier ```unicaen-parametre.global.php(.dist)``` et doit être adaptée à votre application.
- - - - - - - - - - - - -
Historique
ChangeLog
==========
version 0.1.0 25/02/2021
------------------------
Version initiale du module.
**5.0.1**
- Ajout de la fonction de la valeur dans le service ParametreService
- Ajout de l'exception ```ParametreNotFoundException```
- Transformation des classes des entités *à la PHP8*
**5.0.0**
- Finalisation de la migration à BootStrap 5.
Améliorations possibles
-----------------------
......
......@@ -6,15 +6,15 @@ use UnicaenParametre\Entity\Db\Categorie;
use UnicaenParametre\Form\Categorie\CategorieFormAwareTrait;
use UnicaenParametre\Service\Categorie\CategorieServiceAwareTrait;
use UnicaenParametre\Service\Parametre\ParametreServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
class CategorieController extends AbstractActionController {
use CategorieServiceAwareTrait;
use ParametreServiceAwareTrait;
use CategorieFormAwareTrait;
public function indexAction()
public function indexAction() : ViewModel
{
$categories = $this->getCategorieService()->getCategories();
$parametres = $this->getParametreService()->getParametres();
......@@ -27,7 +27,8 @@ class CategorieController extends AbstractActionController {
]);
}
public function ajouterAction() {
public function ajouterAction() : ViewModel
{
$categorie = new Categorie();
$form = $this->getCategorieForm();
......@@ -51,7 +52,7 @@ class CategorieController extends AbstractActionController {
return $vm;
}
public function modifierAction()
public function modifierAction() : ViewModel
{
$categorie = $this->getCategorieService()->getRequestedCategorie($this);
$form = $this->getCategorieForm();
......@@ -76,7 +77,7 @@ class CategorieController extends AbstractActionController {
return $vm;
}
public function supprimerAction()
public function supprimerAction() : ViewModel
{
$categorie = $this->getCategorieService()->getRequestedCategorie($this);
......
......@@ -3,13 +3,21 @@
namespace UnicaenParametre\Controller;
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use UnicaenParametre\Form\Categorie\CategorieForm;
use UnicaenParametre\Service\Categorie\CategorieService;
use UnicaenParametre\Service\Parametre\ParametreService;
class CategorieControllerFactory {
public function __invoke(ContainerInterface $container)
/**
* @param ContainerInterface $container
* @return CategorieController
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container) : CategorieController
{
/**
* @var CategorieService $categorieService
......
......@@ -6,15 +6,15 @@ use UnicaenParametre\Entity\Db\Parametre;
use UnicaenParametre\Form\Parametre\ParametreFormAwareTrait;
use UnicaenParametre\Service\Categorie\CategorieServiceAwareTrait;
use UnicaenParametre\Service\Parametre\ParametreServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
class ParametreController extends AbstractActionController {
use CategorieServiceAwareTrait;
use ParametreServiceAwareTrait;
use ParametreFormAwareTrait;
public function ajouterAction()
public function ajouterAction() : ViewModel
{
$categorie = $this->getCategorieService()->getRequestedCategorie($this);
$parametre = new Parametre();
......@@ -41,7 +41,7 @@ class ParametreController extends AbstractActionController {
return $vm;
}
public function modifierAction()
public function modifierAction() : ViewModel
{
$parametre = $this->getParametreService()->getRequestedParametre($this);
$form = $this->getParametreForm();
......@@ -67,7 +67,7 @@ class ParametreController extends AbstractActionController {
return $vm;
}
public function supprimerAction()
public function supprimerAction() : ViewModel
{
$parametre = $this->getParametreService()->getRequestedParametre($this);
......@@ -90,7 +90,7 @@ class ParametreController extends AbstractActionController {
return $vm;
}
public function modifierValeurAction()
public function modifierValeurAction() : ViewModel
{
$parametre = $this->getParametreService()->getRequestedParametre($this);
......
......@@ -3,6 +3,8 @@
namespace UnicaenParametre\Controller;
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use UnicaenParametre\Form\Parametre\ParametreForm;
use UnicaenParametre\Service\Categorie\CategorieService;
use UnicaenParametre\Service\Parametre\ParametreService;
......@@ -12,8 +14,10 @@ class ParametreControllerFactory {
/**
* @param ContainerInterface $container
* @return ParametreController
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container) : ParametreController
{
/**
* @var CategorieService $categorieService
......
......@@ -6,91 +6,55 @@ class Categorie
{
const DEFAULT_ORDER = 9999;
/** @var integer */
private $id;
/** @var string */
private $code;
/** @var string */
private $libelle;
/** @var string */
private $description;
/** @var integer */
private $ordre;
private ?int $id = null;
private ?string $code = null;
private ?string $libelle = null;
private ?string $description = null;
private ?int $ordre = null;
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return string|null
*/
public function getCode(): ?string
{
return $this->code;
}
/**
* @param string|null $code
* @return Categorie
*/
public function setCode(?string $code): Categorie
{
$this->code = $code;
return $this;
}
/**
* @return string|null
*/
public function getLibelle(): ?string
{
return $this->libelle;
}
/**
* @param string|null $libelle
* @return Categorie
*/
public function setLibelle(?string $libelle): Categorie
{
$this->libelle = $libelle;
return $this;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @param string|null $description
* @return Categorie
*/
public function setDescription(?string $description): Categorie
{
$this->description = $description;
return $this;
}
/**
* @return int|null
*/
public function getOrdre(): ?int
{
return $this->ordre;
}
/**
* @param int $ordre
* @return Categorie
*/
public function setOrdre(int $ordre = Categorie::DEFAULT_ORDER): Categorie
{
$this->ordre = $ordre;
......
......@@ -6,151 +6,95 @@ class Parametre
{
const DEFAULT_ORDER = 9999;
/** @var integer */
private $id;
/** @var Categorie */
private $categorie;
/** @var string */
private $code;
/** @var string */
private $libelle;
/** @var string */
private $description;
/** @var string */
private $valeur;
/** @var string */
private $valeurs_possibles;
/** @var integer */
private $ordre;
/**
* @return int
*/
const TYPE_STRING = "String";
const TYPE_BOOLEAN = "Boolean";
const TYPE_NUMBER = "Number";
private ?int $id = null;
private ?Categorie $categorie = null;
private ?string $code = null;
private ?string $libelle = null;
private ?string $description = null;
private ?string $valeur = null;
private ?string $valeurs_possibles = null;
private ?int $ordre = null;
public function getId(): int
{
return $this->id;
}
/**
* @return Categorie|null
*/
public function getCategorie(): ?Categorie
{
return $this->categorie;
}
/**
* @param Categorie|null $categorie
* @return Parametre
*/
public function setCategorie(?Categorie $categorie): Parametre
{
$this->categorie = $categorie;
return $this;
}
/**
* @return string|null
*/
public function getCode(): ?string
{
return $this->code;
}
/**
* @param string|null $code
* @return Parametre
*/
public function setCode(?string $code): Parametre
{
$this->code = $code;
return $this;
}
/**
* @return string|null
*/
public function getLibelle(): ?string
{
return $this->libelle;
}
/**
* @param string|null $libelle
* @return Parametre
*/
public function setLibelle(?string $libelle): Parametre
{
$this->libelle = $libelle;
return $this;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @param string|null $description
* @return Parametre
*/
public function setDescription(?string $description): Parametre
{
$this->description = $description;
return $this;
}
/**
* @return string|null
*/
public function getValeur(): ?string
{
return $this->valeur;
}
/**
* @param string|null $valeur
* @return Parametre
*/
public function setValeur(?string $valeur): Parametre
{
$this->valeur = $valeur;
return $this;
}
/**
* @return string|null
*/
public function getValeursPossibles(): ?string
{
return $this->valeurs_possibles;
}
/**
* @param string|null $valeurs_possibles
* @return Parametre
*/
public function setValeursPossibles(?string $valeurs_possibles): Parametre
{
$this->valeurs_possibles = $valeurs_possibles;
return $this;
}
/**
* @return int|null
*/
public function getOrdre(): ?int
{
return $this->ordre;
}
/**
* @param int $ordre
* @return Parametre
*/
public function setOrdre(int $ordre = Parametre::DEFAULT_ORDER): Parametre
{
$this->ordre = $ordre;
......
<?php
namespace parametre\src\UnicaenParametre\Exception;
use Exception;
class ParametreMalTypeException extends Exception {}
\ No newline at end of file
<?php
namespace UnicaenParametre\Exception;
use Exception;
class ParametreNotFoundException extends Exception {}
\ No newline at end of file
......@@ -3,14 +3,14 @@
namespace UnicaenParametre\Form\Categorie;
use UnicaenParametre\Service\Categorie\CategorieServiceAwareTrait;
use Zend\Form\Element\Button;
use Zend\Form\Element\Hidden;
use Zend\Form\Element\Number;
use Zend\Form\Element\Text;
use Zend\Form\Element\Textarea;
use Zend\Form\Form;
use Zend\InputFilter\Factory;
use Zend\Validator\Callback;
use Laminas\Form\Element\Button;
use Laminas\Form\Element\Hidden;
use Laminas\Form\Element\Number;
use Laminas\Form\Element\Text;
use Laminas\Form\Element\Textarea;
use Laminas\Form\Form;
use Laminas\InputFilter\Factory;
use Laminas\Validator\Callback;
class CategorieForm extends Form {
use CategorieServiceAwareTrait;
......@@ -91,7 +91,7 @@ class CategorieForm extends Form {
],
'attributes' => [
'type' => 'submit',
'class' => 'btn btn-default',
'class' => 'btn btn-primary',
],
]);
//input filter
......
......@@ -4,24 +4,15 @@ namespace UnicaenParametre\Form\Categorie;
trait CategorieFormAwareTrait {
/** @var CategorieForm */
private $categorieForm;
private CategorieForm $categorieForm;
/**
* @return CategorieForm
*/
public function getCategorieForm(): CategorieForm
{
return $this->categorieForm;
}
/**
* @param CategorieForm $categorieForm
* @return CategorieForm
*/
public function setCategorieForm(CategorieForm $categorieForm): CategorieForm
public function setCategorieForm(CategorieForm $categorieForm): void
{
$this->categorieForm = $categorieForm;
return $this->categorieForm;
}
}
\ No newline at end of file
......@@ -3,6 +3,8 @@
namespace UnicaenParametre\Form\Categorie;
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use UnicaenParametre\Service\Categorie\CategorieService;
class CategorieFormFactory {
......@@ -10,8 +12,10 @@ class CategorieFormFactory {
/**
* @param ContainerInterface $container
* @return CategorieForm
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container) : CategorieForm
{
/**
* @var CategorieService $categorieService
......
......@@ -3,7 +3,7 @@
namespace UnicaenParametre\Form\Categorie;
use UnicaenParametre\Entity\Db\Categorie;
use Zend\Hydrator\HydratorInterface;
use Laminas\Hydrator\HydratorInterface;
class CategorieHydrator implements HydratorInterface {
......@@ -11,7 +11,7 @@ class CategorieHydrator implements HydratorInterface {
* @param Categorie $object
* @return array|void
*/
public function extract($object)
public function extract(object $object) : array
{
$data = [
'code' => $object->getCode(),
......@@ -27,7 +27,7 @@ class CategorieHydrator implements HydratorInterface {
* @param Categorie $object
* @return Categorie
*/
public function hydrate(array $data, $object)
public function hydrate(array $data, $object) : object
{
$code = (isset($data['code']) and trim($data['code']) !== '')?trim($data['code']):null;
$libelle = (isset($data['libelle']) and trim($data['libelle']) !== '')?trim($data['libelle']):null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment