--- /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.scolarite.publipostage
+
+import java.text.SimpleDateFormat
+import grails.converters.JSON
+import org.lilie.services.eliot.impression.TemplateDocument
+import org.lilie.services.eliot.sms.SmsStatut
+import org.lilie.services.eliot.impression.constantes.TypeMedia
+import org.lilie.services.eliot.impression.PublipostageSuivi
+import org.lilie.services.eliot.impression.ImpressionSuiviEleveService
+import org.lilie.services.eliot.scolarite.Etablissement
+import org.lilie.services.eliot.utils.EliotMsg
+import org.lilie.services.eliot.scolarite.StructureEnseignement
+
+/**
+ * Accès aux données du suivi élève
+ */
+class SuiviEleveService {
+
+ ImpressionSuiviEleveService impressionSuiviEleveService
+
+ public Map rechercher(Map params, Etablissement etablissement) {
+
+ Map result = [:]
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss",
+ Locale.FRANCE)
+
+ Map mapParams = (Map) JSON.parse(params.params)
+
+ Date dateDebut = mapParams.dateDebut ? sdf.parse(mapParams.dateDebut) : null
+ Date dateFin = mapParams.dateFin ? sdf.parse(mapParams.dateFin) : null
+
+ List<TemplateDocument> modeles = mapParams.modeleIds ? TemplateDocument.getAll(mapParams
+ .modeleIds) : []
+
+ dateFin.setTime(dateFin.getTime() + 24 * 3600 * 1000)
+
+ int start = mapParams.start ?: 0
+
+ Map sortInfo = [:]
+ List<SmsStatut> statuts = []
+
+ switch (mapParams.mediaId) {
+ case TypeMedia.COURRIER.getCode():
+ sortInfo = mapParams.sortInfo
+ break
+ case TypeMedia.SMS.getCode():
+ sortInfo = mapParams.sort ? [field: mapParams.sort, direction: mapParams.dir] : [:]
+ statuts = mapParams.statuts ? mapParams.statuts.collect {SmsStatut[it]} : []
+ break
+ }
+
+ List<StructureEnseignement> classes = StructureEnseignement.getAll(mapParams.classeIds)
+
+ Map listeEnvoi = impressionSuiviEleveService.listeEnvoi(
+ etablissement,
+ dateDebut,
+ dateFin,
+ classes,
+ modeles,
+ start,
+ sortInfo,
+ TypeMedia.typeMediaForCode(mapParams.mediaId),
+ statuts
+ )
+
+ return marshallRechercher(listeEnvoi, result)
+ }
+
+ private LinkedHashMap marshallRechercher(LinkedHashMap listeEnvoi, LinkedHashMap result) {
+
+ SimpleDateFormat sdfDate = new SimpleDateFormat("dd/MM/yyyy",
+ Locale.FRANCE)
+ SimpleDateFormat sdfHeure = new SimpleDateFormat("HH:mm",
+ Locale.FRANCE)
+
+ List<PublipostageSuivi> suivis = listeEnvoi.liste
+
+ result.data = suivis.collect {
+ [
+ id: it.id,
+ date: sdfDate.format(it.dateEnvoi),
+ heure :sdfHeure.format(it.dateEnvoi),
+ nom: it.personne?.nomAffichage(),
+ classe: it.classe?.code,
+ type: EliotMsg.message(TypeMedia.typeMediaForCode(it.media).libelle),
+ responsable: it?.responsable?.nomAffichage(),
+ modele: it?.templateDocument?.nom,
+ portable: it?.responsable?.getTelephonePortable(),
+ statut: it.statut ? EliotMsg.message('eliot.impression.sms.statut.' + it.statut.toString()) : ''
+ ]
+ }
+
+ result.nbData = listeEnvoi.nbData
+ result.success = true
+ return result
+ }
+
+}