Files can now depends on MCQ
This commit is contained in:
parent
823328ead2
commit
e937073588
8 changed files with 90 additions and 28 deletions
|
|
@ -263,7 +263,9 @@ func (f EFile) Delete() (int64, error) {
|
|||
|
||||
// WipeFiles deletes (only in the database, not on disk) files coming with the challenge.
|
||||
func (e Exercice) WipeFiles() (int64, error) {
|
||||
if _, err := DBExec("DELETE FROM exercice_files_deps WHERE id_flag IN (SELECT id_flag FROM exercice_flags WHERE id_exercice = ?)", e.Id); err != nil {
|
||||
if _, err := DBExec("DELETE FROM exercice_files_okey_deps WHERE id_flag IN (SELECT id_flag FROM exercice_flags WHERE id_exercice = ?)", e.Id); err != nil {
|
||||
return 0, err
|
||||
} else if _, err := DBExec("DELETE FROM exercice_files_omcq_deps WHERE id_mcq IN (SELECT id_mcq FROM exercice_mcq WHERE id_exercice = ?)", e.Id); err != nil {
|
||||
return 0, err
|
||||
} else if res, err := DBExec("DELETE FROM exercice_files WHERE id_exercice = ?", e.Id); err != nil {
|
||||
return 0, err
|
||||
|
|
@ -293,7 +295,9 @@ func (f EFile) GetOrigin() string {
|
|||
// AddDepend insert a new dependency to a given flag.
|
||||
func (f EFile) AddDepend(j Flag) (err error) {
|
||||
if k, ok := j.(FlagKey); ok {
|
||||
_, err = DBExec("INSERT INTO exercice_files_deps (id_file, id_flag) VALUES (?, ?)", f.Id, k.Id)
|
||||
_, err = DBExec("INSERT INTO exercice_files_okey_deps (id_file, id_flag) VALUES (?, ?)", f.Id, k.Id)
|
||||
} else if m, ok := j.(MCQ); ok {
|
||||
_, err = DBExec("INSERT INTO exercice_files_omcq_deps (id_file, id_mcq) VALUES (?, ?)", f.Id, m.Id)
|
||||
} else {
|
||||
err = errors.New("Dependancy type not implemented for this file.")
|
||||
}
|
||||
|
|
@ -303,7 +307,9 @@ func (f EFile) AddDepend(j Flag) (err error) {
|
|||
// DeleteDepend insert a new dependency to a given flag.
|
||||
func (f EFile) DeleteDepend(j Flag) (err error) {
|
||||
if k, ok := j.(FlagKey); ok {
|
||||
_, err = DBExec("DELETE FROM exercice_files_deps WHERE id_file = ? AND id_flag = ?", f.Id, k.Id)
|
||||
_, err = DBExec("DELETE FROM exercice_files_okey_deps WHERE id_file = ? AND id_flag = ?", f.Id, k.Id)
|
||||
} else if m, ok := j.(MCQ); ok {
|
||||
_, err = DBExec("DELETE FROM exercice_files_omcq_deps WHERE id_file = ? AND id_mcq = ?", f.Id, m.Id)
|
||||
} else {
|
||||
err = errors.New("Dependancy type not implemented for this file.")
|
||||
}
|
||||
|
|
@ -312,12 +318,13 @@ func (f EFile) DeleteDepend(j Flag) (err error) {
|
|||
|
||||
// GetDepends retrieve the flag's dependency list.
|
||||
func (f EFile) GetDepends() ([]Flag, error) {
|
||||
if rows, err := DBQuery("SELECT id_flag FROM exercice_files_deps WHERE id_file = ?", f.Id); err != nil {
|
||||
var deps = make([]Flag, 0)
|
||||
|
||||
if rows, err := DBQuery("SELECT id_flag FROM exercice_files_okey_deps WHERE id_file = ?", f.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
var deps = make([]Flag, 0)
|
||||
for rows.Next() {
|
||||
var d int64
|
||||
if err := rows.Scan(&d); err != nil {
|
||||
|
|
@ -328,9 +335,26 @@ func (f EFile) GetDepends() ([]Flag, error) {
|
|||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return deps, nil
|
||||
}
|
||||
|
||||
if rows, err := DBQuery("SELECT id_mcq FROM exercice_files_omcq_deps WHERE id_file = ?", f.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var d int64
|
||||
if err := rows.Scan(&d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
deps = append(deps, MCQ{d, f.IdExercice, "", []MCQ_entry{}})
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return deps, nil
|
||||
}
|
||||
|
||||
// CheckFileOnDisk recalculates the hash of the file on disk.
|
||||
|
|
|
|||
Reference in a new issue