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

Ajout filtre des événements

parent 3c6bd3bc
Loading
Loading
Loading
Loading
Loading

doc/Tables.sql

deleted100644 → 0
+0 −81
Original line number Diff line number Diff line
create table unicaen_evenement_etat
(
    id          serial
        constraint pk_evenement_etat
            primary key,
    code        varchar(255) not null
        constraint un_evenement_etat_code
            unique
                deferrable initially deferred,
    libelle     varchar(255) not null,
    description varchar(2047)
);

create table unicaen_evenement_type
(
    id          serial
        constraint pk_evenement_type
            primary key,
    code        varchar(255) not null
        constraint un_evenement_type_code
            unique
                deferrable initially deferred,
    libelle     varchar(255) not null,
    description varchar(2047),
    parametres  varchar(2047),
    recursion   varchar(64)
);


create table unicaen_evenement_instance
(
    id                 serial
        constraint pk_evenement_instance
            primary key,
    nom                varchar(255)  not null,
    description        varchar(1024) not null,
    type_id            integer       not null
        constraint fk_evenement_instance_type
            references unicaen_evenement_type
            deferrable,
    etat_id            integer       not null
        constraint fk_evenement_instance_etat
            references unicaen_evenement_etat
            deferrable,
    parametres         text,
    date_creation      timestamp     not null,
    date_planification timestamp     not null,
    date_traitement    timestamp,
    log                text,
    parent_id          integer
        constraint fk_evenement_instance_parent
            references unicaen_evenement_instance
            deferrable,
    date_fin           timestamp
);

create index ix_evenement_instance_type
    on unicaen_evenement_instance (type_id);

create index ix_evenement_instance_etat
    on unicaen_evenement_instance (etat_id);

create index ix_evenement_instance_parent
    on unicaen_evenement_instance (parent_id);

create table unicaen_evenement_journal
(
    id             serial
        constraint unicaen_evenement_journal_pk
            primary key,
    date_execution timestamp not null,
    log            text,
    etat_id        integer
        constraint unicaen_evenement_journal_unicaen_evenement_etat_id_fk
            references unicaen_evenement_etat
            on delete set null
);


create unique index unicaen_evenement_journal_id_uindex
    on unicaen_evenement_journal (id);
 No newline at end of file

doc/inserts.sql

deleted100644 → 0
+0 −46
Original line number Diff line number Diff line
INSERT INTO unicaen_evenement_etat (id, code, libelle) VALUES (1, 'en_attente', 'En attente');
INSERT INTO unicaen_evenement_etat (id, code, libelle) VALUES (2, 'en_cours', 'En cours');
INSERT INTO unicaen_evenement_etat (id, code, libelle) VALUES (3, 'echec', 'Échec');
INSERT INTO unicaen_evenement_etat (id, code, libelle) VALUES (4, 'succes', 'Succès');

-- EVENEMENT --------------------------------------------------------------------------------------------------

INSERT INTO unicaen_privilege_categorie (code, libelle, ordre, namespace)
VALUES ('evenementetat', 'Gestion des événements - État', 99991, 'UnicaenEvenement\Provider\Privilege');
INSERT INTO unicaen_privilege_privilege(CATEGORIE_ID, CODE, LIBELLE, ORDRE)
WITH d(code, lib, ordre) AS (
    SELECT 'etat_consultation', 'état - consultation', 10 UNION
    SELECT 'etat_ajout', 'état - ajout', 20 UNION
    SELECT 'etat_edition', 'état - édition', 30 UNION
    SELECT 'etat_suppression', 'état - suppression', 40
)
SELECT cp.id, d.code, d.lib, d.ordre
FROM d
         JOIN unicaen_privilege_categorie cp ON cp.CODE = 'evenementetat';

INSERT INTO unicaen_privilege_categorie (code, libelle, ordre, namespace)
VALUES ('evenementinstance', 'Gestion des événements - Instance', 99993, 'UnicaenEvenement\Provider\Privilege');
INSERT INTO unicaen_privilege_privilege(CATEGORIE_ID, CODE, LIBELLE, ORDRE)
WITH d(code, lib, ordre) AS (
    SELECT 'instance_consultation', 'instance - consultation', 10 UNION
    SELECT 'instance_ajout', 'instance - ajout', 20 UNION
    SELECT 'instance_edition', 'instance - édition', 30 UNION
    SELECT 'instance_suppression', 'instance - suppression', 40 UNION
    SELECT 'instance_traitement', 'instance - traitement', 100
)
SELECT cp.id, d.code, d.lib, d.ordre
FROM d
         JOIN unicaen_privilege_categorie cp ON cp.CODE = 'evenementinstance';

INSERT INTO unicaen_privilege_categorie (code, libelle, ordre, namespace)
VALUES ('evenementtype', 'Gestion des événements - Type', 99992, 'UnicaenEvenement\Provider\Privilege');
INSERT INTO unicaen_privilege_privilege(CATEGORIE_ID, CODE, LIBELLE, ORDRE)
WITH d(code, lib, ordre) AS (
    SELECT 'type_consultation', 'type - consultation', 10 UNION
    SELECT 'type_ajout', 'type - ajout', 20 UNION
    SELECT 'type_edition', 'type - édition', 30 UNION
    SELECT 'type_suppression', 'type - suppression', 40
)
SELECT cp.id, d.code, d.lib, d.ordre
FROM d
         JOIN unicaen_privilege_categorie cp ON cp.CODE = 'evenementtype';
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
```sql
INSERT INTO unicaen_evenement_etat (CODE, LIBELLE, DESCRIPTION) VALUES ('annule', 'Événement dont le traitement a été annulé', null);

alter table unicaen_evenement_instance add mots_clefs text;
```
+6 −1
Original line number Diff line number Diff line
@@ -23,7 +23,11 @@ class IndexController extends AbstractActionController
    {
        $types = $this->getTypeService()->getEntityRepository()->findAll();
        $etats = $this->getEtatEvenementService()->getEntityRepository()->findAll();
        $evenements = $this->getEvenementService()->getEvenements();

        $filtre = $this->params()->fromQuery();
        if (!isset($filtre['date']) OR $filtre['date'] === '') $filtre['date'] = '1M';

        $evenements = $this->getEvenementService()->getEvenementsWithFiltre($filtre);
        $journaux = $this->getJournalService()->getJounaux();

        return new ViewModel([
@@ -31,6 +35,7 @@ class IndexController extends AbstractActionController
            'countEvents' => count(($evenements)??[]),
            'types' => ($types)??[],
            'etats' => ($etats)??[],
            'params' => $filtre,
            'journaux' => $journaux,
        ]);
    }
+29 −0
Original line number Diff line number Diff line
@@ -2,10 +2,12 @@

namespace UnicaenEvenement\Service\Evenement;

use DateInterval;
use DateTime;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\QueryBuilder;
use Exception;
use UnicaenApp\Exception\RuntimeException;
use UnicaenEvenement\Entity\Db\Etat;
use UnicaenEvenement\Entity\Db\Evenement;
@@ -117,6 +119,33 @@ class EvenementService extends CommonService implements EvenementServiceInterfac
        return $result;
    }

    /**
     * @param array $filtres
     * @return Evenement[]
     */
    public function getEvenementsWithFiltre(array $filtres = []) : array
    {
        $qb = $this->createQueryBuilder();

        if (isset($filtres['etat']) AND $filtres['etat'] !== '') {
            $qb = $qb->andWhere('etat.code = :etat')->setParameter('etat', $filtres['etat']);
        }
        if (isset($filtres['date']) AND $filtres['date'] !== '') {
            try {
                $date = (new DateTime())->sub(new DateInterval('P' . $filtres['date']));
            } catch (Exception $e) {
                throw new RuntimeException("Problème de calcul de la date buttoir avec [".$filtres['date']."]",0,$e);
            }
            $qb = $qb->andWhere('evenement.datePlanification >= :date')->setParameter('date',$date);
        }
        if (isset($filtres['type']) AND $filtres['type'] !== '') {
            $qb = $qb->andWhere('type.id = :type')->setParameter('type', $filtres['type']);
        }

        $result = $qb->getQuery()->getResult();
        return $result;
    }

    /**
     * @param int|null $id
     * @return Evenement|null
Loading