@ -12,10 +12,10 @@ class ExercisesController < ApplicationController
before_action :get_exercise_question_counts , only : [ :show , :edit , :start_answer , :review_exercise , :blank_exercise , :export_exercise ]
before_action :get_exercise_question_counts , only : [ :show , :edit , :start_answer , :review_exercise , :blank_exercise , :export_exercise ]
before_action :validate_publish_time , only : [ :commit_setting ] #提交设置时,需判断时间是否符合
before_action :validate_publish_time , only : [ :commit_setting ] #提交设置时,需判断时间是否符合
before_action :check_course_public , only : [ :set_public ]
before_action :check_course_public , only : [ :set_public ]
before_action :check_user_on_answer , only : [ :show , :start_answer , : commit_exercise, : exercise_lists] #判断当前用户在试卷的权限/老师是否属于分班的权限
before_action :check_user_on_answer , only : [ :show , :start_answer , : exercise_lists] #判断当前用户在试卷的权限/老师是否属于分班的权限
before_action :only_student_in , only : [ :start_answer ]
before_action :only_student_in , only : [ :start_answer ]
before_action :check_user_id_start_answer , only : [ :start_answer , :review_exercise ]
before_action :check_user_id_start_answer , only : [ :start_answer , :review_exercise ]
before_action :commit_user_exercise , only : [ :start_answer , :exercise_lists , :review_exercise ] #判断试卷时间到用户是否提交
# before_action :commit_user_exercise,only: [:start_answer,:exercise_lists,:review_exercise] #已有定时的任务
before_action :check_exercise_time , only : [ :commit_exercise ] #提交试卷时,判断时间是否超过
before_action :check_exercise_time , only : [ :commit_exercise ] #提交试卷时,判断时间是否超过
before_action :check_exercise_status , only : [ :redo_modal , :redo_exercise ]
before_action :check_exercise_status , only : [ :redo_modal , :redo_exercise ]
before_action :check_exercise_is_end , only : [ :review_exercise ]
before_action :check_exercise_is_end , only : [ :review_exercise ]
@ -32,13 +32,13 @@ class ExercisesController < ApplicationController
@exercises_all = @course . exercises
@exercises_all = @course . exercises
member_show_exercises = @exercises_all . is_exercise_published #已发布的或已截止的试卷
member_show_exercises = @exercises_all . is_exercise_published #已发布的或已截止的试卷
@current_user_ = current_user
@current_user_ = current_user
@exercises_count = @exercises_all . count # 全部页面,需返回
@exercises_count = @exercises_all . size # 全部页面,需返回
@exercises_unpublish_counts = @exercises_all . exercise_by_status ( 1 ) . count #未发布的试卷数
@exercises_unpublish_counts = @exercises_all . exercise_by_status ( 1 ) . size #未发布的试卷数
@exercises_published_counts = @exercises_all . exercise_by_status ( [ 2 , 3 ] ) . count # 已发布的试卷数,包含已截止的
@exercises_published_counts = @exercises_all . exercise_by_status ( [ 2 , 3 ] ) . size # 已发布的试卷数,包含已截止的
@exercises_ended_counts = @exercises_all . exercise_by_status ( 3 ) . count #已截止的试卷数
@exercises_ended_counts = @exercises_all . exercise_by_status ( 3 ) . size #已截止的试卷数
# 课堂的学生人数
# 课堂的学生人数
@course_all_members = @course . students #当前课堂的全部学生
@course_all_members = @course . students #当前课堂的全部学生
@course_all_members_count = @course_all_members . count #当前课堂的学生数
@course_all_members_count = @course_all_members . size #当前课堂的学生数
@current_student = @course_all_members . course_find_by_ids ( " user_id " , current_user . id ) #当前用户是否为课堂的学生
@current_student = @course_all_members . course_find_by_ids ( " user_id " , current_user . id ) #当前用户是否为课堂的学生
# exercises的不同用户群体的显示
# exercises的不同用户群体的显示
@ -64,7 +64,7 @@ class ExercisesController < ApplicationController
@is_teacher_or = 0
@is_teacher_or = 0
@exercises = member_show_exercises . present? ? member_show_exercises . unified_setting : [ ]
@exercises = member_show_exercises . present? ? member_show_exercises . unified_setting : [ ]
end
end
if @exercises . count > 0
if @exercises . size > 0
if params [ :type ] . present?
if params [ :type ] . present?
choose_type = params [ :type ] . to_i
choose_type = params [ :type ] . to_i
member_group_id = @current_student . first . try ( :course_group_id ) . to_i
member_group_id = @current_student . first . try ( :course_group_id ) . to_i
@ -321,7 +321,7 @@ class ExercisesController < ApplicationController
begin
begin
check_ids = Exercise . where ( id : params [ :check_ids ] )
check_ids = Exercise . where ( id : params [ :check_ids ] )
check_ids . each do | exercise |
check_ids . each do | exercise |
current_ex_bank = current_user . exercise_banks . find_by_container ( exercise . id , " Exercise " ) .first
current_ex_bank = current_user . exercise_banks . find_by_container ( exercise . id , " Exercise " ) & .first
if current_ex_bank . present? #当前用户的选择试卷是否已加入习题库,存在则更新习题库和问题库,否则新建习题库和问题库
if current_ex_bank . present? #当前用户的选择试卷是否已加入习题库,存在则更新习题库和问题库,否则新建习题库和问题库
ex_params = {
ex_params = {
:name = > exercise . exercise_name ,
:name = > exercise . exercise_name ,
@ -402,7 +402,7 @@ class ExercisesController < ApplicationController
:position = > c . position ,
:position = > c . position ,
:challenge_id = > c . challenge_id ,
:challenge_id = > c . challenge_id ,
:shixun_id = > q . shixun_id ,
:shixun_id = > q . shixun_id ,
:question_score = > q . question_score
:question_score = > c . question_score
}
}
shixun_challenge_bank = exercise_bank_question . exercise_bank_shixun_challenges . new challenge_option
shixun_challenge_bank = exercise_bank_question . exercise_bank_shixun_challenges . new challenge_option
shixun_challenge_bank . save
shixun_challenge_bank . save
@ -1006,6 +1006,7 @@ class ExercisesController < ApplicationController
def start_answer
def start_answer
ActiveRecord :: Base . transaction do
ActiveRecord :: Base . transaction do
begin
begin
@exercise_user_current = @exercise . exercise_users . exercise_commit_users ( @exercise_current_user_id ) & . first
if @exercise_user_current . blank?
if @exercise_user_current . blank?
if @user_course_identity > Course :: ASSISTANT_PROFESSOR #当为老师的时候, 不创建exercise_user表, 理论上老师是不能进入答题的
if @user_course_identity > Course :: ASSISTANT_PROFESSOR #当为老师的时候, 不创建exercise_user表, 理论上老师是不能进入答题的
exercise_user_params = {
exercise_user_params = {
@ -1640,38 +1641,38 @@ class ExercisesController < ApplicationController
end
end
def check_exercise_time
def check_exercise_time
@answer_committed_user = @exercise . exercise_users . exercise_commit_users ( current_user . id ) .first
@answer_committed_user = @exercise . exercise_users . exercise_commit_users ( current_user . id ) & .first
if @answer_committed_user . blank?
if @answer_committed_user . blank?
normal_status ( 404 , " 答题用户不存在 " )
normal_status ( 404 , " 答题用户不存在 " )
elsif @exercise . get_exercise_status ( current_user . id ) != 2 || @answer_committed_user . commit_status == 1 #
# elsif @exercise.get_exercise_status(current_user.id) == 2 && @answer_committed_user.commit_status == 1 #当试卷截止时,会自动提交
normal_status ( - 1 , " 提交错误,试卷已截止/用户已提交! " )
# normal_status(-1,"提交错误,试卷用户已提交!" )
end
end
end
end
def commit_user_exercise
# def commit_user_exercise
@exercise_user_current = @exercise . exercise_users . exercise_commit_users ( @exercise_current_user_id ) . first #查找当前用户是否有过答题
# @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first #查找当前用户是否有过答题
if @user_course_identity == Course :: STUDENT
# if @user_course_identity == Course:: STUDENT
if @exercise_user_current . present?
# if @exercise_user_current. present?
if @exercise . time > 0 && @exercise_user_current . start_at . present? && ( @exercise_user_current . commit_status == 0 ) &&
# if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) &&
( ( @exercise_user_current . start_at + ( @exercise . time . to_i + 1 ) . minutes ) < Time . now )
# ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now )
#当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制
# #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制
objective_score = calculate_student_score ( @exercise , current_user ) [ :total_score ]
# objective_score = calculate_student_score(@exercise,current_user)[:total_score]
subjective_score = @exercise_user_current . subjective_score < 0 . 0 ? 0 . 0 : @exercise_user_current . subjective_score
# subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score
total_score = objective_score + subjective_score
# total_score = objective_score + subjective_score
commit_option = {
# commit_option = {
:status = > 1 ,
# :status => 1,
:commit_status = > 1 ,
# :commit_status => 1,
:end_at = > Time . now ,
# :end_at => Time.now,
:objective_score = > objective_score ,
# :objective_score => objective_score,
:score = > total_score ,
# :score => total_score,
:subjective_score = > subjective_score
# :subjective_score => subjective_score
}
# }
@exercise_user_current . update_attributes ( commit_option )
# @exercise_user_current.update_attributes(commit_option)
normal_status ( 0 , " 已交卷成功! " )
# normal_status(0,"已交卷成功!")
end
# end
end
# end
end
# end
end
# end
#打回重做时的初步判断
#打回重做时的初步判断
def check_exercise_status
def check_exercise_status