@ -24,6 +24,15 @@ class ExercisesController < ApplicationController
include ExportHelper
include ExercisesHelper
# model validation error
rescue_from ActiveRecord :: RecordInvalid do | ex |
render_error ( ex . record . errors . full_messages . join ( ',' ) )
end
# form validation error
rescue_from ActiveModel :: ValidationError do | ex |
render_error ( ex . model . errors . full_messages . join ( ',' ) )
end
def index
begin
# 按发布时间或创建时间排序
@ -119,7 +128,6 @@ class ExercisesController < ApplicationController
def create
ActiveRecord :: Base . transaction do
begin
ex_name = params [ :exercise_name ]
ex_desc = params [ :exercise_description ]
exercise_options = {
@ -130,68 +138,44 @@ class ExercisesController < ApplicationController
:time = > - 1 ,
:exercise_status = > 1
}
@exercise = Exercise . create ( exercise_options )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 试卷创建失败! " )
raise ActiveRecord :: Rollback
end
@exercise = Exercise . create! ( exercise_options )
end
end
#试卷的内容,及试题/答案的内容编辑
def edit
ActiveRecord :: Base . transaction do
begin
@exercise_questions = @exercise . exercise_questions . order ( " question_number ASC " )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 试卷创建失败! " )
raise ActiveRecord :: Rollback
end
end
end
def update
ActiveRecord :: Base . transaction do
begin
ex_name = params [ :exercise_name ]
ex_desc = params [ :exercise_description ]
exercise_options = {
:exercise_name = > ex_name ,
:exercise_description = > ex_desc ,
}
@exercise . update_attributes ( exercise_options )
@exercise . update! ( exercise_options )
normal_status ( 0 , " 试卷更新成功! " )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 试卷创建失败! " )
raise ActiveRecord :: Rollback
end
end
end
def show
ActiveRecord :: Base . transaction do
begin
if @user_course_identity < Course :: STUDENT
@is_teacher_or = 1 #为老师/助教/管理员
else
@is_teacher_or = 0 #为学生
end
@exercise_questions = @exercise . exercise_questions & . includes ( :exercise_choices , :exercise_shixun_challenges , :exercise_standard_answers ) . order ( " question_number ASC " )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 试卷创建失败! " )
raise ActiveRecord :: Rollback
end
end
end
#试卷的公用头部
def common_header
ActiveRecord :: Base . transaction do
begin
@user_left_time = nil
if @user_course_identity > Course :: ASSISTANT_PROFESSOR
@is_teacher_or = 0
@ -216,19 +200,12 @@ class ExercisesController < ApplicationController
@exercise_publish_count = 1 #试卷未发布,且课堂没有分班的时候
end
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 没有权限 " )
raise ActiveRecord :: Rollback
end
end
end
#实训题目的选用
def choose_shixun
ActiveRecord :: Base . transaction do
begin
search = params [ :search ]
if @user_course_identity > Course :: ADMIN #当不为管理员的时候
user_school_id = current_user . school_id #当前用户的学校id
@ -252,63 +229,40 @@ class ExercisesController < ApplicationController
@limit = params [ :limit ] || 8
@shixuns = @shixuns . page ( @page ) . per ( @limit )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 实训选择失败! " )
end
end
end
#确认实训的选择
def commit_shixun
ActiveRecord :: Base . transaction do
begin
@shixun_challenges = @shixun . challenges
@shixun_challenges_count = @shixun_challenges . size
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 页面调用失败! " )
raise ActiveRecord :: Rollback
end
end
end
# 首页批量或单独删除
def destroys
ActiveRecord :: Base . transaction do
begin
check_ids = Exercise . where ( id : params [ :check_ids ] )
check_ids . destroy_all
normal_status ( 0 , " 试卷已删除成功! " )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 试卷删除失败! " )
raise ActiveRecord :: Rollback
end
end
end
# 设为公开
def set_public
ActiveRecord :: Base . transaction do
begin
check_ids = Exercise . where ( id : params [ :check_ids ] )
check_ids . each do | exercise |
exercise . update_attribute ( 'is_public' , true )
exercise . update! ( is_public : true )
end
normal_status ( 0 , " 试卷已设为公开! " )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 试卷设为公开失败! " )
raise ActiveRecord :: Rollback
end
end
end
## 加入题库
def join_exercise_banks
ActiveRecord :: Base . transaction do
begin
check_ids = Exercise . where ( id : params [ :check_ids ] )
check_ids . each do | exercise |
current_ex_bank = current_user . exercise_banks . find_by_container ( exercise . id , " Exercise " ) & . first
@ -318,7 +272,7 @@ class ExercisesController < ApplicationController
:description = > exercise . exercise_description ,
:course_list_id = > exercise . course . try ( :course_list_id )
}
current_ex_bank . update_attributes ( ex_params )
current_ex_bank . update! ( ex_params )
# question_bank = QuestionBank.ques_by_container(current_ex_bank.id,current_ex_bank.container_type).first #该习题库是否存在于问题库里
# ques_params = {
# :name => current_ex_bank.name,
@ -352,7 +306,7 @@ class ExercisesController < ApplicationController
# question_bank = QuestionBank.new ques_params
# question_bank.save
# end
exercise . update _attributes !( exercise_bank_id : current_ex_bank . id )
exercise . update !( exercise_bank_id : current_ex_bank . id )
end
# 试卷的问题的输入
exercise . exercise_questions . each do | q |
@ -365,7 +319,7 @@ class ExercisesController < ApplicationController
:shixun_name = > q . shixun_name
}
exercise_bank_question = current_ex_bank . exercise_bank_questions . new option
exercise_bank_question . save
exercise_bank_question . save !
## 试卷选项的输入
if q . question_type != Exercise :: PRACTICAL #不为实训题时,试卷选项加入试题答案库
ex_choices = q . exercise_choices
@ -376,7 +330,7 @@ class ExercisesController < ApplicationController
:choice_text = > c . choice_text
}
ex_bank_choice = exercise_bank_question . exercise_bank_choices . new choice_option
ex_bank_choice . save
ex_bank_choice . save !
end
ex_standard . each do | s |
ex_stand = {
@ -384,7 +338,7 @@ class ExercisesController < ApplicationController
:answer_text = > s . answer_text
}
ex_stand_bank = exercise_bank_question . exercise_bank_standard_answers . new ex_stand
ex_stand_bank . save
ex_stand_bank . save !
end
else #当为实训题时
shixun_challenges = q . exercise_shixun_challenges
@ -396,25 +350,19 @@ class ExercisesController < ApplicationController
:question_score = > c . question_score
}
shixun_challenge_bank = exercise_bank_question . exercise_bank_shixun_challenges . new challenge_option
shixun_challenge_bank . save
shixun_challenge_bank . save !
end
end
end
current_ex_bank . save
current_ex_bank . save !
end
normal_status ( 0 , " 题库更新成功! " )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 题库更新失败! " )
raise ActiveRecord :: Rollback
end
end
end
#试卷的设置页面
def exercise_setting
ActiveRecord :: Base . transaction do
begin
@user_permission = 2
@user_course_groups = @course . teacher_group ( current_user . id ) #当前老师的分班
@being_setting_course_ids = @exercise . common_published_ids ( current_user . id ) #当前用户已发布的班级的id
@ -425,18 +373,12 @@ class ExercisesController < ApplicationController
@exercise_unpublish_count = get_user_permission_course ( exercise_ids , Exercise :: UNPUBLISHED ) . count #判断当前用户是否有试卷未发布的分班,用户显示立即发布
@exercise_users_count = @exercise . exercise_users . commit_exercise_by_status ( 1 ) . count #判断当前试卷是否有已提交的
# ## 需添加发送消息的接口,稍后添加
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 页面调用失败! " )
raise ActiveRecord :: Rollback
end
end
end
#试卷的提交设置
def commit_setting
ActiveRecord :: Base . transaction do
begin
error_count = 0 # 判断循环里是否有已发布/已截止的,且时间更改了的分班。
# course_group_ids = @course.teacher_course_group_ids(current_user.id) #当前老师的班级id数组
course_group_ids = @course . charge_group_ids ( current_user ) #当前老师的班级id数组
@ -461,8 +403,7 @@ class ExercisesController < ApplicationController
tip_exception ( " 发布时间不能为空 " ) if params [ :publish_time ] . blank?
tip_exception ( " 截止时间不能为空 " ) if params [ :end_time ] . blank?
tip_exception ( " 截止时间不能早于发布时间 " ) if params [ :publish_time ] . to_time > params [ :end_time ] . to_time
tip_exception ( " 截止时间不能晚于课堂结束时间( #{ @course . end_date . end_of_day . strftime ( " %Y-%m-%d %H:%M " ) } ) " ) if
@course . end_date . present? && params [ :end_time ] . to_time > @course . end_date . end_of_day
tip_exception ( " 截止时间不能晚于课堂结束时间( #{ @course . end_date . end_of_day . strftime ( " %Y-%m-%d %H:%M " ) } ) " ) if @course . end_date . present? && params [ :end_time ] . to_time > @course . end_date . end_of_day
params_publish_time = params [ :publish_time ] . to_time
params_end_time = params [ :end_time ] . to_time
@ -486,7 +427,7 @@ class ExercisesController < ApplicationController
:publish_time = > params_publish_time ,
:end_time = > params_end_time
}
@exercise . update_attributes ( exercise_params )
@exercise . update! ( exercise_params )
@exercise . exercise_group_settings . destroy_all
normal_status ( 0 , " 试卷设置成功! " )
end
@ -502,8 +443,7 @@ class ExercisesController < ApplicationController
tip_exception ( " 发布时间不能为空 " ) if t [ :publish_time ] . blank?
tip_exception ( " 截止时间不能为空 " ) if t [ :end_time ] . blank?
tip_exception ( " 截止时间不能早于发布时间 " ) if t [ :publish_time ] . to_time > t [ :end_time ] . to_time
tip_exception ( " 截止时间不能晚于课堂结束时间( #{ @course . end_date . end_of_day . strftime ( " %Y-%m-%d %H:%M " ) } ) " ) if
@course . end_date . present? && t [ :end_time ] . to_time > @course . end_date . end_of_day
tip_exception ( " 截止时间不能晚于课堂结束时间( #{ @course . end_date . end_of_day . strftime ( " %Y-%m-%d %H:%M " ) } ) " ) if @course . end_date . present? && t [ :end_time ] . to_time > @course . end_date . end_of_day
course_id = t [ :course_group_id ]
exercise_publish_time = t [ :publish_time ] . to_time
@ -539,7 +479,7 @@ class ExercisesController < ApplicationController
:end_time = > exercise_end_time
}
end
the_group_setting . update _attributes !( ex_group_params )
the_group_setting . update !( ex_group_params )
end
end
if new_group_ids . size > 0
@ -590,7 +530,7 @@ class ExercisesController < ApplicationController
:publish_time = > p_time ,
:end_time = > e_time
}
@exercise . update_attributes ( exercise_params )
@exercise . update! ( exercise_params )
if @exercise . exercise_status == Exercise :: PUBLISHED
if @exercise . course_acts . size == 0
@exercise . course_acts << CourseActivity . new ( :user_id = > @exercise . user_id , :course_id = > @exercise . course_id )
@ -599,11 +539,6 @@ class ExercisesController < ApplicationController
normal_status ( 0 , " 试卷设置成功! " )
end
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( e . message )
raise ActiveRecord :: Rollback
end
end
end
@ -629,9 +564,9 @@ class ExercisesController < ApplicationController
objective_score = @exercise . objective_score > 0 ? params [ :objective_score ] . to_f . round ( 2 ) : 0
score = subjective_score + objective_score
if exercise_user . commit_status == 1
exercise_user . update _attributes !( score : score , subjective_score : subjective_score , objective_score : objective_score )
exercise_user . update !( score : score , subjective_score : subjective_score , objective_score : objective_score )
else
exercise_user . update _attributes !( start_at : start_at_time , end_at : Time . now , status : 1 , commit_status : 1 , score : score ,
exercise_user . update !( start_at : start_at_time , end_at : Time . now , status : 1 , commit_status : 1 , score : score ,
subjective_score : subjective_score , objective_score : objective_score , commit_method : 5 )
end
@ -644,7 +579,6 @@ class ExercisesController < ApplicationController
#我的题库
def my_exercises
ActiveRecord :: Base . transaction do
begin
## 我的试卷题库
@current_user_exercises = current_user . exercise_banks . find_by_c_type ( " Exercise " )
if @current_user_exercises . present?
@ -660,18 +594,12 @@ class ExercisesController < ApplicationController
else
@current_user_exercises = [ ]
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 页面调用失败! " )
raise ActiveRecord :: Rollback
end
end
end
# 公共题库
def public_exercises
ActiveRecord :: Base . transaction do
begin
if current_user . is_certification_teacher
@user_certification = 1 #用户已通过认证
@public_exercises = ExerciseBank . find_by_c_type ( " Exercise " ) . public_exercises
@ -693,11 +621,6 @@ class ExercisesController < ApplicationController
@public_exercises_count = 0
@public_exercises = [ ]
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 题库调用失败! " )
raise ActiveRecord :: Rollback
end
end
end
@ -705,18 +628,12 @@ class ExercisesController < ApplicationController
def publish_modal
ActiveRecord :: Base . transaction do
begin
exercise_ids = params [ :check_ids ]
if exercise_ids . count > 0
@course_groups = get_user_permission_course ( exercise_ids , 1 )
else
@course_groups = [ ]
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 没有权限 " )
raise ActiveRecord :: Rollback
end
end
end
@ -735,21 +652,18 @@ class ExercisesController < ApplicationController
if params [ :detail ] . blank?
tip_exception ( " 缺少截止时间参数 " ) if params [ :end_time ] . blank?
tip_exception ( " 截止时间不能早于当前时间 " ) if params [ :end_time ] < = strf_time ( Time . now )
tip_exception ( " 截止时间不能晚于课堂结束时间( #{ @course . end_date . end_of_day . strftime ( " %Y-%m-%d %H:%M " ) } ) " ) if
@course . end_date . present? && params [ :end_time ] > strf_time ( @course . end_date . end_of_day )
tip_exception ( " 截止时间不能晚于课堂结束时间( #{ @course . end_date . end_of_day . strftime ( " %Y-%m-%d %H:%M " ) } ) " ) if @course . end_date . present? && params [ :end_time ] > strf_time ( @course . end_date . end_of_day )
else
group_end_times = params [ :group_end_times ] . reject ( & :blank? ) . map { | time | time . to_time }
tip_exception ( " 缺少截止时间参数 " ) if group_end_times . blank?
tip_exception ( " 截止时间和分班参数的个数不一致 " ) if group_end_times . length != group_ids . length
group_end_times . each do | time |
tip_exception ( " 分班截止时间不能早于当前时间 " ) if time < = Time . now
tip_exception ( " 分班截止时间不能晚于课堂结束时间( #{ @course . end_date . end_of_day . strftime ( " %Y-%m-%d %H:%M " ) } ) " ) if
@course . end_date . present? && time > @course . end_date . end_of_day
tip_exception ( " 分班截止时间不能晚于课堂结束时间( #{ @course . end_date . end_of_day . strftime ( " %Y-%m-%d %H:%M " ) } ) " ) if @course . end_date . present? && time > @course . end_date . end_of_day
end
end
ActiveRecord :: Base . transaction do
begin
check_ids = Exercise . where ( id : params [ :check_ids ] )
ex_end_time = params [ :end_time ] . blank? ? Time . at ( ( ( 1 . month . since . to_i ) / 3600 . 0 ) . ceil * 3600 ) : params [ :end_time ] . to_time
check_ids . each do | exercise |
@ -777,7 +691,7 @@ class ExercisesController < ApplicationController
exercise_group_setting = exercise . exercise_group_settings . find_in_exercise_group ( " course_group_id " , i ) . first #根据课堂分班的id, 寻找试卷所在的班级
group_end_time = params [ :detail ] ? group_end_times [ index ] : ex_end_time
if exercise_group_setting . present? #如果该试卷分组存在,则更新,否则新建
exercise_group_setting . update _attributes !( publish_time : Time . now , end_time : group_end_time )
exercise_group_setting . update !( publish_time : Time . now , end_time : group_end_time )
else
p_course_group = {
:exercise_id = > exercise . id ,
@ -787,7 +701,7 @@ class ExercisesController < ApplicationController
:end_time = > group_end_time ,
}
new_exercise_group = exercise . exercise_group_settings . new p_course_group
new_exercise_group . save
new_exercise_group . save !
end
end
# group_ids = params[:group_ids]
@ -806,7 +720,7 @@ class ExercisesController < ApplicationController
:exercise_status = > ex_status ,
:unified_setting = > ex_unified
}
exercise . update_attributes ( exercise_params )
exercise . update! ( exercise_params )
if exercise . course_acts . size == 0
exercise . course_acts << CourseActivity . new ( :user_id = > exercise . user_id , :course_id = > exercise . course_id )
@ -816,29 +730,18 @@ class ExercisesController < ApplicationController
end
end
normal_status ( 0 , " 试卷发布成功! " )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 试卷发布失败 " )
raise ActiveRecord :: Rollback
end
end
end
#立即截止的弹窗内容
def end_modal
ActiveRecord :: Base . transaction do
begin
exercise_ids = params [ :check_ids ]
if exercise_ids . count > 0
@course_groups = get_user_permission_course ( exercise_ids , 3 )
else
@course_groups = [ ]
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 没有权限 " )
raise ActiveRecord :: Rollback
end
end
end
@ -846,7 +749,6 @@ class ExercisesController < ApplicationController
def end_exercise
ActiveRecord :: Base . transaction do
begin
check_ids = Exercise . where ( id : params [ :check_ids ] )
course_students = @course . students #课堂的全部学生数
check_ids . each do | exercise |
@ -859,7 +761,7 @@ class ExercisesController < ApplicationController
if exercise . unified_setting && g_course . map ( & :to_i ) . sort == all_course_group_ids . sort #开始为统一设置
exercise . exercise_group_settings . destroy_all
new_ex_status = set_exercise_status ( exercise . publish_time , Time . now )
exercise . update_attributes ( :end_time = > Time . now , :exercise_status = > new_ex_status )
exercise . update! ( :end_time = > Time . now , :exercise_status = > new_ex_status )
exercise_users = exercise . exercise_users
else
course_members_ids = course_students . course_find_by_ids ( " course_group_id " , g_course ) . pluck ( :user_id ) . uniq #该班级的全部学生
@ -878,7 +780,7 @@ class ExercisesController < ApplicationController
:publish_time = > exercise . publish_time ,
:end_time = > exercise . end_time
}
ExerciseGroupSetting . create ( ex_group_options )
ExerciseGroupSetting . create ! ( ex_group_options )
end
end
end
@ -893,17 +795,17 @@ class ExercisesController < ApplicationController
:publish_time = > exercise . publish_time ,
:end_time = > Time . now
}
ExerciseGroupSetting . create ( ex_group_options )
ExerciseGroupSetting . create ! ( ex_group_options )
end
end
new_end_time = exercise . exercise_group_settings . end_time_no_null . map ( & :end_time ) # 试卷结束时间不为空的
new_end_time_s = new_end_time . count > 0 ? new_end_time . max : Time . now
new_ex_status = set_exercise_status ( exercise . publish_time , new_end_time_s )
exercise . update_attributes ( :end_time = > new_end_time_s , :exercise_status = > new_ex_status , :unified_setting = > false )
exercise . update! ( :end_time = > new_end_time_s , :exercise_status = > new_ex_status , :unified_setting = > false )
end
else
exercise_users = exercise . exercise_users
exercise . update_attributes ( :exercise_status = > 3 , :end_time = > Time . now , :unified_setting = > true )
exercise . update! ( :exercise_status = > 3 , :end_time = > Time . now , :unified_setting = > true )
end
ex_user_ids = exercise_users . pluck ( :id )
@ -929,24 +831,18 @@ class ExercisesController < ApplicationController
end
end
normal_status ( 0 , " 试卷截止成功! " )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 立即截止失败! " )
raise ActiveRecord :: Rollback
end
end
end
#学生撤销回答
def cancel_exercise
ActiveRecord :: Base . transaction do
begin
ex_question_ids = @exercise . exercise_questions . pluck ( :id )
exercise_user = @exercise . exercise_users . exercise_commit_users ( current_user . id ) . first
if exercise_user . present?
if exercise_user . commit_status == 1 && @exercise . get_exercise_status ( current_user ) == Exercise :: PUBLISHED #用户已提交且试卷提交中
if @exercise . time == - 1 || ( ( Time . now . to_i - exercise_user . start_at . to_i ) < @exercise . time . to_i * 60 )
exercise_user . update_attributes ( :score = > nil , :end_at = > nil , :status = > nil , :commit_status = > 0 ,
exercise_user . update! ( :score = > nil , :end_at = > nil , :status = > nil , :commit_status = > 0 ,
:objective_score = > 0 . 0 , :subjective_score = > - 1 . 0 )
exercise_user . user . exercise_shixun_answers . search_shixun_answers ( " exercise_question_id " , ex_question_ids ) . destroy_all
exercise_answers = exercise_user . user . exercise_answers . search_answer_users ( " exercise_question_id " , ex_question_ids )
@ -964,18 +860,12 @@ class ExercisesController < ApplicationController
else
normal_status ( - 1 , " 当前用户未答题 " )
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 页面调用失败 " )
raise ActiveRecord :: Rollback
end
end
end
#打回重做modal
def redo_modal
ActiveRecord :: Base . transaction do
begin
#搜索
if params [ :realname ] . present?
search_name = params [ :realname ]
@ -995,18 +885,12 @@ class ExercisesController < ApplicationController
page = params [ :page ] || 1
limit = params [ :limit ] || 15
@exercise_users = @exercise_users . page ( page ) . per ( limit )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 没有权限 " )
raise ActiveRecord :: Rollback
end
end
end
#打回重做确认
def redo_exercise
ActiveRecord :: Base . transaction do
begin
user_ids = params [ :user_ids ]
if user_ids . present?
redo_option = {
@ -1031,22 +915,16 @@ class ExercisesController < ApplicationController
else
normal_status ( - 1 , " 请选择学生! " )
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 没有权限 " )
raise ActiveRecord :: Rollback
end
end
end
#学生开始答题页面
def start_answer
begin
ex_users_current = ExerciseUser . where ( user_id : @exercise_current_user_id , exercise_id : @exercise . id ) #不能用@exercise.exercise_users, 因为exercise_users删除时, 只是状态改变, 未删除
@exercise_user_current = ex_users_current & . first
if ex_users_current . exists?
if @exercise_user_current . start_at . blank?
@exercise_user_current . update_attribute ( " start_at " , Time . now )
@exercise_user_current . update! ( start_at : Time . now )
end
else
if @user_course_identity > Course :: ASSISTANT_PROFESSOR #当为老师的时候, 不创建exercise_user表, 理论上老师是不能进入答题的
@ -1056,7 +934,7 @@ class ExercisesController < ApplicationController
:start_at = > Time . now
}
exercise_user_current = ExerciseUser . new ( exercise_user_params )
exercise_user_current . save
exercise_user_current . save !
end
end
@t_user_exercise_status = @exercise . get_exercise_status ( current_user )
@ -1088,17 +966,11 @@ class ExercisesController < ApplicationController
end
get_user_answer_status ( @exercise_questions , @exercise_current_user_id , @exercise , @t_user_exercise_status )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( e . message )
raise ActiveRecord :: Rollback
end
end
#提交试卷前的弹窗
def begin_commit
ActiveRecord :: Base . transaction do
begin
if @user_course_identity > Course :: ASSISTANT_PROFESSOR #为学生时
@exercise_questions = @exercise . exercise_questions
@shixun_undo = 0
@ -1135,11 +1007,6 @@ class ExercisesController < ApplicationController
end
end
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 试卷提交失败! " )
raise ActiveRecord :: Rollback
end
end
end
@ -1147,7 +1014,6 @@ class ExercisesController < ApplicationController
def commit_exercise
tip_exception ( 0 , " 试卷截止时间已到,系统已自动提交 " ) if @answer_committed_user . commit_status == 1
ActiveRecord :: Base . transaction do
begin
can_commit_exercise = false
user_left_time = nil
if @user_course_identity > Course :: ASSISTANT_PROFESSOR #为学生时
@ -1174,7 +1040,7 @@ class ExercisesController < ApplicationController
:subjective_score = > subjective_score ,
:commit_method = > @answer_committed_user & . commit_method . to_i > 0 ? @answer_committed_user & . commit_method . to_i : params [ :commit_method ] . to_i
}
@answer_committed_user . update _attributes !( commit_option )
@answer_committed_user . update !( commit_option )
CommitExercsieNotifyJobJob . perform_later ( @exercise . id , current_user . id )
normal_status ( 0 , " 试卷提交成功! " )
else
@ -1183,18 +1049,12 @@ class ExercisesController < ApplicationController
else
normal_status ( - 1 , " 提交失败,当前用户不为课堂学生! " )
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 试卷提交失败! " )
raise ActiveRecord :: Rollback
end
end
end
#教师评阅试卷 及学生查看试卷
def review_exercise
ActiveRecord :: Base . transaction do
begin
# 1 老师权限, 0 学生权限
@is_teacher_or = ( @user_course_identity < Course :: STUDENT ) ? 1 : 0
@student_status = 2
@ -1215,17 +1075,11 @@ class ExercisesController < ApplicationController
if @student_status == 2
get_each_student_exercise ( @exercise . id , @exercise_questions , @exercise_current_user_id )
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 没有权限 " )
raise ActiveRecord :: Rollback
end
end
end
#答题列表
def exercise_lists
begin
@current_user_id = current_user . id
exercise_ids = [ @exercise . id ]
@exercise_status = @exercise . get_exercise_status ( current_user )
@ -1368,11 +1222,6 @@ class ExercisesController < ApplicationController
end
end
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( e . message )
raise ActiveRecord :: Rollback
end
end
#导出空白试卷
@ -1410,7 +1259,6 @@ class ExercisesController < ApplicationController
#学生的统计结果
def exercise_result
begin
exercise_ids = [ @exercise . id ]
@exercise_publish_count = get_user_permission_course ( exercise_ids , Exercise :: PUBLISHED ) . size #判断是否有已发布的分班
@exercise_unpublish_count = get_user_permission_course ( exercise_ids , Exercise :: UNPUBLISHED ) . size #判断是否有未发布的分班
@ -1499,11 +1347,6 @@ class ExercisesController < ApplicationController
@page = params [ :page ] || 1
@limit = params [ :limit ] || 10
@question_result_hash = Kaminari . paginate_array ( @question_result_hash ) . page ( @page ) . per ( @limit )
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 没有权限 " )
raise ActiveRecord :: Rollback
end
end
private
@ -1804,6 +1647,7 @@ class ExercisesController < ApplicationController
@exercise_all_questions = @exercise_all_questions . push ( question_options ) . sort_by { | k | k [ :ques_number ] }
end
end
#下一步也有check_on_users再进行判断
def only_student_in
if @user_course_identity < Course :: STUDENT