From efbd0cff2b66fec009f75722c688dc3e5a646f6c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Metivier <jean-philippe.metivier@unicaen.fr> Date: Tue, 31 Jan 2023 16:06:54 +0100 Subject: [PATCH] =?UTF-8?q?Retrait=20de=20d=C3=A9pendance=20=C3=A0=20Unica?= =?UTF-8?q?eApp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 - config/merged/categorie.config.php | 22 +------ config/unicaen-parametre.global.php.dist | 41 +++++++++++++ .../Form/Categorie/CategorieForm.php | 2 +- .../Form/Parametre/ParametreForm.php | 2 +- .../Service/Categorie/CategorieService.php | 60 +++++++++---------- .../Categorie/CategorieServiceAwareTrait.php | 13 +--- .../Categorie/CategorieServiceFactory.php | 11 +++- .../Service/Parametre/ParametreService.php | 52 ++++++++-------- .../Parametre/ParametreServiceAwareTrait.php | 13 +--- .../Parametre/ParametreServiceFactory.php | 8 ++- view/unicaen-parametre/categorie/index.phtml | 6 +- 12 files changed, 119 insertions(+), 112 deletions(-) create mode 100644 config/unicaen-parametre.global.php.dist diff --git a/composer.json b/composer.json index 8e157ae47..720c187eb 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,6 @@ } ], "require": { - "unicaen/app": "^5", "unicaen/privilege": "^5" }, "autoload": { diff --git a/config/merged/categorie.config.php b/config/merged/categorie.config.php index 002cdbd6f..8d917c129 100644 --- a/config/merged/categorie.config.php +++ b/config/merged/categorie.config.php @@ -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' => [ diff --git a/config/unicaen-parametre.global.php.dist b/config/unicaen-parametre.global.php.dist new file mode 100644 index 000000000..b3edde01e --- /dev/null +++ b/config/unicaen-parametre.global.php.dist @@ -0,0 +1,41 @@ +<?php + +namespace UnicaenParametre; + +use UnicaenParametre\Controller\CategorieController; +use UnicaenParametre\Controller\CategorieControllerFactory; +use UnicaenParametre\Form\Categorie\CategorieForm; +use UnicaenParametre\Form\Categorie\CategorieFormFactory; +use UnicaenParametre\Form\Categorie\CategorieHydrator; +use UnicaenParametre\Form\Categorie\CategorieHydratorFactory; +use UnicaenParametre\Provider\Privilege\ParametrecategoriePrivileges; +use UnicaenParametre\Service\Categorie\CategorieService; +use UnicaenParametre\Service\Categorie\CategorieServiceFactory; +use UnicaenPrivilege\Guard\PrivilegeController; +use Laminas\Router\Http\Literal; +use Laminas\Router\Http\Segment; + +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 diff --git a/src/UnicaenParametre/Form/Categorie/CategorieForm.php b/src/UnicaenParametre/Form/Categorie/CategorieForm.php index 7c71a7a0d..bcffc3b49 100644 --- a/src/UnicaenParametre/Form/Categorie/CategorieForm.php +++ b/src/UnicaenParametre/Form/Categorie/CategorieForm.php @@ -91,7 +91,7 @@ class CategorieForm extends Form { ], 'attributes' => [ 'type' => 'submit', - 'class' => 'btn btn-default', + 'class' => 'btn btn-primary', ], ]); //input filter diff --git a/src/UnicaenParametre/Form/Parametre/ParametreForm.php b/src/UnicaenParametre/Form/Parametre/ParametreForm.php index 1d453ce7b..f8a4d233a 100644 --- a/src/UnicaenParametre/Form/Parametre/ParametreForm.php +++ b/src/UnicaenParametre/Form/Parametre/ParametreForm.php @@ -109,7 +109,7 @@ class ParametreForm extends Form { ], 'attributes' => [ 'type' => 'submit', - 'class' => 'btn btn-default', + 'class' => 'btn btn-primary', ], ]); //input filter diff --git a/src/UnicaenParametre/Service/Categorie/CategorieService.php b/src/UnicaenParametre/Service/Categorie/CategorieService.php index d96513c1a..381468a97 100644 --- a/src/UnicaenParametre/Service/Categorie/CategorieService.php +++ b/src/UnicaenParametre/Service/Categorie/CategorieService.php @@ -5,13 +5,14 @@ namespace UnicaenParametre\Service\Categorie; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\ORMException; use Doctrine\ORM\QueryBuilder; -use UnicaenApp\Exception\RuntimeException; -use UnicaenApp\Service\EntityManagerAwareTrait; -use UnicaenParametre\Entity\Db\Categorie; +use DoctrineModule\Persistence\ProvidesObjectManager; use Laminas\Mvc\Controller\AbstractActionController; +use RuntimeException; +use UnicaenParametre\Entity\Db\Categorie; -class CategorieService { - use EntityManagerAwareTrait; +class CategorieService +{ + use ProvidesObjectManager; /** GESTION ENTITY ************************************************************************************************/ @@ -19,13 +20,13 @@ class CategorieService { * @param Categorie $categorie * @return Categorie */ - public function create(Categorie $categorie) : Categorie + public function create(Categorie $categorie): Categorie { try { - $this->getEntityManager()->persist($categorie); - $this->getEntityManager()->flush($categorie); + $this->getObjectManager()->persist($categorie); + $this->getObjectManager()->flush($categorie); } catch (ORMException $e) { - throw new RuntimeException("Une erreur s'est produite lors de l'enregistrement en base.",0,$e); + throw new RuntimeException("Une erreur s'est produite lors de l'enregistrement en base.", 0, $e); } return $categorie; } @@ -34,12 +35,12 @@ class CategorieService { * @param Categorie $categorie * @return Categorie */ - public function update(Categorie $categorie) : Categorie + public function update(Categorie $categorie): Categorie { try { - $this->getEntityManager()->flush($categorie); + $this->getObjectManager()->flush($categorie); } catch (ORMException $e) { - throw new RuntimeException("Une erreur s'est produite lors de la mise à jour en base.",0,$e); + throw new RuntimeException("Une erreur s'est produite lors de la mise à jour en base.", 0, $e); } return $categorie; } @@ -48,13 +49,13 @@ class CategorieService { * @param Categorie $categorie * @return Categorie */ - public function delete(Categorie $categorie) : Categorie + public function delete(Categorie $categorie): Categorie { try { - $this->getEntityManager()->remove($categorie); - $this->getEntityManager()->flush($categorie); + $this->getObjectManager()->remove($categorie); + $this->getObjectManager()->flush($categorie); } catch (ORMException $e) { - throw new RuntimeException("Une erreur s'est produite lors de la suppression en base.",0,$e); + throw new RuntimeException("Une erreur s'est produite lors de la suppression en base.", 0, $e); } return $categorie; } @@ -64,17 +65,18 @@ class CategorieService { /** * @return QueryBuilder */ - public function createQueryBuilder() : QueryBuilder + public function createQueryBuilder(): QueryBuilder { - $qb = $this->getEntityManager()->getRepository(Categorie::class)->createQueryBuilder('categorie'); + $qb = $this->getObjectManager()->getRepository(Categorie::class)->createQueryBuilder('categorie'); return $qb; } + /** * @param string $champ * @param string $ordre * @return Categorie[] */ - public function getCategories(string $champ="ordre", string $ordre="ASC") : array + public function getCategories(string $champ = "ordre", string $ordre = "ASC"): array { $qb = $this->createQueryBuilder() ->orderBy('categorie.' . $champ, $ordre); @@ -88,9 +90,9 @@ class CategorieService { * @param string $ordre * @return array */ - public function getCategoriesAsOptions(string $champ="ordre", string $ordre="ASC") : array + public function getCategoriesAsOptions(string $champ = "ordre", string $ordre = "ASC"): array { - $categories = $this->getCategories($champ,$ordre); + $categories = $this->getCategories($champ, $ordre); $array = []; foreach ($categories as $categorie) { $array[$categorie->getId()] = $categorie->getLibelle(); @@ -102,16 +104,15 @@ class CategorieService { * @param int|null $id * @return Categorie|null */ - public function getCategorie(?int $id) : ?Categorie + public function getCategorie(?int $id): ?Categorie { $qb = $this->createQueryBuilder() ->andWhere('categorie.id = :id') - ->setParameter('id', $id) - ; + ->setParameter('id', $id); try { $result = $qb->getQuery()->getOneOrNullResult(); } catch (NonUniqueResultException $e) { - throw new RuntimeException("Plusieurs ParamatreCategorie partagent le même id [".$id."]",0,$e); + throw new RuntimeException("Plusieurs ParamatreCategorie partagent le même id [" . $id . "]", 0, $e); } return $result; } @@ -120,16 +121,15 @@ class CategorieService { * @param string $code * @return Categorie|null */ - public function getCategoriebyCode(string $code) : ?Categorie + public function getCategoriebyCode(string $code): ?Categorie { $qb = $this->createQueryBuilder() ->andWhere('categorie.code = :code') - ->setParameter('code', $code) - ; + ->setParameter('code', $code); try { $result = $qb->getQuery()->getOneOrNullResult(); } catch (NonUniqueResultException $e) { - throw new RuntimeException("Plusieurs ParamatreCategorie partagent le même code [".$code."]",0,$e); + throw new RuntimeException("Plusieurs ParamatreCategorie partagent le même code [" . $code . "]", 0, $e); } return $result; } @@ -139,7 +139,7 @@ class CategorieService { * @param string $param * @return Categorie|null */ - public function getRequestedCategorie(AbstractActionController $controller, string $param='categorie') : ?Categorie + public function getRequestedCategorie(AbstractActionController $controller, string $param = 'categorie'): ?Categorie { $id = $controller->params()->fromRoute($param); $result = $this->getCategorie($id); diff --git a/src/UnicaenParametre/Service/Categorie/CategorieServiceAwareTrait.php b/src/UnicaenParametre/Service/Categorie/CategorieServiceAwareTrait.php index 93ecb4d47..67d07a604 100644 --- a/src/UnicaenParametre/Service/Categorie/CategorieServiceAwareTrait.php +++ b/src/UnicaenParametre/Service/Categorie/CategorieServiceAwareTrait.php @@ -4,25 +4,16 @@ namespace UnicaenParametre\Service\Categorie; trait CategorieServiceAwareTrait { - /** @var CategorieService */ - private $parametreCategorieService; + private CategorieService $parametreCategorieService; - /** - * @return CategorieService - */ public function getCategorieService(): CategorieService { return $this->parametreCategorieService; } - /** - * @param CategorieService $parametreCategorieService - * @return CategorieService - */ - public function setCategorieService(CategorieService $parametreCategorieService): CategorieService + public function setCategorieService(CategorieService $parametreCategorieService): void { $this->parametreCategorieService = $parametreCategorieService; - return $this->parametreCategorieService; } } \ No newline at end of file diff --git a/src/UnicaenParametre/Service/Categorie/CategorieServiceFactory.php b/src/UnicaenParametre/Service/Categorie/CategorieServiceFactory.php index f8b96d4a7..a105c7e44 100644 --- a/src/UnicaenParametre/Service/Categorie/CategorieServiceFactory.php +++ b/src/UnicaenParametre/Service/Categorie/CategorieServiceFactory.php @@ -4,14 +4,19 @@ namespace UnicaenParametre\Service\Categorie; use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; -class CategorieServiceFactory { +class CategorieServiceFactory +{ /** * @param ContainerInterface $container * @return CategorieService + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): CategorieService { /** * @var EntityManager $entityManager @@ -19,7 +24,7 @@ class CategorieServiceFactory { $entityManager = $container->get('doctrine.entitymanager.orm_default'); $service = new CategorieService(); - $service->setEntityManager($entityManager); + $service->setObjectManager($entityManager); return $service; } diff --git a/src/UnicaenParametre/Service/Parametre/ParametreService.php b/src/UnicaenParametre/Service/Parametre/ParametreService.php index f5f00fb74..3abf22096 100644 --- a/src/UnicaenParametre/Service/Parametre/ParametreService.php +++ b/src/UnicaenParametre/Service/Parametre/ParametreService.php @@ -5,15 +5,15 @@ namespace UnicaenParametre\Service\Parametre; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\ORMException; use Doctrine\ORM\QueryBuilder; -use UnicaenApp\Exception\RuntimeException; -use UnicaenApp\Service\EntityManagerAwareTrait; +use DoctrineModule\Persistence\ProvidesObjectManager; +use RuntimeException; use UnicaenParametre\Entity\Db\Categorie; use UnicaenParametre\Entity\Db\Parametre; use Laminas\Mvc\Controller\AbstractActionController; class ParametreService { - use EntityManagerAwareTrait; + use ProvidesObjectManager; /** GESTION ENTITY ************************************************************************************************/ @@ -21,13 +21,13 @@ class ParametreService * @param Parametre $parametre * @return Parametre */ - public function create(Parametre $parametre) : Parametre + public function create(Parametre $parametre): Parametre { try { - $this->getEntityManager()->persist($parametre); - $this->getEntityManager()->flush($parametre); + $this->getObjectManager()->persist($parametre); + $this->getObjectManager()->flush($parametre); } catch (ORMException $e) { - throw new RuntimeException("Une erreur s'est produite lors de l'enregistrement en base.",0,$e); + throw new RuntimeException("Une erreur s'est produite lors de l'enregistrement en base.", 0, $e); } return $parametre; } @@ -36,12 +36,12 @@ class ParametreService * @param Parametre $parametre * @return Parametre */ - public function update(Parametre $parametre) : Parametre + public function update(Parametre $parametre): Parametre { try { - $this->getEntityManager()->flush($parametre); + $this->getObjectManager()->flush($parametre); } catch (ORMException $e) { - throw new RuntimeException("Une erreur s'est produite lors de la mise à jour en base.",0,$e); + throw new RuntimeException("Une erreur s'est produite lors de la mise à jour en base.", 0, $e); } return $parametre; } @@ -50,13 +50,13 @@ class ParametreService * @param Parametre $parametre * @return Parametre */ - public function delete(Parametre $parametre) : Parametre + public function delete(Parametre $parametre): Parametre { try { - $this->getEntityManager()->remove($parametre); - $this->getEntityManager()->flush($parametre); + $this->getObjectManager()->remove($parametre); + $this->getObjectManager()->flush($parametre); } catch (ORMException $e) { - throw new RuntimeException("Une erreur s'est produite lors de la suppression en base.",0,$e); + throw new RuntimeException("Une erreur s'est produite lors de la suppression en base.", 0, $e); } return $parametre; } @@ -66,9 +66,9 @@ class ParametreService /** * @return QueryBuilder */ - public function createQueryBuilder() : QueryBuilder + public function createQueryBuilder(): QueryBuilder { - $qb = $this->getEntityManager()->getRepository(Parametre::class)->createQueryBuilder('parametre') + $qb = $this->getObjectManager()->getRepository(Parametre::class)->createQueryBuilder('parametre') ->addSelect('categorie')->join('parametre.categorie', 'categorie'); return $qb; } @@ -78,7 +78,7 @@ class ParametreService * @param string $ordre * @return Parametre[] */ - public function getParametres(string $champ = 'ordre', string $ordre = 'ASC') : array + public function getParametres(string $champ = 'ordre', string $ordre = 'ASC'): array { $qb = $this->createQueryBuilder() ->orderBy('parametre.' . $champ, $ordre); @@ -92,7 +92,7 @@ class ParametreService * @param string $ordre * @return Parametre[] */ - public function getParametresByCategorie(Categorie $categorie, string $champ = 'ordre', string $ordre = 'ASC') : array + public function getParametresByCategorie(Categorie $categorie, string $champ = 'ordre', string $ordre = 'ASC'): array { $qb = $this->createQueryBuilder() ->andWhere('parametre.categorie = :categorie') @@ -106,16 +106,15 @@ class ParametreService * @param int $id * @return Parametre|null */ - public function getParametre(int $id) : ?Parametre + public function getParametre(int $id): ?Parametre { $qb = $this->createQueryBuilder() ->andWhere('parametre.id = :id') - ->setParameter('id', $id) - ; + ->setParameter('id', $id); try { $result = $qb->getQuery()->getOneOrNullResult(); } catch (NonUniqueResultException $e) { - throw new RuntimeException("Plusieurs Parametre partagent le même id [".$id."]",0,$e); + throw new RuntimeException("Plusieurs Parametre partagent le même id [" . $id . "]", 0, $e); } return $result; } @@ -125,19 +124,18 @@ class ParametreService * @param string $parametreCode * @return Parametre|null */ - public function getParametreByCode(string $categorieCode, string $parametreCode ) : ?Parametre + public function getParametreByCode(string $categorieCode, string $parametreCode): ?Parametre { $qb = $this->createQueryBuilder() ->andWhere('categorie.code = :categorieCode') ->andWhere('parametre.code = :parametreCode') ->setParameter('categorieCode', $categorieCode) - ->setParameter('parametreCode', $parametreCode) - ; + ->setParameter('parametreCode', $parametreCode); try { $result = $qb->getQuery()->getOneOrNullResult(); } catch (NonUniqueResultException $e) { - throw new RuntimeException("Plusieurs Parametre partagent le même code [".$categorieCode ." - ".$parametreCode."]",0,$e); + throw new RuntimeException("Plusieurs Parametre partagent le même code [" . $categorieCode . " - " . $parametreCode . "]", 0, $e); } return $result; } @@ -151,7 +149,7 @@ class ParametreService { $id = $controller->params()->fromRoute($param); /** @var Parametre $parametre */ - $parametre = $this->getParametre($id); + $parametre = $this->getParametre($id); return $parametre; } diff --git a/src/UnicaenParametre/Service/Parametre/ParametreServiceAwareTrait.php b/src/UnicaenParametre/Service/Parametre/ParametreServiceAwareTrait.php index 327e4c7e2..695f20d90 100644 --- a/src/UnicaenParametre/Service/Parametre/ParametreServiceAwareTrait.php +++ b/src/UnicaenParametre/Service/Parametre/ParametreServiceAwareTrait.php @@ -5,22 +5,13 @@ namespace UnicaenParametre\Service\Parametre; trait ParametreServiceAwareTrait { - /** @var ParametreService */ - protected $parametreService; + protected ParametreService $parametreService; - /** - * @param ParametreService $parametreService - * @return ParametreService - */ - public function setParametreService(ParametreService $parametreService) : ParametreService + public function setParametreService(ParametreService $parametreService) : void { $this->parametreService = $parametreService; - return $this->parametreService; } - /** - * @return ParametreService - */ public function getParametreService() : ParametreService { return $this->parametreService; diff --git a/src/UnicaenParametre/Service/Parametre/ParametreServiceFactory.php b/src/UnicaenParametre/Service/Parametre/ParametreServiceFactory.php index 1bee2aa06..6f1efb4e2 100644 --- a/src/UnicaenParametre/Service/Parametre/ParametreServiceFactory.php +++ b/src/UnicaenParametre/Service/Parametre/ParametreServiceFactory.php @@ -4,6 +4,8 @@ namespace UnicaenParametre\Service\Parametre; use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; class ParametreServiceFactory { @@ -11,8 +13,10 @@ class ParametreServiceFactory /** * @param ContainerInterface $container * @return ParametreService + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container) : ParametreService { /** * @var EntityManager $entityManager @@ -20,7 +24,7 @@ class ParametreServiceFactory $entityManager = $container->get('doctrine.entitymanager.orm_default'); $service = new ParametreService(); - $service->setEntityManager($entityManager); + $service->setObjectManager($entityManager); return $service; } } \ No newline at end of file diff --git a/view/unicaen-parametre/categorie/index.phtml b/view/unicaen-parametre/categorie/index.phtml index 1e64b3346..1cf9ad3fa 100644 --- a/view/unicaen-parametre/categorie/index.phtml +++ b/view/unicaen-parametre/categorie/index.phtml @@ -42,12 +42,11 @@ if ($selection !== null) $categories = [ $selection ]; <?php foreach ($categories as $categorie) : ?> <?php $id = $categorie->getId(); ?> - <div class="row"> <h2 title="<?php echo $categorie->getDescription(); ?>" data-bs-toggle="tooltip" data-bs-html="true" style="cursor: help;"> Catégorie : <?php echo $categorie->getLibelle(); ?> </h2> - <br/> + <a <?php /** @see \Application\Controller\ParametreController::ajouterAction() */?> href="<?php echo $this->url('parametre/ajouter', ['categorie' => $categorie->getId()], [], true); ?>" - class="btn btn-primary action ajax-modal" data-event="modification"> + class="btn btn-primary ajax-modal" data-event="modification"> <i class="fas fa-plus"></i> Ajouter un paramètre </a> <?php if ($selection === null) : ?> @@ -70,7 +69,6 @@ if ($selection !== null) $categories = [ $selection ]; </span> <?php endif; ?> <?php endif; ?> - </div> <br/> -- GitLab