-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathanswers_controller.rb
More file actions
62 lines (54 loc) · 2.38 KB
/
answers_controller.rb
File metadata and controls
62 lines (54 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true
class Course::Statistics::AnswersController < Course::Statistics::Controller
helper Course::Assessment::Submission::SubmissionsHelper.name.sub(/Helper$/, '')
load_resource :answer, class: 'Course::Assessment::Answer', only: :show
def show
@submission = @answer.submission
@assessment = @submission.assessment
@question = @answer.question
end
def all_answers
@submission_question = Course::Assessment::SubmissionQuestion.
where(
submission_id: all_answers_params[:submission_id],
question_id: all_answers_params[:question_id]
).
includes(actable: { files: { annotations:
{ discussion_topic: { posts: :codaveri_feedback } } } },
discussion_topic: { posts: :codaveri_feedback }).first
@all_answers = Course::Assessment::Answer.
unscope(:order).
order(:created_at).
where(
submission_id: all_answers_params[:submission_id],
question_id: all_answers_params[:question_id]
).
where.not(workflow_state: :attempting)
@question = Course::Assessment::Question.find(all_answers_params[:question_id])
assessment_id = Course::QuestionAssessment.where(question_id: @question.id).first.assessment_id
@assessment = Course::Assessment.find(assessment_id)
@submission = Course::Assessment::Submission.find(all_answers_params[:submission_id])
fetch_all_actable_questions(@question)
end
private
def all_answers_params
params.permit(:submission_id, :question_id)
end
def fetch_all_actable_questions(question)
unless versioned_question?(question)
@all_actable_questions = [question.actable]
return
end
question = question.actable
@all_actable_questions = [question]
while question.parent
@all_actable_questions << question.parent
question = question.parent
end
end
# at the moment, we only support versioning for Programming Question. In the future, we might extend the support
# for all auto-gradable questions, such as MCQ/MRQ.
def versioned_question?(question)
question.actable.is_a?(Course::Assessment::Question::Programming)
end
end