--- /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.domaine
+
+import org.lilie.services.eliot.notes.scolarite.NotesTypePeriodeService
+import org.lilie.services.eliot.notes.AbstractNotesController
+import grails.converters.JSON
+import org.lilie.services.eliot.scolarite.TypePeriode
+import org.lilie.services.eliot.scolarite.StructureEnseignement
+import org.lilie.services.eliot.scolarite.Service
+import org.lilie.services.eliot.scolarite.TypeIntervalleEnum
+import org.lilie.services.eliot.scolarite.Periode
+import org.lilie.services.eliot.notes.ActionEnum
+import org.lilie.services.eliot.notes.NotesDroitService
+import org.lilie.services.eliot.notes.NotesFonction
+
+/**
+ * @author bper
+ */
+class TypePeriodeController extends AbstractNotesController {
+
+ NotesDroitService notesDroitService
+ NotesTypePeriodeService notesTypePeriodeService
+
+ /**
+ * Returne la liste des type périodes de nature EXAMEN de l'établissement courrant
+ * @param idClasse
+ * @return List < TypePeriodeInfo >
+ * @author bper
+ */
+ def listeTypePeriodesExamen = {
+ Map result = tryCatch {
+ notesDroitService.verifieAutorisationByEtablissement(
+ securiteSession,
+ etablissementCourant(),
+ ActionEnum.CONSULTATION,
+ NotesFonction.DIRECTION_ASSIMILE
+ )
+
+ Long idClasse = Long.valueOf(params.idClasse)
+ StructureEnseignement classe = StructureEnseignement.get(idClasse)
+
+ // Récupère les TypePeriodes non affectés
+ List<TypePeriode> typePeriodes = notesTypePeriodeService.
+ getTypePeriodesExamenNonAffectes(securiteSession, classe)
+
+ // Récupère le TypePeriode actuallement selectinné
+ if (params.idTypePeriode) {
+ TypePeriode typePeriode = TypePeriode.get(Long.valueOf(params.idTypePeriode))
+ if (typePeriode) {
+ typePeriodes << typePeriode
+ }
+ }
+
+ // Crée la liste des typePeriodeInfos
+ List<TypePeriodeInfo> typePeriodeInfos = typePeriodes.collect {
+ TypePeriodeInfo typePeriodeInfo = new TypePeriodeInfo()
+ typePeriodeInfo.idTypePeriode = it.id
+ typePeriodeInfo.libelle = getTypePeriodeLibelle(it)
+ return typePeriodeInfo
+ }
+
+ // Trie les resultats par libellé
+ typePeriodeInfos.sort {a, b -> a.libelle.toLowerCase() <=> b.libelle.toLowerCase()}
+
+ return [typePeriodeInfos: typePeriodeInfos]
+ }
+
+ render result as JSON
+ }
+
+ /**
+ * Crée un type de période de nature EXAMEN
+ * @param libelle
+ * @author bper
+ */
+ def creerTypePeriode = {
+ Map result = tryCatch {
+ notesDroitService.verifieAutorisationByEtablissement(
+ securiteSession,
+ etablissementCourant(),
+ ActionEnum.CREATION,
+ NotesFonction.DIRECTION_ASSIMILE
+ )
+
+ TypePeriode typePeriode = notesTypePeriodeService.creeTypePeriodeExamen(
+ getSecuriteSession(),
+ etablissementCourant(),
+ params.libelle
+ )
+ return [idTypePeriode: typePeriode.id]
+ }
+
+ render result as JSON
+ }
+
+ /**
+ * Retourne la liste des types des périodes rattaché au service.
+ * Seulement les périodes évaluables sont retournées.
+ * @param idService
+ * @author bper
+ * @author msan
+ */
+ def listeTypePeriodesForService = {
+ Map result = getResultIfNullParams(['idService'])
+ if (!result) {
+ result = tryCatch {
+ notesDroitService.verifieAutorisationByEtablissement(
+ securiteSession,
+ etablissementCourant(),
+ ActionEnum.CONSULTATION,
+ (List) (NotesFonction.ENSEIGNANT_ASSIMILE +
+ NotesFonction.DIRECTION_ASSIMILE
+ )
+ )
+
+ Service service = Service.get(Long.valueOf(params.idService))
+
+ // Liste des périodes évaluables du service
+ List<TypePeriode> typePeriodes = notesTypePeriodeService.
+ findAllTypePeriodeForService(
+ securiteSession,
+ service,
+ true
+ )
+
+ // Récupère la pemiere période en cours du service
+ Periode periodeEnCours = service.relPeriodeServices.find {
+ it.periode.isPeriodeEnCours() && it.evaluable
+ }?.periode
+
+ // Récupère le type de période en cours et le type équivalent
+ TypePeriode typePeriodeEnCours = null
+ TypePeriode typePeriodeEquivEnCours = null
+ if (periodeEnCours) {
+ typePeriodeEnCours = periodeEnCours.typePeriode
+ typePeriodeEquivEnCours = notesTypePeriodeService.
+ getTypePeriodeEquivalent(typePeriodeEnCours)
+ }
+
+ // Enlève les types de période equivanlents
+ typePeriodes = notesTypePeriodeService.excludeTypePeriodesEquivalents(
+ typePeriodes,
+ TypeIntervalleEnum.TRIMESTRE)
+
+ List<TypePeriodeInfo> typePeriodeInfos = typePeriodes.collect {
+ TypePeriodeInfo typePeriodeInfo = new TypePeriodeInfo()
+ typePeriodeInfo.libelle = getTypePeriodeLibelle(it)
+ typePeriodeInfo.id = it.id
+ if (it.id == typePeriodeEnCours?.id || it.id == typePeriodeEquivEnCours?.id) {
+ typePeriodeInfo.isPeriodeEnCours = true
+ } else {
+ typePeriodeInfo.isPeriodeEnCours = false
+ }
+ return typePeriodeInfo
+ }
+
+ // Si aucune période évaluable est en cours, on marque la première
+ // comme en cours
+ if (periodeEnCours == null && typePeriodeInfos?.size() > 0) {
+ typePeriodeInfos.first().isPeriodeEnCours = true
+ }
+
+ return [typePeriodeInfos: typePeriodeInfos]
+ }
+ }
+ render result as JSON
+ }
+
+
+}