candidate quiz progression work

This commit is contained in:
Mark Moser
2016-07-29 13:34:23 -05:00
parent a901186a74
commit 5be93e0d38
4 changed files with 44 additions and 8 deletions

View File

@ -24,7 +24,7 @@ class CandidateQuiz
inner join questions q on q.quiz_id = c.quiz_id
left join answers a on a.candidate_id = c.id AND a.question_id = q.id
where q.active = true and c.id = #{candidate_id} #{question}
order by c.id, q.sort;"
order by q.sort;"
ActiveRecord::Base.connection.exec_query(sql)
end
end

View File

@ -27,4 +27,16 @@ class QuizStatus
(answs / total * 100).round.to_i
end
def current_question_id
sql = "select q.id question_id
from candidates c
inner join questions q on q.quiz_id = c.quiz_id
left join answers a on a.candidate_id = c.id AND a.question_id = q.id
where q.active = true and c.id = #{candidate.to_i}
and (a.id is null OR a.submitted is false)
order by q.sort limit 1;"
result = ActiveRecord::Base.connection.exec_query(sql).to_hash.first
result['question_id'] unless result.nil?
end
end