New option to allow teams to self reset their progression
This commit is contained in:
parent
a0c34018cf
commit
d6ff46ca7f
9 changed files with 173 additions and 3 deletions
|
|
@ -139,3 +139,47 @@ func (t *Team) DelHistoryItem(kind string, h time.Time, primary *int64, secondar
|
|||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ResetProgressionOnExercice removes all tries and validations for a given Exercice.
|
||||
func (t *Team) ResetProgressionOnExercice(exercice *Exercice) error {
|
||||
hints, err := exercice.GetHints()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
flags, err := exercice.GetFlags()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := DBExec("DELETE FROM exercice_tries WHERE id_team = ? AND id_exercice = ?", t.Id, exercice.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := DBExec("DELETE FROM exercice_solved WHERE id_team = ? AND id_exercice = ?", t.Id, exercice.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, hint := range hints {
|
||||
if _, err := DBExec("DELETE FROM team_hints WHERE id_team = ? AND id_hint = ?", t.Id, hint.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for _, flag := range flags {
|
||||
if k, ok := flag.(*FlagKey); ok {
|
||||
if _, err := DBExec("DELETE FROM team_wchoices WHERE id_team = ? AND id_flag = ?", t.Id, k.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := DBExec("DELETE FROM flag_found WHERE id_team = ? AND id_flag = ?", t.Id, k.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if mcq, ok := flag.(*MCQ); ok {
|
||||
if _, err := DBExec("DELETE FROM mcq_found WHERE id_team = ? AND id_mcq = ?", t.Id, mcq.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue