Apply standalone exercices settings
This commit is contained in:
parent
a1ce2df131
commit
398de21793
6 changed files with 63 additions and 1 deletions
|
|
@ -116,6 +116,29 @@ func (t *Team) Delete() (int64, error) {
|
|||
|
||||
// HasAccess checks if the Team has access to the given challenge.
|
||||
func (t *Team) HasAccess(e *Exercice) bool {
|
||||
// Case of standalone exercices
|
||||
if e.IdTheme == nil || *e.IdTheme == 0 {
|
||||
ord, err := e.GetOrdinal()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if ord < UnlockedStandaloneExercices {
|
||||
return true
|
||||
}
|
||||
|
||||
sc, err := t.SolvedCount()
|
||||
if sc == nil || err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if ord < UnlockedStandaloneExercices+int(UnlockedStandaloneExercicesByValidation*float64(*sc)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
if UnlockedChallengeDepth < 0 {
|
||||
return true
|
||||
}
|
||||
|
|
@ -297,6 +320,12 @@ func (t *Team) LastTryDist(e *Exercice) int64 {
|
|||
}
|
||||
}
|
||||
|
||||
// SolvedCount returns the number of solved exercices.
|
||||
func (t *Team) SolvedCount() (nb *int64, err error) {
|
||||
err = DBQueryRow("SELECT COUNT(*) FROM exercice_solved WHERE id_team = ?", t.Id).Scan(&nb)
|
||||
return
|
||||
}
|
||||
|
||||
// HasSolved checks if the Team already has validated the given challenge.
|
||||
// Note that the function also returns the effective validation timestamp.
|
||||
func (t *Team) HasSolved(e *Exercice) (tm *time.Time) {
|
||||
|
|
|
|||
Reference in a new issue