Utilise a new field to send justifications instead of too complex guessing crap

This commit is contained in:
nemunaire 2018-11-28 07:39:50 +01:00
commit d40922629b
6 changed files with 69 additions and 24 deletions

View file

@ -66,6 +66,35 @@ func (e Exercice) GetMCQ() ([]MCQ, error) {
}
}
// GetMCQbyChoice returns the MCQ corresponding to a choice ID.
func GetMCQbyChoice(cid int64) (m MCQ, c MCQ_entry, err error) {
if errr := DBQueryRow("SELECT id_mcq, id_exercice, title FROM exercice_mcq WHERE id_mcq = (SELECT id_mcq FROM mcq_entries WHERE id_mcq_entry = ?)", cid).Scan(&m.Id, &m.IdExercice, &m.Title); err != nil {
return MCQ{}, MCQ_entry{}, errr
}
if entries_rows, errr := DBQuery("SELECT id_mcq_entry, label, response FROM mcq_entries WHERE id_mcq = ?", m.Id); err != nil {
return MCQ{}, MCQ_entry{}, errr
} else {
defer entries_rows.Close()
for entries_rows.Next() {
var e MCQ_entry
if err = entries_rows.Scan(&e.Id, &e.Label, &e.Response); err != nil {
return
}
if e.Id == cid {
c = e
}
m.Entries = append(m.Entries, e)
}
}
return
}
// AddMCQ creates and fills a new struct MCQ and registers it into the database.
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 {
@ -145,6 +174,11 @@ func (e Exercice) WipeMCQs() (int64, error) {
}
}
// GetJustifiedFlag searchs for a flag in the scope of the given exercice.
func (m MCQ) GetJustifiedFlag(e Exercice, c MCQ_entry) (Flag, error) {
return e.GetFlagByLabel("%" + m.Title + "%" + c.Label)
}
// Check if the given vals are the expected ones to validate this flag.
func (m MCQ) Check(vals map[int64]bool) int {
diff := 0