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

Retrait de dépendance à UnicaeApp

parent 7dfa2430
Branches
Tags
No related merge requests found
Pipeline #18060 passed
Showing
with 119 additions and 112 deletions
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
} }
], ],
"require": { "require": {
"unicaen/app": "^5",
"unicaen/privilege": "^5" "unicaen/privilege": "^5"
}, },
"autoload": { "autoload": {
......
...@@ -51,27 +51,7 @@ return [ ...@@ -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' => [ 'router' => [
'routes' => [ 'routes' => [
......
<?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
...@@ -91,7 +91,7 @@ class CategorieForm extends Form { ...@@ -91,7 +91,7 @@ class CategorieForm extends Form {
], ],
'attributes' => [ 'attributes' => [
'type' => 'submit', 'type' => 'submit',
'class' => 'btn btn-default', 'class' => 'btn btn-primary',
], ],
]); ]);
//input filter //input filter
......
...@@ -109,7 +109,7 @@ class ParametreForm extends Form { ...@@ -109,7 +109,7 @@ class ParametreForm extends Form {
], ],
'attributes' => [ 'attributes' => [
'type' => 'submit', 'type' => 'submit',
'class' => 'btn btn-default', 'class' => 'btn btn-primary',
], ],
]); ]);
//input filter //input filter
......
...@@ -5,13 +5,14 @@ namespace UnicaenParametre\Service\Categorie; ...@@ -5,13 +5,14 @@ namespace UnicaenParametre\Service\Categorie;
use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\ORMException; use Doctrine\ORM\ORMException;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use UnicaenApp\Exception\RuntimeException; use DoctrineModule\Persistence\ProvidesObjectManager;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenParametre\Entity\Db\Categorie;
use Laminas\Mvc\Controller\AbstractActionController; use Laminas\Mvc\Controller\AbstractActionController;
use RuntimeException;
use UnicaenParametre\Entity\Db\Categorie;
class CategorieService { class CategorieService
use EntityManagerAwareTrait; {
use ProvidesObjectManager;
/** GESTION ENTITY ************************************************************************************************/ /** GESTION ENTITY ************************************************************************************************/
...@@ -22,8 +23,8 @@ class CategorieService { ...@@ -22,8 +23,8 @@ class CategorieService {
public function create(Categorie $categorie): Categorie public function create(Categorie $categorie): Categorie
{ {
try { try {
$this->getEntityManager()->persist($categorie); $this->getObjectManager()->persist($categorie);
$this->getEntityManager()->flush($categorie); $this->getObjectManager()->flush($categorie);
} catch (ORMException $e) { } 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);
} }
...@@ -37,7 +38,7 @@ class CategorieService { ...@@ -37,7 +38,7 @@ class CategorieService {
public function update(Categorie $categorie): Categorie public function update(Categorie $categorie): Categorie
{ {
try { try {
$this->getEntityManager()->flush($categorie); $this->getObjectManager()->flush($categorie);
} catch (ORMException $e) { } 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);
} }
...@@ -51,8 +52,8 @@ class CategorieService { ...@@ -51,8 +52,8 @@ class CategorieService {
public function delete(Categorie $categorie): Categorie public function delete(Categorie $categorie): Categorie
{ {
try { try {
$this->getEntityManager()->remove($categorie); $this->getObjectManager()->remove($categorie);
$this->getEntityManager()->flush($categorie); $this->getObjectManager()->flush($categorie);
} catch (ORMException $e) { } 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);
} }
...@@ -66,9 +67,10 @@ class CategorieService { ...@@ -66,9 +67,10 @@ class CategorieService {
*/ */
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; return $qb;
} }
/** /**
* @param string $champ * @param string $champ
* @param string $ordre * @param string $ordre
...@@ -106,8 +108,7 @@ class CategorieService { ...@@ -106,8 +108,7 @@ class CategorieService {
{ {
$qb = $this->createQueryBuilder() $qb = $this->createQueryBuilder()
->andWhere('categorie.id = :id') ->andWhere('categorie.id = :id')
->setParameter('id', $id) ->setParameter('id', $id);
;
try { try {
$result = $qb->getQuery()->getOneOrNullResult(); $result = $qb->getQuery()->getOneOrNullResult();
} catch (NonUniqueResultException $e) { } catch (NonUniqueResultException $e) {
...@@ -124,8 +125,7 @@ class CategorieService { ...@@ -124,8 +125,7 @@ class CategorieService {
{ {
$qb = $this->createQueryBuilder() $qb = $this->createQueryBuilder()
->andWhere('categorie.code = :code') ->andWhere('categorie.code = :code')
->setParameter('code', $code) ->setParameter('code', $code);
;
try { try {
$result = $qb->getQuery()->getOneOrNullResult(); $result = $qb->getQuery()->getOneOrNullResult();
} catch (NonUniqueResultException $e) { } catch (NonUniqueResultException $e) {
......
...@@ -4,25 +4,16 @@ namespace UnicaenParametre\Service\Categorie; ...@@ -4,25 +4,16 @@ namespace UnicaenParametre\Service\Categorie;
trait CategorieServiceAwareTrait { trait CategorieServiceAwareTrait {
/** @var CategorieService */ private CategorieService $parametreCategorieService;
private $parametreCategorieService;
/**
* @return CategorieService
*/
public function getCategorieService(): CategorieService public function getCategorieService(): CategorieService
{ {
return $this->parametreCategorieService; return $this->parametreCategorieService;
} }
/** public function setCategorieService(CategorieService $parametreCategorieService): void
* @param CategorieService $parametreCategorieService
* @return CategorieService
*/
public function setCategorieService(CategorieService $parametreCategorieService): CategorieService
{ {
$this->parametreCategorieService = $parametreCategorieService; $this->parametreCategorieService = $parametreCategorieService;
return $this->parametreCategorieService;
} }
} }
\ No newline at end of file
...@@ -4,14 +4,19 @@ namespace UnicaenParametre\Service\Categorie; ...@@ -4,14 +4,19 @@ namespace UnicaenParametre\Service\Categorie;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Interop\Container\ContainerInterface; use Interop\Container\ContainerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class CategorieServiceFactory { class CategorieServiceFactory
{
/** /**
* @param ContainerInterface $container * @param ContainerInterface $container
* @return CategorieService * @return CategorieService
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function __invoke(ContainerInterface $container) public function __invoke(ContainerInterface $container): CategorieService
{ {
/** /**
* @var EntityManager $entityManager * @var EntityManager $entityManager
...@@ -19,7 +24,7 @@ class CategorieServiceFactory { ...@@ -19,7 +24,7 @@ class CategorieServiceFactory {
$entityManager = $container->get('doctrine.entitymanager.orm_default'); $entityManager = $container->get('doctrine.entitymanager.orm_default');
$service = new CategorieService(); $service = new CategorieService();
$service->setEntityManager($entityManager); $service->setObjectManager($entityManager);
return $service; return $service;
} }
......
...@@ -5,15 +5,15 @@ namespace UnicaenParametre\Service\Parametre; ...@@ -5,15 +5,15 @@ namespace UnicaenParametre\Service\Parametre;
use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\ORMException; use Doctrine\ORM\ORMException;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use UnicaenApp\Exception\RuntimeException; use DoctrineModule\Persistence\ProvidesObjectManager;
use UnicaenApp\Service\EntityManagerAwareTrait; use RuntimeException;
use UnicaenParametre\Entity\Db\Categorie; use UnicaenParametre\Entity\Db\Categorie;
use UnicaenParametre\Entity\Db\Parametre; use UnicaenParametre\Entity\Db\Parametre;
use Laminas\Mvc\Controller\AbstractActionController; use Laminas\Mvc\Controller\AbstractActionController;
class ParametreService class ParametreService
{ {
use EntityManagerAwareTrait; use ProvidesObjectManager;
/** GESTION ENTITY ************************************************************************************************/ /** GESTION ENTITY ************************************************************************************************/
...@@ -24,8 +24,8 @@ class ParametreService ...@@ -24,8 +24,8 @@ class ParametreService
public function create(Parametre $parametre): Parametre public function create(Parametre $parametre): Parametre
{ {
try { try {
$this->getEntityManager()->persist($parametre); $this->getObjectManager()->persist($parametre);
$this->getEntityManager()->flush($parametre); $this->getObjectManager()->flush($parametre);
} catch (ORMException $e) { } 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);
} }
...@@ -39,7 +39,7 @@ class ParametreService ...@@ -39,7 +39,7 @@ class ParametreService
public function update(Parametre $parametre): Parametre public function update(Parametre $parametre): Parametre
{ {
try { try {
$this->getEntityManager()->flush($parametre); $this->getObjectManager()->flush($parametre);
} catch (ORMException $e) { } 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);
} }
...@@ -53,8 +53,8 @@ class ParametreService ...@@ -53,8 +53,8 @@ class ParametreService
public function delete(Parametre $parametre): Parametre public function delete(Parametre $parametre): Parametre
{ {
try { try {
$this->getEntityManager()->remove($parametre); $this->getObjectManager()->remove($parametre);
$this->getEntityManager()->flush($parametre); $this->getObjectManager()->flush($parametre);
} catch (ORMException $e) { } 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);
} }
...@@ -68,7 +68,7 @@ class ParametreService ...@@ -68,7 +68,7 @@ class ParametreService
*/ */
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'); ->addSelect('categorie')->join('parametre.categorie', 'categorie');
return $qb; return $qb;
} }
...@@ -110,8 +110,7 @@ class ParametreService ...@@ -110,8 +110,7 @@ class ParametreService
{ {
$qb = $this->createQueryBuilder() $qb = $this->createQueryBuilder()
->andWhere('parametre.id = :id') ->andWhere('parametre.id = :id')
->setParameter('id', $id) ->setParameter('id', $id);
;
try { try {
$result = $qb->getQuery()->getOneOrNullResult(); $result = $qb->getQuery()->getOneOrNullResult();
} catch (NonUniqueResultException $e) { } catch (NonUniqueResultException $e) {
...@@ -131,8 +130,7 @@ class ParametreService ...@@ -131,8 +130,7 @@ class ParametreService
->andWhere('categorie.code = :categorieCode') ->andWhere('categorie.code = :categorieCode')
->andWhere('parametre.code = :parametreCode') ->andWhere('parametre.code = :parametreCode')
->setParameter('categorieCode', $categorieCode) ->setParameter('categorieCode', $categorieCode)
->setParameter('parametreCode', $parametreCode) ->setParameter('parametreCode', $parametreCode);
;
try { try {
$result = $qb->getQuery()->getOneOrNullResult(); $result = $qb->getQuery()->getOneOrNullResult();
......
...@@ -5,22 +5,13 @@ namespace UnicaenParametre\Service\Parametre; ...@@ -5,22 +5,13 @@ namespace UnicaenParametre\Service\Parametre;
trait ParametreServiceAwareTrait trait ParametreServiceAwareTrait
{ {
/** @var ParametreService */ protected ParametreService $parametreService;
protected $parametreService;
/** public function setParametreService(ParametreService $parametreService) : void
* @param ParametreService $parametreService
* @return ParametreService
*/
public function setParametreService(ParametreService $parametreService) : ParametreService
{ {
$this->parametreService = $parametreService; $this->parametreService = $parametreService;
return $this->parametreService;
} }
/**
* @return ParametreService
*/
public function getParametreService() : ParametreService public function getParametreService() : ParametreService
{ {
return $this->parametreService; return $this->parametreService;
......
...@@ -4,6 +4,8 @@ namespace UnicaenParametre\Service\Parametre; ...@@ -4,6 +4,8 @@ namespace UnicaenParametre\Service\Parametre;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Interop\Container\ContainerInterface; use Interop\Container\ContainerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class ParametreServiceFactory class ParametreServiceFactory
{ {
...@@ -11,8 +13,10 @@ class ParametreServiceFactory ...@@ -11,8 +13,10 @@ class ParametreServiceFactory
/** /**
* @param ContainerInterface $container * @param ContainerInterface $container
* @return ParametreService * @return ParametreService
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function __invoke(ContainerInterface $container) public function __invoke(ContainerInterface $container) : ParametreService
{ {
/** /**
* @var EntityManager $entityManager * @var EntityManager $entityManager
...@@ -20,7 +24,7 @@ class ParametreServiceFactory ...@@ -20,7 +24,7 @@ class ParametreServiceFactory
$entityManager = $container->get('doctrine.entitymanager.orm_default'); $entityManager = $container->get('doctrine.entitymanager.orm_default');
$service = new ParametreService(); $service = new ParametreService();
$service->setEntityManager($entityManager); $service->setObjectManager($entityManager);
return $service; return $service;
} }
} }
\ No newline at end of file
...@@ -42,12 +42,11 @@ if ($selection !== null) $categories = [ $selection ]; ...@@ -42,12 +42,11 @@ if ($selection !== null) $categories = [ $selection ];
<?php foreach ($categories as $categorie) : ?> <?php foreach ($categories as $categorie) : ?>
<?php $id = $categorie->getId(); ?> <?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> <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() */?> <a <?php /** @see \Application\Controller\ParametreController::ajouterAction() */?>
href="<?php echo $this->url('parametre/ajouter', ['categorie' => $categorie->getId()], [], true); ?>" 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 <i class="fas fa-plus"></i> Ajouter un paramètre
</a> </a>
<?php if ($selection === null) : ?> <?php if ($selection === null) : ?>
...@@ -70,7 +69,6 @@ if ($selection !== null) $categories = [ $selection ]; ...@@ -70,7 +69,6 @@ if ($selection !== null) $categories = [ $selection ];
</span> </span>
<?php endif; ?> <?php endif; ?>
<?php endif; ?> <?php endif; ?>
</div>
<br/> <br/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment