@ -614,31 +614,21 @@ class ExerciseQuestionsController < ApplicationController
@exercise_current_user . update! ( ex_scores )
end
comments = params [ :comment ]
question_comment = @exercise_question . exercise_answer_comments & . first
if question_comment . present?
comment_option = {
:comment = > comments ,
:score = > @c_score ,
:exercise_answer_id = > ex_answers . present? ? ex_answers . first . id : nil ,
:user_id = > current_user . id
}
question_comment . update! ( comment_option )
@exercise_comments = question_comment
if @exercise_question . question_type == Exercise :: PRACTICAL
shixun_answer = ExerciseShixunAnswer . find_by ( exercise_question_id : @exercise_question . id , user_id : @user_id , exercise_shixun_challenge_id : @shixun_a_id )
answer_comment = shixun_answer & . exercise_answer_comments . take
else
ex_answer_comment_id = @exercise_question . exercise_answers . find_by ( user_id : @user_id ) . try ( :id )
comment_option = {
:user_id = > current_user . id ,
:comment = > comments ,
:score = > @c_score ,
:exercise_question_id = > @exercise_question . id ,
:exercise_shixun_answer_id = > @shixun_a_id . present? ? @shixun_a_id : nil ,
:exercise_answer_id = > ex_answer_comment_id
}
@exercise_comments = ExerciseAnswerComment . new ( comment_option )
@exercise_comments . save!
question_answer = ExerciseAnswer . find_by ( exercise_question_id : @exercise_question . id , user_id : @user_id )
answer_comment = question_answer & . exercise_answer_comments . take
end
# 给被评阅人发送消息,同一个教师评阅无需重复发消息
if answer_comment . present?
answer_comment . update! ( :comment = > comments , :score = > @c_score )
else
ExerciseAnswerComment . create! ( :comment = > comments , :score = > @c_score , :user_id = > current_user . id ,
:exercise_question_id = > @exercise_question . id , :exercise_shixun_answer_id = > shixun_answer & . id ,
:exercise_answer_id = > question_answer & . id )
unless Tiding . where ( user_id : @user_id , trigger_user_id : current_user . id , parent_container_id : @exercise . id , parent_container_type : " ExerciseScore " ) . exists?
Tiding . create! ( user_id : @user_id , trigger_user_id : current_user . id , container_id : @exercise . id ,
@ -646,8 +636,42 @@ class ExerciseQuestionsController < ApplicationController
parent_container_type : " ExerciseScore " , belong_container_id : @course . id ,
belong_container_type : 'Course' , tiding_type : " Exercise " )
end
end
# question_comment = @exercise_question.exercise_answer_comments&.first
#
# if question_comment.present?
# comment_option = {
# :comment => comments,
# :score => @c_score,
# :exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil,
# :user_id => current_user.id
# }
# question_comment.update!(comment_option)
# @exercise_comments = question_comment
# else
# ex_answer_comment_id = @exercise_question.exercise_answers.find_by(user_id: @user_id).try(:id)
# comment_option = {
# :user_id => current_user.id,
# :comment => comments,
# :score => @c_score,
# :exercise_question_id => @exercise_question.id,
# :exercise_shixun_answer_id => @shixun_a_id.present? ? @shixun_a_id : nil,
# :exercise_answer_id => ex_answer_comment_id
# }
# @exercise_comments = ExerciseAnswerComment.new(comment_option)
# @exercise_comments.save!
#
# # 给被评阅人发送消息,同一个教师评阅无需重复发消息
#
# unless Tiding.where(user_id: @user_id, trigger_user_id: current_user.id, parent_container_id: @exercise.id, parent_container_type: "ExerciseScore").exists?
# Tiding.create!(user_id: @user_id, trigger_user_id: current_user.id, container_id: @exercise.id,
# container_type: "Exercise", parent_container_id: @exercise.id,
# parent_container_type: "ExerciseScore", belong_container_id: @course.id,
# belong_container_type: 'Course', tiding_type: "Exercise")
# end
#
# end
end
end