Add new helper string related to justified MCQ flag

This commit is contained in:
nemunaire 2018-12-02 04:52:15 +01:00
parent 11e0b46034
commit c5b65289d3
10 changed files with 122 additions and 70 deletions

View file

@ -28,7 +28,8 @@ Tous les textes doivent utiliser l'encodage UTF8.
* `label = "Intitulé du groupe"` : (facultatif) intitulé du groupe de choix ;
* `[[flag_mcq.choice]]` : représente un choix, répétez autant de fois qu'il y a de choix :
+ `label = "Intitulé de la réponse"`,
+ `value = true` : (facultatif, par défaut `false`) valeur attendue pour ce choix ; pour un QCM justifié, utilisez une chaîne de caractères (notez qu'il n'est pas possible de combiner des réponses vraies justifiées et justifiées) ;
+ `value = true` : (facultatif, par défaut `false`) valeur attendue pour ce choix ; pour un QCM justifié, utilisez une chaîne de caractères (notez qu'il n'est pas possible de combiner des réponses vraies justifiées et justifiées),
+ `help = "Flag correspondant"` : (facultatif) indication affichée dans le champ de texte des QCM justifiés ;
- `[[flag_ucq]]` : drapeau sous forme de question à choix unique :
* `label = "Intitulé du groupe"` : (facultatif) intitulé du groupe de choix ;
* `raw = 'MieH2athxuPhai6u'` : drapeau attendu parmi les propositions ;
@ -222,5 +223,5 @@ Exemple `DIGESTS.txt` {#exemple-digeststxt}
---
title: Format des répertoires pour la synchronisation
author: FIC team 2019
date: "Dernière mise à jour du document : 27 novembre 2018"
date: "Dernière mise à jour du document : 1 décembre 2018"
---

View file

@ -39,6 +39,7 @@ type ExerciceFlag struct {
type ExerciceFlagMCQChoice struct {
Label string
Value interface{} `toml:",omitempty"`
Help string `toml:",omitempty"`
}
// ExerciceFlagMCQ holds information about a MCQ flag.

View file

@ -123,33 +123,44 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
isJustified := false
for cid, choice := range quest.Choice {
var val bool
var justify string
if choice.Value == nil {
val = false
} else if p, ok := choice.Value.(bool); ok {
val = p
if len(choice.Help) > 0 {
errs = append(errs, fmt.Sprintf("%q: error MCQ #%d: help field has to be used only with justified mcq.", path.Base(exercice.Path), nline + 1))
continue
}
if isJustified {
errs = append(errs, fmt.Sprintf("%q: error MCQ #%d: all true items has to be justified in this MCQ.", path.Base(exercice.Path), nline + 1))
continue
}
} else if p, ok := choice.Value.(string); ok {
val = true
if len(choice.Help) == 0 {
choice.Help = "Flag correspondant"
}
if hasOne && !isJustified {
errs = append(errs, fmt.Sprintf("%q: error MCQ #%d: all true items has to be justified in this MCQ.", path.Base(exercice.Path), nline + 1))
continue
}
isJustified = true
if _, err := exercice.AddRawFlag("%" + quest.Label + "%" + choice.Label, "", false, nil, []byte(p)); err != nil {
errs = append(errs, fmt.Sprintf("%q: error MCQ #%d: %s", path.Base(exercice.Path), nline + 1, err))
continue
}
justify = p
} else {
errs = append(errs, fmt.Sprintf("%q: error in MCQ %d choice %d: has an invalid type. Expected true, false or a string", path.Base(exercice.Path), nline + 1, cid))
continue
}
if _, err := flag.AddEntry(choice.Label, val); err != nil {
if e, err := flag.AddEntry(choice.Label, val); err != nil {
errs = append(errs, fmt.Sprintf("%q: error in MCQ %d choice %d: %s", path.Base(exercice.Path), nline + 1, cid, err))
continue
} else if len(justify) > 0 {
if _, err := exercice.AddRawFlag(fmt.Sprintf("%%%d%%%s", e.Id, choice.Help), "", false, nil, []byte(justify)); err != nil {
errs = append(errs, fmt.Sprintf("%q: error MCQ #%d: %s", path.Base(exercice.Path), nline + 1, err))
continue
}
}
if val {