admin: new form to update history coefficient
This commit is contained in:
parent
2b75287d16
commit
ba5642da8f
5 changed files with 174 additions and 4 deletions
|
@ -56,6 +56,37 @@ func (e Exercice) GetHistory() ([]map[string]interface{}, error) {
|
|||
return hist, nil
|
||||
}
|
||||
|
||||
// UpdateHistoryItem sets values an entry from the history.
|
||||
func (e Exercice) UpdateHistoryItem(coeff float32, tId int64, kind string, h time.Time, secondary *int64) (interface{}, error) {
|
||||
if kind == "hint" && secondary != nil {
|
||||
if res, err := DBExec("UPDATE team_hints SET coefficient = ?, time = ? WHERE id_team = ? AND time = ? AND id_hint = ?", coeff, h, tId, h, *secondary); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
return nb, err
|
||||
}
|
||||
} else if kind == "wchoices" && secondary != nil {
|
||||
if res, err := DBExec("UPDATE team_wchoices SET coefficient = ?, time = ? WHERE id_team = ? AND time = ? AND id_flag = ?", coeff, h, tId, h, *secondary); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
return nb, err
|
||||
}
|
||||
} else if kind == "solved" {
|
||||
if res, err := DBExec("UPDATE exercice_solved SET coefficient = ?, time = ? WHERE id_team = ? AND time = ? AND id_exercice = ?", coeff, h, tId, h, e.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
return nb, err
|
||||
}
|
||||
} else {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
// DelHistoryItem removes from the database an entry from the history.
|
||||
func (e Exercice) DelHistoryItem(tId int64, kind string, h time.Time, secondary *int64) (interface{}, error) {
|
||||
if kind == "tries" {
|
||||
|
|
Reference in a new issue