Handle justified MCQ in admin and sync part
This commit is contained in:
parent
488a032eba
commit
d7553f0392
4 changed files with 62 additions and 28 deletions
|
@ -27,7 +27,7 @@ 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 ;
|
||||
+ `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) ;
|
||||
- `[[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 ;
|
||||
|
@ -221,5 +221,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 : 17 août 2018"
|
||||
date: "Dernière mise à jour du document : 27 novembre 2018"
|
||||
---
|
||||
|
|
|
@ -38,7 +38,7 @@ type ExerciceFlag struct {
|
|||
// ExerciceFlagMCQChoice holds a choice for an MCQ flag.
|
||||
type ExerciceFlagMCQChoice struct {
|
||||
Label string
|
||||
Value bool `toml:",omitempty"`
|
||||
Value interface{} `toml:",omitempty"`
|
||||
}
|
||||
|
||||
// ExerciceFlagMCQ holds information about a MCQ flag.
|
||||
|
|
|
@ -120,13 +120,39 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
|
|||
continue
|
||||
} else {
|
||||
hasOne := false
|
||||
isJustified := false
|
||||
for cid, choice := range quest.Choice {
|
||||
if _, err := flag.AddEntry(choice.Label, choice.Value); err != nil {
|
||||
var val bool
|
||||
if choice.Value == nil {
|
||||
val = false
|
||||
} else if p, ok := choice.Value.(bool); ok {
|
||||
val = p
|
||||
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 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
|
||||
}
|
||||
} 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 {
|
||||
errs = append(errs, fmt.Sprintf("%q: error in MCQ %d choice %d: %s", path.Base(exercice.Path), nline + 1, cid, err))
|
||||
continue
|
||||
}
|
||||
|
||||
if choice.Value {
|
||||
if val {
|
||||
hasOne = true
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue