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

Vers PHP 8.0 + retrait de certaines dependance à unicaen/app

parent 9e3255a2
No related branches found
No related tags found
No related merge requests found
Pipeline #17300 passed
Showing
with 179 additions and 310 deletions
<?php
return [
// 'navigation' => [
// 'default' => [
// 'home' => [
// 'pages' => [
// 'indicateur' => [
// 'label' => 'Mes indicateurs',
// 'route' => 'mes-indicateurs',
// 'resource' => PrivilegeController::getResourceId(IndexController::class, 'index'),
// 'order' => 10001,
// 'icon' => 'fas fa-angle-right',
// ],
// ],
// ],
// ],
// ],
'navigation' => [
'default' => [
'home' => [
'pages' => [
'mes-indicateurs' => [
'label' => 'Mes indicateurs',
'route' => 'mes-indicateurs',
'resource' => PrivilegeController::getResourceId(IndexController::class, 'index'),
'order' => 10001,
'icon' => 'fas fa-angle-right',
],
],
],
],
],
];
\ No newline at end of file
INSERT INTO unicaen_privilege_categorie (code, libelle, ordre, namespace)
VALUES ('indicateur', 'Gestions des indicateurs', 800, 'Indicateur\Provider\Privilege');
VALUES ('indicateur', 'Gestions des indicateurs', 800, 'UnicaenIndicateur\Provider\Privilege');
INSERT INTO unicaen_privilege_privilege(CATEGORIE_ID, CODE, LIBELLE, ORDRE)
WITH d(code, lib, ordre) AS (
SELECT 'afficher-indicateur', 'Afficher un indicateur', 1 UNION
......@@ -11,7 +11,7 @@ FROM d
JOIN unicaen_privilege_categorie cp ON cp.CODE = 'indicateur';
INSERT INTO unicaen_privilege_categorie (code, libelle, ordre, namespace)
VALUES ('abonnement', 'Gestions des abonnement', 810, 'Indicateur\Provider\Privilege');
VALUES ('abonnement', 'Gestions des abonnement', 810, 'UnicaenIndicateur\Provider\Privilege');
INSERT INTO unicaen_privilege_privilege(CATEGORIE_ID, CODE, LIBELLE, ORDRE)
WITH d(code, lib, ordre) AS (
SELECT 'afficher-abonnement', 'Afficher un abonnement', 4 UNION
......
......@@ -2,8 +2,7 @@
namespace UnicaenIndicateur\Controller;
use DateInterval;
use DateTime;
use Laminas\Http\Response;
use UnicaenIndicateur\Entity\Db\Abonnement;
use UnicaenIndicateur\Service\Abonnement\AbonnementServiceAwareTrait;
use UnicaenIndicateur\Service\Indicateur\IndicateurServiceAwareTrait;
......@@ -13,10 +12,10 @@ use Laminas\View\Model\ViewModel;
class AbonnementController extends AbstractActionController {
use AbonnementServiceAwareTrait;
use UnicaenIndicateurServiceAwareTrait;
use IndicateurServiceAwareTrait;
use UserServiceAwareTrait;
public function indexAction()
public function indexAction() : ViewModel
{
$abonnements = [];
......@@ -25,7 +24,7 @@ class AbonnementController extends AbstractActionController {
]);
}
public function souscrireAction()
public function souscrireAction(): Response
{
$indicateur = $this->getIndicateurService()->getRequestedIndicateur($this);
$user = $this->getUserService()->getConnectedUser();
......@@ -39,7 +38,7 @@ class AbonnementController extends AbstractActionController {
return $this->redirect()->toRoute('indicateurs', [], [], true);
}
public function resilierAction()
public function resilierAction(): Response
{
$indicateur = $this->getIndicateurService()->getRequestedIndicateur($this);
$user = $this->getUserService()->getConnectedUser();
......@@ -52,15 +51,14 @@ class AbonnementController extends AbstractActionController {
return $this->redirect()->toRoute('indicateurs', [], [], true);
}
public function notifierAction()
public function notifierAction(): Response
{
$this->getAbonnementService()->notifyAbonnements();
return $this->redirect()->toRoute('indicateurs', [], [], true);
}
public function notifierConsoleAction()
public function notifierConsoleAction() : void
{
$this->getAbonnementService()->notifyAbonnements();
exit();
}
}
\ No newline at end of file
......@@ -2,6 +2,8 @@
namespace UnicaenIndicateur\Controller;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use UnicaenIndicateur\Service\Abonnement\AbonnementService;
use UnicaenIndicateur\Service\Indicateur\IndicateurService;
use Interop\Container\ContainerInterface;
......@@ -9,7 +11,13 @@ use UnicaenUtilisateur\Service\User\UserService;;
class AbonnementControllerFactory {
public function __invoke(ContainerInterface $container)
/**
* @param ContainerInterface $container
* @return AbonnementController
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container): AbonnementController
{
/**
* @var AbonnementService $abonnementService
......@@ -20,7 +28,6 @@ class AbonnementControllerFactory {
$indicateurService = $container->get(IndicateurService::class);
$userService = $container->get(UserService::class);
/** @var AbonnementController $controller */
$controller = new AbonnementController();
$controller->setAbonnementService($abonnementService);
$controller->setIndicateurService($indicateurService);
......
......@@ -2,16 +2,16 @@
namespace UnicaenIndicateur\Controller;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
use UnicaenIndicateur\Entity\Db\Abonnement;
use UnicaenIndicateur\Service\Abonnement\AbonnementServiceAwareTrait;
use UnicaenIndicateur\Service\Indicateur\IndicateurServiceAwareTrait;
use UnicaenUtilisateur\Service\User\UserServiceAwareTrait;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
class IndexController extends AbstractActionController {
use AbonnementServiceAwareTrait;
use UnicaenIndicateurServiceAwareTrait;
use IndicateurServiceAwareTrait;
use UserServiceAwareTrait;
public function indexAction() : ViewModel
......@@ -32,7 +32,7 @@ class IndexController extends AbstractActionController {
]);
}
public function abonnementAction()
public function abonnementAction() : ViewModel
{
$user = $this->getUserService()->getConnectedUser();
$indicateurs = $this->getIndicateurService()->getIndicateurs();
......@@ -48,11 +48,8 @@ class IndexController extends AbstractActionController {
$abonnement = new Abonnement();
$abonnement->setUser($user);
$abonnement->setIndicateur($indicateur);
// $abonnement->setFrequence('P1W');
$this->getAbonnementService()->create( $abonnement );
}
exit();
}
return new ViewModel([
......
......@@ -2,13 +2,21 @@
namespace UnicaenIndicateur\Controller;
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use UnicaenIndicateur\Service\Abonnement\AbonnementService;
use UnicaenIndicateur\Service\Indicateur\IndicateurService;
use Interop\Container\ContainerInterface;
use UnicaenUtilisateur\Service\User\UserService;
class IndexControllerFactory {
/**
* @param ContainerInterface $container
* @return IndexController
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container) : IndexController
{
/**
......
......@@ -3,6 +3,7 @@
namespace UnicaenIndicateur\Controller;
use DateTime;
use Laminas\Http\Response;
use UnicaenIndicateur\Entity\Db\Indicateur;
use UnicaenIndicateur\Form\Indicateur\IndicateurFormAwareTrait;
use UnicaenIndicateur\Service\Abonnement\AbonnementServiceAwareTrait;
......@@ -14,13 +15,13 @@ use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
class IndicateurController extends AbstractActionController {
use UnicaenIndicateurServiceAwareTrait;
use IndicateurServiceAwareTrait;
use UserServiceAwareTrait;
use AbonnementServiceAwareTrait;
use UnicaenIndicateurFormAwareTrait;
use IndicateurFormAwareTrait;
public function indexAction()
public function indexAction() : ViewModel
{
$indicateurs = $this->getIndicateurService()->getIndicateurs();
$user = $this->getUserService()->getConnectedUser();
......@@ -52,14 +53,14 @@ class IndicateurController extends AbstractActionController {
]);
}
public function rafraichirAction()
public function rafraichirAction() : Response
{
$indicateur = $this->getIndicateurService()->getRequestedIndicateur($this);
$this->getIndicateurService()->refresh($indicateur);
return $this->redirect()->toRoute('indicateur/afficher', ['indicateur' => $indicateur->getId()], [], true);
}
public function creerAction()
public function creerAction() : ViewModel
{
$indicateur = new Indicateur();
$form = $this->getIndicateurForm();
......@@ -72,13 +73,14 @@ class IndicateurController extends AbstractActionController {
$data = $request->getPost();
$form->setData($data);
if ($form->isValid()) {
$indicateur->setDernierRafraichissement(new DateTime());
$this->getIndicateurService()->create($indicateur);
$this->getIndicateurService()->createView($indicateur);
}
}
$vm = new ViewModel();
$vm->setTemplate('indicateur/default/default-form');
$vm->setTemplate('unicaen-indicateur/default/default-form');
$vm->setVariables([
'title' => 'Création d\'un nouvel indicateur',
'form' => $form,
......@@ -86,7 +88,7 @@ class IndicateurController extends AbstractActionController {
return $vm;
}
public function modifierAction()
public function modifierAction(): ViewModel
{
$indicateur = $this->getIndicateurService()->getRequestedIndicateur($this);
$form = $this->getIndicateurForm();
......@@ -105,7 +107,7 @@ class IndicateurController extends AbstractActionController {
}
$vm = new ViewModel();
$vm->setTemplate('indicateur/default/default-form');
$vm->setTemplate('unicaen-indicateur/default/default-form');
$vm->setVariables([
'title' => 'Modification d\'un indicateur',
'form' => $form,
......@@ -113,7 +115,7 @@ class IndicateurController extends AbstractActionController {
return $vm;
}
public function detruireAction()
public function detruireAction(): Response
{
$indicateur = $this->getIndicateurService()->getRequestedIndicateur($this);
$this->getIndicateurService()->dropView($indicateur);
......@@ -121,7 +123,7 @@ class IndicateurController extends AbstractActionController {
return $this->redirect()->toRoute('indicateurs', [], [], true);
}
public function exporterAction()
public function exporterAction(): CsvModel
{
$indicateur = $this->getIndicateurService()->getRequestedIndicateur($this);
$date = new DateTime();
......@@ -139,16 +141,16 @@ class IndicateurController extends AbstractActionController {
return $CSV;
}
public function rafraichirTousAction()
public function rafraichirTousAction() : void
{
$indicateurs = $this->getIndicateurService()->getIndicateurs();
foreach ($indicateurs as $indicateur) {
$this->getIndicateurService()->refresh($indicateur);
}
exit();
}
public function rafraichirConsoleAction() {
public function rafraichirConsoleAction() : void
{
$indicateurs = $this->getIndicateurService()->getIndicateurs();
foreach ($indicateurs as $indicateur) {
$this->getIndicateurService()->refresh($indicateur);
......
......@@ -2,6 +2,8 @@
namespace UnicaenIndicateur\Controller;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use UnicaenIndicateur\Form\Indicateur\IndicateurForm;
use UnicaenIndicateur\Service\Abonnement\AbonnementService;
use UnicaenIndicateur\Service\Indicateur\IndicateurService;
......@@ -10,7 +12,13 @@ use UnicaenUtilisateur\Service\User\UserService;;
class IndicateurControllerFactory {
public function __invoke(ContainerInterface $container)
/**
* @param ContainerInterface $container
* @return IndicateurController
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container) : IndicateurController
{
/**
* @var AbonnementService $abonnementService
......@@ -26,7 +34,6 @@ class IndicateurControllerFactory {
*/
$indicateurForm = $container->get('FormElementManager')->get(IndicateurForm::class);
/** @var IndicateurController $controller */
$controller = new IndicateurController();
$controller->setAbonnementService($abonnementService);
$controller->setIndicateurService($indicateurService);
......
......@@ -7,95 +7,55 @@ use UnicaenUtilisateur\Entity\Db\User;
class Abonnement {
/** @var integer */
private $id;
/** @var User */
private $user;
/** @var Indicateur */
private $indicateur;
/** @var string */
private $frequence;
/** @var DateTime */
private $dernierEnvoi;
private ?int $id = null;
private ?User $user = null;
private ?Indicateur $indicateur = null;
private ?string $frequence = null;
private ?DateTime $dernierEnvoi = null;
/**
* @return int
*/
public function getId()
public function getId() : ?int
{
return $this->id;
}
/**
* @return User
*/
public function getUser()
public function getUser() : ?User
{
return $this->user;
}
/**
* @param User $user
* @return Abonnement
*/
public function setUser($user)
public function setUser(?User $user) : void
{
$this->user = $user;
return $this;
}
/**
* @return Indicateur
*/
public function getIndicateur()
public function getIndicateur() : ?Indicateur
{
return $this->indicateur;
}
/**
* @param Indicateur $indicateur
* @return Abonnement
*/
public function setIndicateur($indicateur)
public function setIndicateur(?Indicateur $indicateur) : void
{
$this->indicateur = $indicateur;
return $this;
}
/**
* @return string
*/
public function getFrequence()
public function getFrequence() : ?string
{
return $this->frequence;
}
/**
* @param string $frequence
* @return Abonnement
*/
public function setFrequence($frequence)
public function setFrequence(?string $frequence) : void
{
$this->frequence = $frequence;
return $this;
}
/**
* @return DateTime
*/
public function getDernierEnvoi()
public function getDernierEnvoi() : ?DateTime
{
return $this->dernierEnvoi;
}
/**
* @param DateTime $denierEnvoi
* @return Abonnement
*/
public function setDernierEnvoi($denierEnvoi)
public function setDernierEnvoi(?DateTime $denierEnvoi) : void
{
$this->dernierEnvoi = $denierEnvoi;
return $this;
}
......
......@@ -4,6 +4,7 @@ namespace UnicaenIndicateur\Entity\Db;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
class Indicateur {
......@@ -12,180 +13,105 @@ class Indicateur {
const ENTITY_LIBRE = 'Libre';
const ENTITY_ADAPTATIF = 'Adaptatif';
/** @var integer */
private $id;
/** @var string */
private $titre;
/** @var string */
private $description;
/** @var string */
private $requete;
/** @var DateTime */
private $dernierRafraichissement;
/** @var string */
private $viewId;
/** @var string */
private $entity;
/** @var ArrayCollection (Abonnement) */
private $abonnements;
private ?int $id = null;
private ?string $titre = null;
private ?string $description = null;
private ?string $requete = null;
private ?DateTime $dernierRafraichissement = null;
private ?string $viewId = null;
private ?string $entity = null;
private Collection $abonnements;
public function __construct()
{
$this->abonnements = new ArrayCollection();
}
/**
* @return int
*/
public function getId()
public function getId() : ?int
{
return $this->id;
}
/**
* @return string
*/
public function getTitre()
public function getTitre() : string
{
return $this->titre;
}
/**
* @param string $titre
* @return Indicateur
*/
public function setTitre($titre)
public function setTitre(?string $titre) : void
{
$this->titre = $titre;
return $this;
}
/**
* @return string
*/
public function getDescription()
public function getDescription() : string
{
return $this->description;
}
/**
* @param string $description
* @return Indicateur
*/
public function setDescription($description)
public function setDescription(?string $description) : void
{
$this->description = $description;
return $this;
}
/**
* @return string
*/
public function getRequete()
public function getRequete() : string
{
return $this->requete;
}
/**
* @param string $requete
* @return Indicateur
*/
public function setRequete($requete)
public function setRequete(?string $requete) : void
{
$this->requete = $requete;
return $this;
}
/**
* @return DateTime
*/
public function getDernierRafraichissement()
public function getDernierRafraichissement() : ?DateTime
{
return $this->dernierRafraichissement;
}
/**
* @param DateTime $dernierRafraichissement
* @return Indicateur
*/
public function setDernierRafraichissement($dernierRafraichissement)
public function setDernierRafraichissement(?DateTime $dernierRafraichissement) : void
{
$this->dernierRafraichissement = $dernierRafraichissement;
return $this;
}
/**
* @return string
*/
public function getViewId()
public function getViewId() : string
{
return $this->viewId;
}
/**
* @param string $viewId
* @return Indicateur
*/
public function setViewId($viewId)
public function setViewId(?string $viewId) : void
{
$this->viewId = $viewId;
return $this;
}
/**
* @return string
*/
public function getEntity()
public function getEntity() : ?string
{
return $this->entity;
}
/**
* @param string $entity
* @return Indicateur
*/
public function setEntity($entity)
public function setEntity(?string $entity) : void
{
$this->entity = $entity;
return $this;
}
/**
* @return Abonnement[]
*/
public function getAbonnements()
public function getAbonnements() : array
{
return $this->abonnements->toArray();
}
/**
* @param Abonnement $abonnement
* @return Indicateur
*/
public function addAbonnement($abonnement)
public function addAbonnement(Abonnement $abonnement) : void
{
$this->abonnements->add($abonnement);
return $this;
}
/**
* @param Abonnement $abonnement
* @return Indicateur
*/
public function removeAbonnement($abonnement)
public function removeAbonnement(Abonnement $abonnement) : void
{
$this->abonnements->removeElement($abonnement);
return $this;
}
/**
* @param Abonnement $abonnement
* @return Indicateur
*/
public function hasAbonnement($abonnement)
public function hasAbonnement(Abonnement $abonnement) : bool
{
$this->abonnements->contains($abonnement);
return $this;
return $this->abonnements->contains($abonnement);
}
}
\ No newline at end of file
......@@ -2,28 +2,19 @@
namespace UnicaenIndicateur\Form\Indicateur;
trait IndicateurFormAwareTrait {
trait IndicateurFormAwareTrait
{
/** @var IndicateurForm */
private $indicateurForm;
private IndicateurForm $indicateurForm;
/**
* @return IndicateurForm
*/
public function getIndicateurForm()
public function getIndicateurForm() : IndicateurForm
{
return $this->indicateurForm;
}
/**
* @param IndicateurForm $indicateurForm
* @return IndicateurForm
*/
public function setIndicateurForm($indicateurForm)
public function setIndicateurForm(IndicateurForm $indicateurForm) : void
{
$this->indicateurForm = $indicateurForm;
return $this->indicateurForm;
}
}
\ No newline at end of file
......@@ -3,16 +3,22 @@
namespace UnicaenIndicateur\Form\Indicateur;
use Interop\Container\ContainerInterface;
use Laminas\Form\FormElementManager;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class IndicateurFormFactory {
public function __invoke(ContainerInterface $container)
/**
* @param ContainerInterface $container
* @return IndicateurForm
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container) : IndicateurForm
{
/** @var IndicateurHydrator $hydrator */
$hydrator = $container->get('HydratorManager')->get(IndicateurHydrator::class);
/** @var IndicateurForm $form */
$form = new IndicateurForm();
$form->setHydrator($hydrator);
$form->init();
......
......@@ -28,7 +28,7 @@ class IndicateurHydrator implements HydratorInterface {
* @param Indicateur $object
* @return Indicateur
*/
public function hydrate(array $data, $object)
public function hydrate(array $data, $object) : object
{
$object->setTitre($data['libelle']);
$object->setDescription($data['description']);
......
......@@ -6,9 +6,8 @@ use Interop\Container\ContainerInterface;
class IndicateurHydratorFactory {
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container) : IndicateurHydrator
{
/** @var IndicateurHydrator $hydrator */
$hydrator = new IndicateurHydrator();
return $hydrator;
}
......
......@@ -6,7 +6,7 @@ use UnicaenPrivilege\Provider\Privilege\Privileges;
class AbonnementPrivileges extends Privileges
{
const AFFICHER = 'indicateur-afficher-abonnement';
const EDITER = 'indicateur-editer-abonnement';
const DETRUIRE = 'indicateur-detruire-abonnement';
const AFFICHER = 'abonnement-afficher';
const EDITER = 'abonnement-editer';
const DETRUIRE = 'abonnement-detruire';
}
\ No newline at end of file
......@@ -6,7 +6,7 @@ use UnicaenPrivilege\Provider\Privilege\Privileges;
class IndicateurPrivileges extends Privileges
{
const AFFICHER = 'indicateur-afficher-indicateur';
const EDITER = 'indicateur-editer-indicateur';
const DETRUIRE = 'indicateur-detruire-indicateur';
const AFFICHER = 'indicateur-afficher';
const EDITER = 'indicateur-editer';
const DETRUIRE = 'indicateur-detruire';
}
\ No newline at end of file
......@@ -3,63 +3,55 @@
namespace UnicaenIndicateur\Service\Abonnement;
use DateTime;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\QueryBuilder;
use DoctrineModule\Persistence\ProvidesObjectManager;
use Laminas\Mvc\Controller\AbstractActionController;
use RuntimeException;
use UnicaenIndicateur\Entity\Db\Abonnement;
use UnicaenIndicateur\Entity\Db\Indicateur;
use UnicaenIndicateur\Service\Indicateur\IndicateurServiceAwareTrait;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenMail\Service\Mail\MailServiceAwareTrait;
use UnicaenUtilisateur\Entity\Db\User;
use Laminas\Mvc\Controller\AbstractActionController;
/**
* @property EntityManager $objectManager
*/
class AbonnementService {
use EntityManagerAwareTrait;
use UnicaenIndicateurServiceAwareTrait;
use IndicateurServiceAwareTrait;
use MailServiceAwareTrait;
use ProvidesObjectManager;
/** GESTION DES ENTITES *******************************************************************************************/
/**
* @param Abonnement $abonnement
* @return Abonnement
*/
public function create(Abonnement $abonnement) : Abonnement
{
try {
$this->getEntityManager()->persist($abonnement);
$this->getEntityManager()->flush($abonnement);
$this->getObjectManager()->persist($abonnement);
$this->getObjectManager()->flush($abonnement);
} catch (ORMException $e) {
throw new RuntimeException("Un problème est survenue lors de l'enregistrement en base.", $e);
}
return $abonnement;
}
/**
* @param Abonnement $abonnement
* @return Abonnement
*/
public function update(Abonnement $abonnement) : Abonnement
{
try {
$this->getEntityManager()->flush($abonnement);
$this->getObjectManager()->flush($abonnement);
} catch (ORMException $e) {
throw new RuntimeException("Un problème est survenue lors de l'enregistrement en base.", $e);
}
return $abonnement;
}
/**
* @param Abonnement $abonnement
* @return Abonnement
*/
public function delete(Abonnement $abonnement) : Abonnement
{
try {
$this->getEntityManager()->remove($abonnement);
$this->getEntityManager()->flush($abonnement);
$this->getObjectManager()->remove($abonnement);
$this->getObjectManager()->flush($abonnement);
} catch (ORMException $e) {
throw new RuntimeException("Un problème est survenue lors de l'enregistrement en base.", $e);
}
......@@ -68,23 +60,15 @@ class AbonnementService {
/** REQUETAGE *****************************************************************************************************/
/**
* @return QueryBuilder
*/
public function createQueryBuilder() : QueryBuilder
{
$qb = $this->getEntityManager()->getRepository(Abonnement::class)->createQueryBuilder('abonnement')
$qb = $this->getObjectManager()->getRepository(Abonnement::class)->createQueryBuilder('abonnement')
->join('abonnement.user', 'user')->addSelect('user')
->join('abonnement.indicateur', 'indicateur')->addSelect('indicateur')
;
return $qb;
}
/**
* @param string $attribut
* @param string $ordre
* @return Abonnement[]
*/
public function getAbonnements(string $attribut = 'id', string $ordre = 'ASC') : array
{
$qb = $this->createQueryBuilder()
......@@ -94,10 +78,6 @@ class AbonnementService {
return $result;
}
/**
* @param int|null $id
* @return Abonnement|null
*/
public function getAbonnement(?int $id) : ?Abonnement
{
$qb = $this->createQueryBuilder()
......@@ -113,11 +93,6 @@ class AbonnementService {
return $result;
}
/**
* @param AbstractActionController $controller
* @param string $paramName
* @return Abonnement|null
*/
public function getRequestedAbonnement(AbstractActionController $controller, string $paramName='abonnement') : ?Abonnement
{
$id = $controller->params()->fromRoute($paramName);
......@@ -125,10 +100,10 @@ class AbonnementService {
}
/**
* @param User
* @param User $user
* @return Abonnement[]
*/
public function getAbonnementsByUser($user) : array
public function getAbonnementsByUser(User $user) : array
{
$qb = $this->createQueryBuilder()
->andWhere('abonnement.user = :user')
......@@ -158,7 +133,8 @@ class AbonnementService {
/** FONCTIONNEMENT ************************************************************************************************/
public function notifyAbonnements() {
public function notifyAbonnements() : void
{
$indicateurs = $this->getIndicateurService()->getIndicateurs();
foreach ($indicateurs as $indicateur) {
......@@ -194,10 +170,6 @@ class AbonnementService {
}
}
/**
* @param User|null $user
* @param Indicateur|null $indicateur
*/
public function isAbonner(?User $user, ?Indicateur $indicateur) : bool
{
foreach ($indicateur->getAbonnements() as $abonnement) {
......
......@@ -4,26 +4,16 @@ namespace UnicaenIndicateur\Service\Abonnement;
trait AbonnementServiceAwareTrait {
/** @var AbonnementService */
private $abonnementService;
private AbonnementService $abonnementService;
/**
* @return AbonnementService
*/
public function getAbonnementService() : AbonnementService
{
return $this->abonnementService;
}
/**
* @param AbonnementService $abonnementService
* @return AbonnementService
*/
public function setAbonnementService(AbonnementService $abonnementService) : AbonnementService
public function setAbonnementService(AbonnementService $abonnementService) : void
{
$this->abonnementService = $abonnementService;
return $this->abonnementService;
}
}
\ No newline at end of file
......@@ -3,6 +3,8 @@
namespace UnicaenIndicateur\Service\Abonnement;
use Doctrine\ORM\EntityManager;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use UnicaenIndicateur\Service\Indicateur\IndicateurService;
use Interop\Container\ContainerInterface;
use UnicaenMail\Service\Mail\MailService;
......@@ -12,8 +14,10 @@ class AbonnementServiceFactory {
/**
* @param ContainerInterface $container
* @return AbonnementService
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container) : AbonnementService
{
/**
* @var EntityManager $entityManager
......@@ -24,9 +28,8 @@ class AbonnementServiceFactory {
$indicateurService = $container->get(IndicateurService::class);
$mailService = $container->get(MailService::class);
/** @var AbonnementService $service */
$service = new AbonnementService();
$service->setEntityManager($entityManager);
$service->setObjectManager($entityManager);
$service->setIndicateurService($indicateurService);
$service->setMailService($mailService);
return $service;
......
......@@ -5,16 +5,20 @@ namespace UnicaenIndicateur\Service\Indicateur;
use DateTime;
use Doctrine\DBAL\Exception as DBA_Exception;
use Doctrine\DBAL\Driver\Exception as DBA_Driver_Exception;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\ORMException;
use DoctrineModule\Persistence\ProvidesObjectManager;
use Exception;
use RuntimeException;
use UnicaenIndicateur\Entity\Db\Indicateur;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait;
use Laminas\Mvc\Controller\AbstractActionController;
/**
* @property EntityManager $objectManager
*/
class IndicateurService {
use EntityManagerAwareTrait;
use ProvidesObjectManager;
/** GESTION DES ENTITES ***********************************************************************************************/
......@@ -25,8 +29,8 @@ class IndicateurService {
public function create(Indicateur $indicateur) : Indicateur
{
try {
$this->getEntityManager()->persist($indicateur);
$this->getEntityManager()->flush($indicateur);
$this->getObjectManager()->persist($indicateur);
$this->getObjectManager()->flush($indicateur);
} catch (ORMException $e) {
throw new RuntimeException("Un problème est survenue lors de l'enregistrement en base.", $e);
}
......@@ -40,7 +44,7 @@ class IndicateurService {
public function update(Indicateur $indicateur) : Indicateur
{
try {
$this->getEntityManager()->flush($indicateur);
$this->getObjectManager()->flush($indicateur);
} catch (ORMException $e) {
throw new RuntimeException("Un problème est survenue lors de l'enregistrement en base.", $e);
}
......@@ -54,8 +58,8 @@ class IndicateurService {
public function delete(Indicateur $indicateur) : Indicateur
{
try {
$this->getEntityManager()->remove($indicateur);
$this->getEntityManager()->flush($indicateur);
$this->getObjectManager()->remove($indicateur);
$this->getObjectManager()->flush($indicateur);
} catch (ORMException $e) {
throw new RuntimeException("Un problème est survenue lors de l'enregistrement en base.", $e);
}
......@@ -68,7 +72,7 @@ class IndicateurService {
{
try {
$sql = "SELECT EXISTS (SELECT FROM pg_matviews WHERE matviewname='" . $viewname . "')";
$query = $this->getEntityManager()->getConnection()->prepare($sql);
$query = $this->getObjectManager()->getConnection()->prepare($sql);
$query->execute();
$value = $query->fetchOne();
} catch (Exception $e) {
......@@ -89,7 +93,7 @@ class IndicateurService {
$sql = "SELECT * FROM " . $indicateur->getViewId();
try {
$query = $this->getEntityManager()->getConnection()->prepare($sql);
$query = $this->getObjectManager()->getConnection()->prepare($sql);
} catch (DBA_Exception $e) {
throw new RuntimeException("Un problème est survenu lors de la récupération de la session.", 0, $e);
}
......@@ -109,7 +113,7 @@ class IndicateurService {
{
$sql = "REFRESH MATERIALIZED VIEW " . $indicateur->getViewId();
try {
$query = $this->getEntityManager()->getConnection()->prepare($sql);
$query = $this->getObjectManager()->getConnection()->prepare($sql);
} catch (DBA_Exception $e) {
throw new RuntimeException("Un problème est survenu lors de la récupération de la session.", 0, $e);
}
......@@ -129,7 +133,7 @@ class IndicateurService {
{
$sql = "DROP MATERIALIZED VIEW IF EXISTS " . $indicateur->getViewId();
try {
$query = $this->getEntityManager()->getConnection()->prepare($sql);
$query = $this->getObjectManager()->getConnection()->prepare($sql);
} catch (DBA_Exception $e) {
throw new RuntimeException("Un problème est survenu lors de la récupération de la session.", 0, $e);
}
......@@ -147,7 +151,7 @@ class IndicateurService {
{
$sql = "CREATE MATERIALIZED VIEW ".$indicateur->getViewId(). " AS ".$indicateur->getRequete();
try {
$query = $this->getEntityManager()->getConnection()->prepare($sql);
$query = $this->getObjectManager()->getConnection()->prepare($sql);
} catch (DBA_Exception $e) {
throw new RuntimeException("Un problème est survenu lors de la récupération de la session.", 0, $e);
}
......@@ -178,7 +182,7 @@ class IndicateurService {
*/
public function getIndicateurs(string $attribut = 'id', string $ordre = 'ASC') : array
{
$qb = $this->getEntityManager()->getRepository(Indicateur::class)->createQueryBuilder('indicateur')
$qb = $this->getObjectManager()->getRepository(Indicateur::class)->createQueryBuilder('indicateur')
->orderBy('indicateur.' . $attribut, $ordre);
$result = $qb->getQuery()->getResult();
......@@ -193,7 +197,7 @@ class IndicateurService {
{
if ($id === null) return null;
$qb = $this->getEntityManager()->getRepository(Indicateur::class)->createQueryBuilder('indicateur')
$qb = $this->getObjectManager()->getRepository(Indicateur::class)->createQueryBuilder('indicateur')
->andWhere('indicateur.id = :id')
->setParameter('id', $id);
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment