Apply standalone exercices settings
This commit is contained in:
parent
a1ce2df131
commit
398de21793
6 changed files with 63 additions and 1 deletions
|
|
@ -420,6 +420,27 @@ func (e *Exercice) GetLevel() (int, error) {
|
|||
return nb, nil
|
||||
}
|
||||
|
||||
// GetOrdinal returns the position of the exercice in list (usefull for standalone exercices).
|
||||
func (e *Exercice) GetOrdinal() (int, error) {
|
||||
theme := &Theme{Id: 0}
|
||||
if e.IdTheme != nil {
|
||||
theme.Id = *e.IdTheme
|
||||
}
|
||||
|
||||
exercices, err := theme.GetExercices()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
for n, exercice := range exercices {
|
||||
if exercice.Id == e.Id {
|
||||
return n, nil
|
||||
}
|
||||
}
|
||||
|
||||
return 0, fmt.Errorf("exercice not found in theme")
|
||||
}
|
||||
|
||||
// NewTry registers a solving attempt for the given Team.
|
||||
func (e *Exercice) NewTry(t *Team, cksum []byte) error {
|
||||
if _, err := DBExec("INSERT INTO exercice_tries (id_exercice, id_team, time, cksum) VALUES (?, ?, ?, ?)", e.Id, t.Id, time.Now(), cksum); err != nil {
|
||||
|
|
|
|||
Reference in a new issue