+++ /dev/null
-/*
- * Copyright © FYLAB and the Conseil Régional d'Île-de-France, 2009
- * This file is part of L'Interface Libre et Interactive de l'Enseignement (Lilie).
- *
- * Lilie is free software. You can redistribute it and/or modify since
- * you respect the terms of either (at least one of the both license) :
- * - under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- * - the CeCILL-C as published by CeCILL-C; either version 1 of the
- * License, or any later version
- *
- * There are special exceptions to the terms and conditions of the
- * licenses as they are applied to this software. View the full text of
- * the exception in file LICENSE.txt in the directory of this software
- * distribution.
- *
- * Lilie is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * Licenses for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the CeCILL-C along with Lilie. If not, see :
- * <http://www.gnu.org/licenses/> and
- * <http://www.cecill.info/licences.fr.html>.
- */
-
-package org.lilie.services.eliot.absences.statistiques.tableaudebord
-
-import org.lilie.services.eliot.absences.Sanction
-
-/**
- * @author jbui
- */
-class TableauDeBordSanctionService {
- /**
- * Compte le nombre de sanctions sur la période et pour la liste de structures
- * @param criteres
- * @return
- */
- Integer calculeTotalSanction(TableauDeBordParams criteres,
- TableauDeBord tableauDeBord) {
- if (criteres.hasSeuil()) {
- return calculeTotalSanctionForEleves(criteres, tableauDeBord)
- } else {
- return calculeTotalSanctionForCriteres(criteres)
- }
- }
-
- /**
- * Calcule le nombre de sanctions en fonction des critères (dates) et de la
- * liste d'élèves
- * @param criteres : les critères (dates)
- * @param tableauDeBord : le tdb contenant la liste d'élèves
- * @return un Integer
- */
- private Integer calculeTotalSanctionForEleves(TableauDeBordParams criteres,
- TableauDeBord tableauDeBord) {
- if (tableauDeBord.lignes) {
- String hql = """select count(s.id)
- from Sanction s
- where s.eleve.autorite.id in (:autoriteIds)
- and s.date >= :dateDebut
- and s.date <= :dateFin
- """
- List result = Sanction.executeQuery(hql, [
- autoriteIds: tableauDeBord.lignes*.autoriteEleveId,
- dateDebut: criteres.dateDebut,
- dateFin: criteres.dateFin
- ])
- return (Integer) result[0]
- } else {
- return 0
- }
- }
-
- /**
- * Calcule le nombre de sanction en fonction des critères (dates et classes)
- * @param criteres : les critères
- * @return un Integer
- */
- private Integer calculeTotalSanctionForCriteres(TableauDeBordParams criteres) {
- String hql = """select count(s.id)
- from Sanction s,
- PersonneProprietesScolarite persProp
- where s.eleve = persProp.personne
- and persProp.proprietesScolarite.structureEnseignement in (:structures)
- and s.date >= :dateDebut
- and s.date <= :dateFin
- """
- List result = Sanction.executeQuery(hql, [
- structures: criteres.classes,
- dateDebut: criteres.dateDebut,
- dateFin: criteres.dateFin
- ])
- return (Integer) result[0]
- }
-
- /**
- * Prépare les lignes du résultat en fonction du seuil demandé
- * @param criteres
- * @return
- */
- TableauDeBord prepareResultSetAvecSeuil(TableauDeBordParams criteres) {
- TableauDeBord result = new TableauDeBord()
-
- result.lignes.addAll(prepareLignes(criteres))
- result.nbLignes = calculeCount(criteres)
-
- return result
- }
-
- /**
- * Calcule le nombre total de lignes sans tenir compte de la pagination
- * @param criteres
- * @return un Long
- */
- Long calculeCount(TableauDeBordParams criteres) {
- String hql = """
- select 1
- from
- Sanction s,
- PersonneProprietesScolarite persProp
- where
- s.eleve = persProp.personne
- and persProp.proprietesScolarite.structureEnseignement.id in (:structureIds)
- and s.date >= :dateDebut
- and s.date <= :dateFin
- group by
- s.eleve.id,
- s.eleve.autorite.id,
- persProp.proprietesScolarite.structureEnseignement.code,
- s.eleve.nom,
- s.eleve.prenom
- having count(s.id) >= :seuil
- order by s.eleve.nom, s.eleve.prenom
- """
- List datas = Sanction.executeQuery(
- hql,
- [
- structureIds:criteres.classes*.id,
- dateDebut: criteres.dateDebut,
- dateFin: criteres.dateFin,
- seuil: (Long)criteres.valeurSeuil
- ]
- )
- return datas.size()
- }
-
- /**
- * Retourne les données pour la page demandée
- * @param criteres
- * @return List<TableauDeBordLigne>
- */
- List<TableauDeBordLigne> prepareLignes(TableauDeBordParams criteres) {
- String hql = """
- select
- s.eleve.id,
- s.eleve.autorite.id,
- persProp.proprietesScolarite.structureEnseignement.code,
- s.eleve.nom,
- s.eleve.prenom
- from
- Sanction s,
- PersonneProprietesScolarite persProp
- where
- s.eleve = persProp.personne
- and persProp.proprietesScolarite.structureEnseignement.id in (:structureIds)
- and s.date >= :dateDebut
- and s.date <= :dateFin
- group by
- s.eleve.id,
- s.eleve.autorite.id,
- persProp.proprietesScolarite.structureEnseignement.code,
- s.eleve.nom,
- s.eleve.prenom
- having count(s.id) >= :seuil
- """
-
- String sortOrder = criteres.sortAsc ? '' : 'desc'
- if(criteres.sortField == TableauDeBordService.FIELD_DIVISION_CODE){
- hql += "order by persProp.proprietesScolarite.structureEnseignement.code " +
- "$sortOrder, s.eleve.nom $sortOrder, s.eleve.prenom $sortOrder"
- } else {
- hql += "order by s.eleve.nom $sortOrder, s.eleve.prenom $sortOrder"
- }
-
- Map paramsPagination = [offset: criteres.start]
- if (criteres.limit != -1) {
- paramsPagination['max']=criteres.limit
- }
-
- List datas = Sanction.executeQuery(
- hql,
- [
- structureIds:criteres.classes*.id,
- dateDebut: criteres.dateDebut,
- dateFin: criteres.dateFin,
- seuil: (Long)criteres.valeurSeuil
- ],
- paramsPagination
- )
-
- List<TableauDeBordLigne> result = []
- datas.each {
- result << new TableauDeBordLigne(
- autoriteEleveId: (Long)it[1],
- personneEleveId: (Long)it[0],
- divisionCode: it[2],
- nomPrenom: (it[3] + ' ' + it[4]).trim()
- )
- }
- return result
- }
-}