libfic/mcq: remove Kind, as we can only handle checkbox; another kind of record should be created to handle select/radio

This commit is contained in:
nemunaire 2017-12-17 16:28:31 +01:00
parent eee1558dd9
commit 4052969304
4 changed files with 11 additions and 20 deletions

View File

@ -71,7 +71,7 @@ func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
// Unique Choice Questions (checkbox)
if ucq, err := getFileContent(i, path.Join(exercice.Path, "flags-ucq.txt")); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to read ucq: %s", path.Base(exercice.Path), err))
} else if flag, err := exercice.AddMCQ("", "checkbox"); err != nil {
} else if flag, err := exercice.AddMCQ(""); err != nil {
errs = append(errs, fmt.Sprintf("%q: unable to add ucq: %s", path.Base(exercice.Path), err))
} else {
for nline, quest := range strings.Split(ucq, "\n") {
@ -107,7 +107,7 @@ func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
continue
}
if flag, err := exercice.AddMCQ(quest_splt[0], "radio"); err != nil {
if flag, err := exercice.AddMCQ(quest_splt[0]); err != nil {
errs = append(errs, fmt.Sprintf("%q: error in mcq file at line %d: %s", path.Base(exercice.Path), nline + 1, err))
continue
} else {
@ -130,13 +130,7 @@ func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
}
if choice[0] == 49 {
if hasOne {
flag.Kind = "checkbox"
flag.Update()
errs = append(errs, fmt.Sprintf("%q: warning in mcq file at line %d: multiple expected response, switching to ucq-like quiz; is this really expected?", path.Base(exercice.Path), nline + 1))
} else {
hasOne = true
}
hasOne = true
}
}
if !hasOne {

View File

@ -147,7 +147,6 @@ CREATE TABLE IF NOT EXISTS exercice_mcq(
id_mcq INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
id_exercice INTEGER NOT NULL,
title VARCHAR(255) NOT NULL,
kind ENUM('checkbox', 'radio', 'select') NOT NULL,
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice)
);
`); err != nil {

View File

@ -8,7 +8,6 @@ type MCQ struct {
Id int64 `json:"id"`
IdExercice int64 `json:"idExercice"`
Title string `json:"title"`
Kind string `json:"kind"`
Entries []MCQ_entry `json:"entries"`
}
@ -19,7 +18,7 @@ type MCQ_entry struct {
}
func (e Exercice) GetMCQ() ([]MCQ, error) {
if rows, err := DBQuery("SELECT id_mcq, id_exercice, title, kind FROM exercice_mcq WHERE id_exercice = ?", e.Id); err != nil {
if rows, err := DBQuery("SELECT id_mcq, id_exercice, title FROM exercice_mcq WHERE id_exercice = ?", e.Id); err != nil {
return nil, err
} else {
defer rows.Close()
@ -29,7 +28,7 @@ func (e Exercice) GetMCQ() ([]MCQ, error) {
var m MCQ
m.IdExercice = e.Id
if err := rows.Scan(&m.Id, &m.IdExercice, &m.Title, &m.Kind); err != nil {
if err := rows.Scan(&m.Id, &m.IdExercice, &m.Title); err != nil {
return nil, err
}
@ -59,18 +58,18 @@ func (e Exercice) GetMCQ() ([]MCQ, error) {
}
}
func (e Exercice) AddMCQ(title string, kind string) (MCQ, error) {
if res, err := DBExec("INSERT INTO exercice_mcq (id_exercice, title, kind) VALUES (?, ?, ?)", e.Id, title, kind); err != nil {
func (e Exercice) AddMCQ(title string) (MCQ, error) {
if res, err := DBExec("INSERT INTO exercice_mcq (id_exercice, title) VALUES (?, ?)", e.Id, title); err != nil {
return MCQ{}, err
} else if qid, err := res.LastInsertId(); err != nil {
return MCQ{}, err
} else {
return MCQ{qid, e.Id, title, kind, []MCQ_entry{}}, nil
return MCQ{qid, e.Id, title, []MCQ_entry{}}, nil
}
}
func (m MCQ) Update() (int64, error) {
if res, err := DBExec("UPDATE exercice_mcq SET id_exercice = ?, title = ?, kind = ? WHERE id_mcq = ?", m.IdExercice, m.Title, m.Kind, m.Id); err != nil {
if res, err := DBExec("UPDATE exercice_mcq SET id_exercice = ?, title = ? WHERE id_mcq = ?", m.IdExercice, m.Title, m.Id); err != nil {
return 0, err
} else if nb, err := res.RowsAffected(); err != nil {
return 0, err

View File

@ -23,7 +23,6 @@ type myTeamHint struct {
}
type myTeamMCQ struct {
Title string `json:"title"`
Kind string `json:"kind"`
Choices map[int64]string `json:"choices,omitempty"`
Solved *time.Time `json:"solved,omitempty"`
}
@ -145,9 +144,9 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
choices[e.Id] = e.Label
}
if t == nil {
exercice.MCQs = append(exercice.MCQs, myTeamMCQ{mcq.Title, mcq.Kind, choices, nil})
exercice.MCQs = append(exercice.MCQs, myTeamMCQ{mcq.Title, choices, nil})
} else {
exercice.MCQs = append(exercice.MCQs, myTeamMCQ{mcq.Title, mcq.Kind, choices, t.HasPartiallyRespond(mcq)})
exercice.MCQs = append(exercice.MCQs, myTeamMCQ{mcq.Title, choices, t.HasPartiallyRespond(mcq)})
}
}
}