--- /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.notes.publipostage.suivipareleve
+
+import grails.converters.JSON
+import org.lilie.services.eliot.notes.AbstractNotesController
+import org.lilie.services.eliot.notes.ActionEnum
+import org.lilie.services.eliot.notes.NotesDroitService
+import org.lilie.services.eliot.notes.page.Page
+import org.lilie.services.eliot.scolarite.structureenseignement.LocalStructureEnseignementService
+import org.lilie.services.eliot.impression.ImpressionEditionService
+import org.lilie.services.eliot.impression.ImpressionSuiviEleveService
+import org.lilie.services.eliot.scolarite.StructureEnseignement
+import java.text.SimpleDateFormat
+import org.lilie.services.eliot.scolarite.Calendrier
+import org.lilie.services.eliot.parametrages.calendrier.CalendrierService
+
+import org.lilie.services.eliot.scolarite.etablissement.PreferencesEtablissementAbsencesService
+import org.lilie.services.eliot.impression.constantes.TemplateTypeFonctionnaliteEnum
+import org.lilie.services.eliot.impression.ImpressionTemplateDocumentService
+import org.lilie.services.eliot.impression.PublipostageSuivi
+import org.lilie.services.eliot.impression.TemplateDocument
+import org.lilie.services.eliot.notes.NotesFonction
+import org.lilie.services.eliot.urllabel.breadcrumbs.BreadCrumbsItemInfo
+
+/**
+ * Suivi du publipostage
+ * @author onic
+ */
+class SuiviEleveController extends AbstractNotesController {
+
+ private SimpleDateFormat df = new SimpleDateFormat(
+ "yyyy-MM-dd'T'HH:mm:ss",
+ Locale.FRANCE
+ )
+
+ private SimpleDateFormat sdfJS = new SimpleDateFormat(
+ "dd/MM/yyyy",
+ Locale.FRANCE
+ )
+
+ NotesDroitService notesDroitService
+ LocalStructureEnseignementService localStructureEnseignementService
+ CalendrierService calendrierService
+ PreferencesEtablissementAbsencesService preferencesEtablissementAbsencesService
+ ImpressionEditionService impressionEditionService
+ ImpressionSuiviEleveService impressionSuiviEleveService
+ ImpressionTemplateDocumentService impressionTemplateDocumentService
+
+ /**
+ * Page d'accueil
+ */
+ def index = {
+
+ notesDroitService.verifieAutorisationByEtablissement(
+ securiteSession,
+ etablissementCourant(),
+ ActionEnum.CONSULTATION,
+ NotesFonction.DIRECTION_ASSIMILE
+ )
+
+ Map modele = prepareBaseModele(Page.PUBLIPOSTAGE_SUIVI_PAR_ELEVE)
+
+ // Liste des classes
+ modele.classes = getClasses().collect {[id: it.id, libelle: it.code]} as JSON
+
+ modele.modeles = getAllModeleDeNotes() as JSON
+
+ Calendrier calendrier = calendrierService.
+ getCalendrierForEtablissement(etablissementCourant())
+
+ modele.anneeScolaire = [
+ debutAnneeScolaire: calendrier.premierJour ? sdfJS.format(calendrier.premierJour) : null,
+ finAnneeScolaire: calendrier.dernierJour ? sdfJS.format(calendrier.dernierJour) : null
+ ] as JSON
+
+ render(
+ view: '/publipostage/suivipareleve/index',
+ model: modele
+ )
+ }
+
+ /**
+ * Recherche
+ */
+ def recherche = {
+
+ Map resultat = tryCatch {
+
+ Map result = [:]
+
+ SimpleDateFormat sdfAffichageDate = new SimpleDateFormat(
+ "dd/MM/yyyy HH:mm",
+ Locale.FRANCE
+ )
+
+ notesDroitService.verifieAutorisationByEtablissement(
+ securiteSession,
+ etablissementCourant(),
+ ActionEnum.CONSULTATION,
+ NotesFonction.DIRECTION_ASSIMILE
+ )
+
+ Map mapParams = (Map) JSON.parse(params.params)
+
+ Date dateDebut = mapParams.dateDebut ? df.parse(mapParams.dateDebut) : null
+ Date dateFin = mapParams.dateFin ? df.parse(mapParams.dateFin) : null
+
+ // Classes
+ List<StructureEnseignement> classes = []
+ List<Long> classesAutoriseesIds = getClasses().collect {it.id}
+ mapParams.classes?.each {
+
+ Long classeId = Long.valueOf(it)
+
+ if (classesAutoriseesIds.contains(classeId)) {
+ StructureEnseignement classe = StructureEnseignement.get(classeId)
+ if (classe != null) {
+ classes.push(classe)
+ }
+ }
+
+ }
+
+ //TOREFACT : il faut utiliser les id des TemplateDocument
+ List<TemplateDocument> modeles = []
+ mapParams.modeles.each {
+ modeles << TemplateDocument.findByNomAndEtablissement(it,etablissementCourant())
+ }
+
+ dateFin.setTime(dateFin.getTime() + 24 * 3600 * 1000)
+
+ int start = mapParams.start ?: 0
+
+ Map listeEnvoi = impressionSuiviEleveService.listeEnvoi(
+ etablissementCourant(),
+ dateDebut,
+ dateFin,
+ classes,
+ modeles,
+ start,
+ mapParams.sortInfo
+ )
+ List<PublipostageSuivi> suivis = listeEnvoi.liste
+
+ result.data = suivis.collect {
+
+ String type = ''
+
+ switch (it.media) {
+ case 1:
+ type = message(code: 'eliot.notes.media.courrier')
+ break;
+
+ case 2:
+ type = message(code: 'eliot.notes.media.sms')
+ break;
+
+ case 3:
+ type = message(code: 'eliot.notes.media.email')
+ break;
+ }
+
+ [
+ id: it.id,
+ date: sdfAffichageDate.format(it.dateEnvoi),
+ nom: it.personne?.nomAffichage(),
+ classe: it.classe?.code,
+ type: type,
+ modele: it?.templateDocument.nom,
+ periode: getNomPeriode(it)
+ ]
+ }
+
+ result.nbData = listeEnvoi.nbData
+ result.success = true
+ return result
+ }
+
+ resultat.success = true
+ render resultat as JSON
+ }
+
+ private String getNomPeriode(PublipostageSuivi suivi) {
+ if(suivi.typeFonctionnalite.code ==
+ TemplateTypeFonctionnaliteEnum.BREVET.toString()) {
+ return TemplateTypeFonctionnaliteEnum.BREVET.getDescription()
+ }
+ else {
+ return suivi.periode
+ }
+ }
+
+ private List<StructureEnseignement> getClasses() {
+ return localStructureEnseignementService.
+ findAllClasseByEtablissement(etablissementCourant()).
+ sort {a, b -> cc.compare(a.code, b.code)}
+ }
+
+ private List getAllModeleDeNotes() {
+ return impressionTemplateDocumentService.findAllTemplateParEtabEtTypeFonctionnalites(
+ etablissementCourant(),
+ [
+ TemplateTypeFonctionnaliteEnum.BULLETIN_NOTES,
+ TemplateTypeFonctionnaliteEnum.RELEVE_NOTES,
+ TemplateTypeFonctionnaliteEnum.BREVET
+ ],
+ false
+ )
+ }
+
+ /**
+ * Gestion du breadCrumbs
+ */
+ protected List getBreadCrumbsInfo() {
+ List breadCrumbsInfo = super.getBreadCrumbsInfo()
+ breadCrumbsInfo << new BreadCrumbsItemInfo(
+ codeLabel: 'notes.menu.publipostage.titrePrincipal'
+ )
+ breadCrumbsInfo << new BreadCrumbsItemInfo(
+ codeLabel: 'notes.menu.publipostage.suiviParEleve.titrePrincipal'
+ )
+
+ return breadCrumbsInfo
+
+ }
+
+}