实训作业查看答案

chromesetting
cxt 5 years ago
parent 7ad3538839
commit baec0f86d7

@ -119,6 +119,12 @@ class Game < ApplicationRecord
# self.outputs.pluck(:query_index).first
#end
# 是否查看了答案(通关的是否在通关前看的答案)
def view_answer
answer_exists = Grade.exists?("container_type = 'Answer' and container_id = #{id} and created_at < '#{end_time}'")
answer_open != 0 ? (status == 2 ? answer_exists : true) : false
end
# 用户关卡得分
def get_user_final_score

@ -83,9 +83,10 @@ class Myshixun < ApplicationRecord
self.games.select{|game| game.status == 2}.size
end
# 查看答案的关卡数
# 查看答案的关卡数,只统计通关前看的关卡
def view_answer_count
self.games.select{|game| game.status == 2 && game.answer_open != 0}.size
answer_ids = user.grades.joins("join games on grades.container_id = games.id").where("container_type = 'Answer' and games.status=2 and games.end_time > grades.created_at").pluck(:container_id)
self.games.select{|game| game.status == 2 && game.answer_open != 0 && answer_ids.include?(game.id)}.size
end
# 通关时间

@ -42,7 +42,7 @@ if @shixun
json.challenge_comment challenge_comment&.comment
json.challenge_comment_hidden @user_course_identity < Course::STUDENT ? challenge_comment&.hidden_comment : nil
json.comment_id challenge_comment&.id
json.view_answer game ? game.answer_open != 0 : 0
json.view_answer game ? game.view_answer : false
end
end

Loading…
Cancel
Save