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:
parent
eee1558dd9
commit
4052969304
@ -71,7 +71,7 @@ func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
|
|||||||
// Unique Choice Questions (checkbox)
|
// Unique Choice Questions (checkbox)
|
||||||
if ucq, err := getFileContent(i, path.Join(exercice.Path, "flags-ucq.txt")); err != nil {
|
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))
|
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))
|
errs = append(errs, fmt.Sprintf("%q: unable to add ucq: %s", path.Base(exercice.Path), err))
|
||||||
} else {
|
} else {
|
||||||
for nline, quest := range strings.Split(ucq, "\n") {
|
for nline, quest := range strings.Split(ucq, "\n") {
|
||||||
@ -107,7 +107,7 @@ func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
|
|||||||
continue
|
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))
|
errs = append(errs, fmt.Sprintf("%q: error in mcq file at line %d: %s", path.Base(exercice.Path), nline + 1, err))
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
@ -130,13 +130,7 @@ func SyncExerciceMCQ(i Importer, exercice fic.Exercice) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if choice[0] == 49 {
|
if choice[0] == 49 {
|
||||||
if hasOne {
|
hasOne = true
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !hasOne {
|
if !hasOne {
|
||||||
|
@ -147,7 +147,6 @@ CREATE TABLE IF NOT EXISTS exercice_mcq(
|
|||||||
id_mcq INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
id_mcq INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
id_exercice INTEGER NOT NULL,
|
id_exercice INTEGER NOT NULL,
|
||||||
title VARCHAR(255) NOT NULL,
|
title VARCHAR(255) NOT NULL,
|
||||||
kind ENUM('checkbox', 'radio', 'select') NOT NULL,
|
|
||||||
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice)
|
FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice)
|
||||||
);
|
);
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
|
@ -8,7 +8,6 @@ type MCQ struct {
|
|||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
IdExercice int64 `json:"idExercice"`
|
IdExercice int64 `json:"idExercice"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Kind string `json:"kind"`
|
|
||||||
Entries []MCQ_entry `json:"entries"`
|
Entries []MCQ_entry `json:"entries"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ type MCQ_entry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e Exercice) GetMCQ() ([]MCQ, error) {
|
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
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
@ -29,7 +28,7 @@ func (e Exercice) GetMCQ() ([]MCQ, error) {
|
|||||||
var m MCQ
|
var m MCQ
|
||||||
m.IdExercice = e.Id
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,18 +58,18 @@ func (e Exercice) GetMCQ() ([]MCQ, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e Exercice) AddMCQ(title string, kind string) (MCQ, error) {
|
func (e Exercice) AddMCQ(title string) (MCQ, error) {
|
||||||
if res, err := DBExec("INSERT INTO exercice_mcq (id_exercice, title, kind) VALUES (?, ?, ?)", e.Id, title, kind); err != nil {
|
if res, err := DBExec("INSERT INTO exercice_mcq (id_exercice, title) VALUES (?, ?)", e.Id, title); err != nil {
|
||||||
return MCQ{}, err
|
return MCQ{}, err
|
||||||
} else if qid, err := res.LastInsertId(); err != nil {
|
} else if qid, err := res.LastInsertId(); err != nil {
|
||||||
return MCQ{}, err
|
return MCQ{}, err
|
||||||
} else {
|
} 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) {
|
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
|
return 0, err
|
||||||
} else if nb, err := res.RowsAffected(); err != nil {
|
} else if nb, err := res.RowsAffected(); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -23,7 +23,6 @@ type myTeamHint struct {
|
|||||||
}
|
}
|
||||||
type myTeamMCQ struct {
|
type myTeamMCQ struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Kind string `json:"kind"`
|
|
||||||
Choices map[int64]string `json:"choices,omitempty"`
|
Choices map[int64]string `json:"choices,omitempty"`
|
||||||
Solved *time.Time `json:"solved,omitempty"`
|
Solved *time.Time `json:"solved,omitempty"`
|
||||||
}
|
}
|
||||||
@ -145,9 +144,9 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||||||
choices[e.Id] = e.Label
|
choices[e.Id] = e.Label
|
||||||
}
|
}
|
||||||
if t == nil {
|
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 {
|
} 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)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user