include id_theme in Exercice struct
This commit is contained in:
parent
69979ced1d
commit
78b6211b94
@ -34,7 +34,7 @@ func treatOpeningHint(pathname string, team fic.Team) {
|
|||||||
log.Println("[WRN]", err)
|
log.Println("[WRN]", err)
|
||||||
} else if lvl, err := exercice.GetLevel(); err != nil {
|
} else if lvl, err := exercice.GetLevel(); err != nil {
|
||||||
log.Println("[WRN]", err)
|
log.Println("[WRN]", err)
|
||||||
} else if theme, err := exercice.GetTheme(); err != nil {
|
} else if theme, err := fic.GetTheme(exercice.IdTheme); err != nil {
|
||||||
log.Println("[WRN]", err)
|
log.Println("[WRN]", err)
|
||||||
} else if _, err := fic.NewEvent(fmt.Sprintf("L'équipe %s a dévoilé un indice pour le <strong>%d<sup>e</sup></strong> défi %s !", team.Name, lvl, theme.Name), "alert-info"); err != nil {
|
} else if _, err := fic.NewEvent(fmt.Sprintf("L'équipe %s a dévoilé un indice pour le <strong>%d<sup>e</sup></strong> défi %s !", team.Name, lvl, theme.Name), "alert-info"); err != nil {
|
||||||
log.Println("[WRN] Unable to create event:", err)
|
log.Println("[WRN] Unable to create event:", err)
|
||||||
|
@ -44,7 +44,7 @@ func treatSubmission(pathname string, team fic.Team, exercice_id string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the corresponding theme
|
// Find the corresponding theme
|
||||||
theme, err := exercice.GetTheme()
|
theme, err := fic.GetTheme(exercice.IdTheme)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s [ERR] Unable to retrieve theme for exercice %d: %s\n", id, eid, err)
|
log.Printf("%s [ERR] Unable to retrieve theme for exercice %d: %s\n", id, eid, err)
|
||||||
return
|
return
|
||||||
|
@ -18,6 +18,7 @@ var PartialMCQValidation bool
|
|||||||
// Exercice represents a challenge inside a Theme.
|
// Exercice represents a challenge inside a Theme.
|
||||||
type Exercice struct {
|
type Exercice struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
|
IdTheme int64 `json:"id_theme"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
// URLid is used to reference the challenge from the URL path
|
// URLid is used to reference the challenge from the URL path
|
||||||
URLId string `json:"urlid"`
|
URLId string `json:"urlid"`
|
||||||
@ -50,7 +51,7 @@ type Exercice struct {
|
|||||||
// GetExercice retrieves the challenge with the given id.
|
// GetExercice retrieves the challenge with the given id.
|
||||||
func GetExercice(id int64) (Exercice, error) {
|
func GetExercice(id int64) (Exercice, error) {
|
||||||
var e Exercice
|
var e Exercice
|
||||||
if err := DBQueryRow("SELECT id_exercice, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, finished FROM exercices WHERE id_exercice = ?", id).Scan(&e.Id, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Finished); err != nil {
|
if err := DBQueryRow("SELECT id_exercice, id_theme, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, finished FROM exercices WHERE id_exercice = ?", id).Scan(&e.Id, &e.IdTheme, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Finished); err != nil {
|
||||||
return Exercice{}, err
|
return Exercice{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ func GetExercice(id int64) (Exercice, error) {
|
|||||||
// GetExercice retrieves the challenge with the given id.
|
// GetExercice retrieves the challenge with the given id.
|
||||||
func (t Theme) GetExercice(id int) (Exercice, error) {
|
func (t Theme) GetExercice(id int) (Exercice, error) {
|
||||||
var e Exercice
|
var e Exercice
|
||||||
if err := DBQueryRow("SELECT id_exercice, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, finished FROM exercices WHERE id_theme = ? AND id_exercice = ?", t.Id, id).Scan(&e.Id, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Finished); err != nil {
|
if err := DBQueryRow("SELECT id_exercice, id_theme, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, finished FROM exercices WHERE id_theme = ? AND id_exercice = ?", t.Id, id).Scan(&e.Id, &e.IdTheme, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Finished); err != nil {
|
||||||
return Exercice{}, err
|
return Exercice{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ func (t Theme) GetExercice(id int) (Exercice, error) {
|
|||||||
// GetExerciceByTitle retrieves the challenge with the given title.
|
// GetExerciceByTitle retrieves the challenge with the given title.
|
||||||
func (t Theme) GetExerciceByTitle(title string) (Exercice, error) {
|
func (t Theme) GetExerciceByTitle(title string) (Exercice, error) {
|
||||||
var e Exercice
|
var e Exercice
|
||||||
if err := DBQueryRow("SELECT id_exercice, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, finished FROM exercices WHERE id_theme = ? AND title = ?", t.Id, title).Scan(&e.Id, &e.Title, &t.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Finished); err != nil {
|
if err := DBQueryRow("SELECT id_exercice, id_theme, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, finished FROM exercices WHERE id_theme = ? AND title = ?", t.Id, title).Scan(&e.Id, &e.IdTheme, &e.Title, &t.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Finished); err != nil {
|
||||||
return Exercice{}, err
|
return Exercice{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ func (t Theme) GetExerciceByTitle(title string) (Exercice, error) {
|
|||||||
|
|
||||||
// GetExercices returns the list of all challenges present in the database.
|
// GetExercices returns the list of all challenges present in the database.
|
||||||
func GetExercices() ([]Exercice, error) {
|
func GetExercices() ([]Exercice, error) {
|
||||||
if rows, err := DBQuery("SELECT id_exercice, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, finished FROM exercices"); err != nil {
|
if rows, err := DBQuery("SELECT id_exercice, id_theme, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, finished FROM exercices"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
@ -87,7 +88,7 @@ func GetExercices() ([]Exercice, error) {
|
|||||||
var exos = make([]Exercice, 0)
|
var exos = make([]Exercice, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var e Exercice
|
var e Exercice
|
||||||
if err := rows.Scan(&e.Id, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Finished); err != nil {
|
if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Finished); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
exos = append(exos, e)
|
exos = append(exos, e)
|
||||||
@ -102,7 +103,7 @@ func GetExercices() ([]Exercice, error) {
|
|||||||
|
|
||||||
// GetExercices returns the list of all challenges in the Theme.
|
// GetExercices returns the list of all challenges in the Theme.
|
||||||
func (t Theme) GetExercices() ([]Exercice, error) {
|
func (t Theme) GetExercices() ([]Exercice, error) {
|
||||||
if rows, err := DBQuery("SELECT id_exercice, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, finished FROM exercices WHERE id_theme = ?", t.Id); err != nil {
|
if rows, err := DBQuery("SELECT id_exercice, id_theme, title, url_id, path, statement, overview, headline, issue, issue_kind, depend, gain, coefficient_cur, video_uri, finished FROM exercices WHERE id_theme = ?", t.Id); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
@ -110,7 +111,7 @@ func (t Theme) GetExercices() ([]Exercice, error) {
|
|||||||
var exos = make([]Exercice, 0)
|
var exos = make([]Exercice, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var e Exercice
|
var e Exercice
|
||||||
if err := rows.Scan(&e.Id, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Finished); err != nil {
|
if err := rows.Scan(&e.Id, &e.IdTheme, &e.Title, &e.URLId, &e.Path, &e.Statement, &e.Overview, &e.Headline, &e.Issue, &e.IssueKind, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI, &e.Finished); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
exos = append(exos, e)
|
exos = append(exos, e)
|
||||||
@ -216,21 +217,6 @@ func (e *Exercice) FixURLId() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetThemeId returns the theme's id for the Exercice.
|
|
||||||
func (e Exercice) GetThemeId() (tid int64, err error) {
|
|
||||||
err = DBQueryRow("SELECT id_theme FROM exercices WHERE id_exercice=?", e.Id).Scan(&tid)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTheme returns the parent Theme where the Exercice lives.
|
|
||||||
func (e Exercice) GetTheme() (Theme, error) {
|
|
||||||
if tid, err := e.GetThemeId(); err != nil {
|
|
||||||
return Theme{}, err
|
|
||||||
} else {
|
|
||||||
return GetTheme(tid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the challenge from the database.
|
// Delete the challenge from the database.
|
||||||
func (e Exercice) Delete() (int64, error) {
|
func (e Exercice) Delete() (int64, error) {
|
||||||
if res, err := DBExec("DELETE FROM exercices WHERE id_exercice = ?", e.Id); err != nil {
|
if res, err := DBExec("DELETE FROM exercices WHERE id_exercice = ?", e.Id); err != nil {
|
||||||
|
@ -97,9 +97,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||||||
for _, e := range exos {
|
for _, e := range exos {
|
||||||
if t == nil || t.HasAccess(e) {
|
if t == nil || t.HasAccess(e) {
|
||||||
exercice := myTeamExercice{}
|
exercice := myTeamExercice{}
|
||||||
if tid, err := e.GetThemeId(); err == nil {
|
exercice.ThemeId = e.IdTheme
|
||||||
exercice.ThemeId = tid
|
|
||||||
}
|
|
||||||
|
|
||||||
exercice.Statement = strings.Replace(e.Statement, "$FILES$", FilesDir, -1)
|
exercice.Statement = strings.Replace(e.Statement, "$FILES$", FilesDir, -1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user