@ -23,7 +23,6 @@ class ExercisesController < ApplicationController
before_action :commit_shixun_present , only : [ :commit_shixun ]
include ExportHelper
include ExercisesHelper
# require 'pdfkit'
def index
ActiveRecord :: Base . transaction do
@ -43,45 +42,38 @@ class ExercisesController < ApplicationController
@exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同)
elsif @user_course_identity == Course :: STUDENT # 2为课堂成员, 能看到统一设置的和自己班级的
@is_teacher_or = 2
# get_exercise_left_time(@exercise,current_user)
member_group_id = @current_student . first . try ( :course_group_id ) . to_i # 成员的分班id, 默认为0
if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
@member_group_id = @current_student . first . try ( :course_group_id ) . to_i # 成员的分班id, 默认为0
if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
@exercises = member_show_exercises . exists? ? member_show_exercises . unified_setting : [ ]
else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷
# 已发布 当前用户班级分组的 试卷id
exercise_settings_ids = @course . exercise_group_settings . exercise_group_published
. where ( course_group_id : member_group_id ) . pluck ( :exercise_id ) . uniq
@exercises = member_show_exercises . exists? ?
member_show_exercises . unified_setting . or ( member_show_exercises . where ( id : exercise_settings_ids ) )
: [ ]
not_exercise_ids = @course . exercise_group_settings . exercise_group_not_published . where ( " course_group_id = #{ @member_group_id } " ) . pluck ( :exercise_id )
@exercises = member_show_exercises . where . not ( id : not_exercise_ids )
end
else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁
@is_teacher_or = 0
@exercises = member_show_exercises . exists? ? member_show_exercises . unified_setting : [ ]
@exercises = member_show_exercises . unified_setting
end
if @exercises . size > 0
if params [ :type ] . present?
choose_type = params [ :type ] . to_i
member_group_id = @current_student . first . try ( :course_group_id ) . to_i
if @is_teacher_or == 2 && member_group_id > 0
exercise_groups_sets = @course . exercise_group_settings . where ( course_group_id : member_group_id )
. exercise_group_published
exercise_settings_ids = exercise_groups_sets . pluck ( :exercise_id )
exercise_ended_ids = exercise_groups_sets . exercise_group_ended . pluck ( :exercise_id ) . uniq
if choose_type == 2
@exercises = @exercises_all . exists? ?
@exercises_all . exercise_by_status ( 2 ) . unified_setting
. or ( @exercises_all . where ( id : ( exercise_settings_ids - exercise_ended_ids ) . uniq ) )
: [ ]
elsif choose_type == 3
@exercises = @exercises_all . exists? ?
@exercises_all . exercise_by_status ( 3 ) . unified_setting
. or ( @exercises_all . where ( id : exercise_ended_ids ) )
: [ ]
end
ex_setting_ids = [ ]
if @is_teacher_or != 2
@exercises = @exercises . where ( " exercise_status = #{ choose_type } " )
else
@exercises = @exercises . exercise_by_status ( choose_type )
case choose_type
when 1
ex_setting_ids = @course . exercise_group_settings . where ( " course_group_id = #{ @member_group_id } " ) . exercise_group_not_published . pluck ( :exercise_id )
when 2
ex_setting_ids = @course . exercise_group_settings . where ( " course_group_id = #{ @member_group_id } " )
. where ( " publish_time is not null and publish_time <= ? and end_time > ? " , Time . now , Time . now ) . pluck ( :exercise_id )
when 3
ex_setting_ids = @course . exercise_group_settings . where ( " course_group_id = #{ @member_group_id } " ) . exercise_group_ended . pluck ( :exercise_id )
end
unified_setting_ids = @exercises . unified_setting . where ( " exercise_status = #{ choose_type } " ) . pluck ( :id )
ex_ids = ( ex_setting_ids + unified_setting_ids ) . uniq
@exercises = @exercises . where ( id : ex_ids )
end
end
@ -97,7 +89,7 @@ class ExercisesController < ApplicationController
@page = params [ :page ] || 1
@limit = params [ :limit ] || 15
@exercises = @exercises . page ( @page ) . per ( @limit )
@exercises = @exercises & . includes ( : exercise_users, :exercise_questions , :exercise_group _settings)
@exercises = @exercises & . includes ( : published _settings)
else
@exercises = [ ]
end
@ -213,7 +205,7 @@ class ExercisesController < ApplicationController
@user_exercise_answer = 3 #教师页面
@user_commit_counts = @exercise . exercise_users . where ( commit_status : 1 ) . count #已提交的用户数
end
@ex_status = @exercise . get_exercise_status ( current_user . id )
@ex_status = @exercise . get_exercise_status ( current_user )
exercise_id_array = [ @exercise . id ]
@exercise_publish_count = get_user_permission_course ( exercise_id_array , 2 ) . count #是否存在已发布的
@ -227,7 +219,6 @@ class ExercisesController < ApplicationController
end
end
rescue Exception = > e
uid_logger_error ( e . message )
tip_exception ( " 没有权限 " )
@ -451,7 +442,7 @@ class ExercisesController < ApplicationController
# course_group_ids = @course.teacher_course_group_ids(current_user.id) #当前老师的班级id数组
course_group_ids = @course . charge_group_ids ( current_user ) #当前老师的班级id数组
exercise_status = @exercise . get_exercise_status ( current_user . id )
exercise_status = @exercise . get_exercise_status ( current_user )
if exercise_status == 1 && course_group_ids . size > 0 # 试卷未发布, 且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理
unified_setting = params [ :unified_setting ]
@ -805,7 +796,7 @@ class ExercisesController < ApplicationController
check_ids = Exercise . where ( id :params [ :check_ids ] )
course_students = @course . students #课堂的全部学生数
check_ids . each do | exercise |
exercise_status = exercise . get_exercise_status ( current_user . id )
exercise_status = exercise . get_exercise_status ( current_user )
if exercise_status == 2 #跳过已截止的或未发布的
g_course = params [ :group_ids ]
if g_course . present?
@ -900,7 +891,7 @@ class ExercisesController < ApplicationController
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 . id ) == 2 #用户已提交且试卷提交中
if exercise_user . commit_status == 1 && @exercise . get_exercise_status ( current_user ) == 2 #用户已提交且试卷提交中
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 ,
:objective_score = > 0 . 0 , :subjective_score = > - 1 . 0 )
@ -1027,7 +1018,7 @@ class ExercisesController < ApplicationController
# @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
# end
@t_user_exercise_status = @exercise . get_exercise_status ( current_user . id )
@t_user_exercise_status = @exercise . get_exercise_status ( current_user )
@user_left_time = nil
if @user_course_identity < Course :: STUDENT || ( @t_user_exercise_status == 3 ) ||
@ -1049,6 +1040,7 @@ class ExercisesController < ApplicationController
@exercise_questions = @exercise_questions . order ( " question_number ASC " )
end
# 判断问题是否已回答还是未回答
@exercise_questions = @exercise_questions . includes ( :exercise_stand_answers , :exercise_answers , :exercise_shixun_answers )
if @t_user_exercise_status == 3
get_each_student_exercise ( @exercise . id , @exercise_questions , @exercise_current_user_id )
@ -1138,9 +1130,9 @@ class ExercisesController < ApplicationController
@is_teacher_or = @user_course_identity < Course :: STUDENT ? 1 : 0
@student_status = 2
# @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者
@exercise_questions = @exercise . exercise_questions . order( " question_number ASC " )
@exercise_questions = @exercise . exercise_questions . includes( :exercise_shixun_challenges , :exercise_standard_answers , :exercise_answers , :exercise_shixun_answers ) . order( " question_number ASC " )
@question_status = [ ]
get_exercise_status = @exercise . get_exercise_status ( current_user . id )
get_exercise_status = @exercise . get_exercise_status ( current_user )
if @ex_user . present? && @is_teacher_or == 0
if get_exercise_status == 2 #当前用户已提交,且试卷未截止
if @ex_user . commit_status == 0 #学生未提交,且当前为学生
@ -1168,7 +1160,7 @@ class ExercisesController < ApplicationController
begin
@current_user_id = current_user . id
exercise_ids = [ @exercise . id ]
@exercise_status = @exercise . get_exercise_status ( current_user . id )
@exercise_status = @exercise . get_exercise_status ( current_user )
@course_all_members = @course . students
@c_group_counts = @course . course_groups_count
question_types = @exercise . exercise_questions . pluck ( :question_type ) . uniq
@ -1192,12 +1184,12 @@ class ExercisesController < ApplicationController
ex_common_ids = @exercise . common_published_ids ( current_user . id )
@exercise_course_groups = @course . get_ex_published_course ( ex_common_ids )
@exercise_users_list = @exercise . all_exercise_users ( current_user . id ) #当前老师所在班级的全部学生
get_exercise_answers ( @exercise_users_list )
get_exercise_answers ( @exercise_users_list , @exercise_status )
end
elsif @user_course_identity > Course :: ASSISTANT_PROFESSOR #当前为学生或者有过答题的(提交/未提交)
@ex_user_end_time = @exercise . get_exercise_end_time ( current_user . id ) #当前用户所看到的剩余时间
@exercise_all_users = @exercise . get_stu_exercise_users
get_exercise_answers ( @exercise_all_users ) # 未答和已答的
get_exercise_answers ( @exercise_all_users , @exercise_status ) # 未答和已答的
exercise_current_user = @exercise_all_users . exercise_commit_users ( current_user . id ) #当前用户是否开始做试卷(提交/未提交/没做)
if exercise_current_user . present?
@exercise_current_user_status = 1 #当前用户的状态,为学生
@ -1211,11 +1203,9 @@ class ExercisesController < ApplicationController
end
else
@exercise_all_users = @exercise . get_stu_exercise_users
get_exercise_answers ( @exercise_all_users ) # 未答和已答的
get_exercise_answers ( @exercise_all_users , @exercise_status ) # 未答和已答的
@exercise_current_user_status = 2 #当前用户非课堂成员
@exercise_users_list = [ ]
# @exercise_unanswers = 0
# @exercise_answers = 0
end
end
@ -1302,9 +1292,9 @@ class ExercisesController < ApplicationController
respond_to do | format |
format . xlsx {
get_export_users ( @exercise , @course , @export_ex_users )
exercise_export_name =
exercise_export_name _ =
" #{ current_user . real_name } _ #{ @course . name } _ #{ @exercise . exercise_name } _ #{ Time . now . strftime ( '%Y%m%d_%H%M%S' ) } "
render xlsx : " #{ exercise_export_name . strip . first ( 30 ) } " , template : " exercises/exercise_lists.xlsx.axlsx " , locals : { table_columns : @table_columns , exercise_users : @user_columns }
render xlsx : " #{ exercise_export_name _ . strip . first ( 30 ) } " , template : " exercises/exercise_lists.xlsx.axlsx " , locals : { table_columns : @table_columns , exercise_users : @user_columns }
}
end
end
@ -1321,9 +1311,9 @@ class ExercisesController < ApplicationController
def export_exercise
@request_url = request . base_url
@exercise_questions = @exercise . exercise_questions . includes ( :exercise_choices ) . order ( " question_number ASC " )
filename = " #{ @exercise . user . real_name } _ #{ @ exercise. exercise_name } _ #{ Time . current . strftime ( '%Y%m%d_%H%M ') } .pdf "
filename _ = " #{ @exercise . user . real_name } _ #{ @ course. name } __ #{ Time . now . strftime ( '%Y%m%d_%H%M %S ') } "
stylesheets = " #{ Rails . root } /app/templates/exercise_export/exercise_export.css "
render pdf : 'exercise_export/blank_exercise' , filename : filename , stylesheets : stylesheets
render pdf : 'exercise_export/blank_exercise' , filename : filename _ , stylesheets : stylesheets
end
#空白试卷预览页面,仅供测试使用,无其他任何用途
@ -1370,7 +1360,7 @@ class ExercisesController < ApplicationController
@exercise_commit_users = @exercise_all_users . commit_exercise_by_status ( 1 ) #试卷的已提交用户
@exercise_commit_user_ids = @exercise_commit_users . pluck ( :user_id ) . uniq #已提交试卷的全部用户id
@exercise_commit_user_counts = @exercise_commit_users . count #试卷的已提交用户人数
@exercise_status = @exercise . get_exercise_status ( current_user . id )
@exercise_status = @exercise . get_exercise_status ( current_user )
#提交率
if @course_all_members_count == 0
@ -1552,13 +1542,12 @@ class ExercisesController < ApplicationController
exercises_all . each do | exercise |
if exercise . present?
if exercise . unified_setting #统一设置只有两种情况,全部发布,全部截止
exercise_user_status = exercise . get_exercise_status ( current_user . id ) #当前用户的能看到的试卷
if exercise_user_status == exercise_status || exercise_status == 3 #未发布的情况
exercise_user_status = exercise . get_exercise_status ( current_user ) #当前用户的能看到的试卷
if ( exercise_user_status == exercise_status ) || exercise_status == 3 #未发布的情况
unpublish_group = unpublish_group + user_groups_id
else
unpublish_group = [ ]
end
# unpublish_group = unpublish_group + user_groups_id
else
ex_all_group_settings = exercise . exercise_group_settings
ex_group_settings = ex_all_group_settings . exercise_group_published . pluck ( :course_group_id ) . uniq #问卷设置的班级
@ -1586,13 +1575,13 @@ class ExercisesController < ApplicationController
def set_exercise_status ( publish_time , end_time )
time_now_i = Time . now
if publish_time . present? && publish_time < = time_now_i && end_time > time_now_i
if publish_time . present? && ( publish_time < = time_now_i ) && ( end_time > time_now_i )
2
elsif publish_time . nil? || ( publish_time . present? && publish_time > time_now_i )
1
elsif end_time . present? && end_time < = time_now_i
elsif end_time . present? && ( end_time < = time_now_i )
3
elsif end_time . present? && publish_time . present? && end_time < publish_time
elsif end_time . present? && publish_time . present? && ( end_time < publish_time )
normal_status ( - 1 , " 时间设置错误! " )
else
1
@ -1622,7 +1611,7 @@ class ExercisesController < ApplicationController
## 判断开始答题页面的用户权限
def check_user_on_answer
if @user_course_identity == Course :: STUDENT && @exercise . get_exercise_status ( current_user . id ) == 1 #试卷未发布,且当前用户不为老师/管理员
if @user_course_identity == Course :: STUDENT && @exercise . get_exercise_status ( current_user ) == 1 #试卷未发布,且当前用户不为老师/管理员
normal_status ( - 1 , " 未发布试卷! " )
elsif @user_course_identity > Course :: STUDENT && ( ! @exercise . is_public || ( @exercise . is_public && ! @exercise . unified_setting ) ) ##不为课堂成员,且试卷不为公开的,或试卷公开,但不是统一设置的
normal_status ( - 1 , " 试卷暂未公开! " )
@ -1639,7 +1628,7 @@ class ExercisesController < ApplicationController
#打回重做时的初步判断
def check_exercise_status
@exercise_users = @exercise . all_exercise_users ( current_user . id ) . commit_exercise_by_status ( 1 ) #当前教师所在分班的全部已提交的学生数
if @exercise . get_exercise_status ( current_user . id ) != 2
if @exercise . get_exercise_status ( current_user ) != 2
normal_status ( - 1 , " 非提交中的试卷不允许打回重做! " )
elsif @exercise_users . count < 1
normal_status ( - 1 , " 暂无人提交试卷! " )
@ -1649,7 +1638,7 @@ class ExercisesController < ApplicationController
#查看试题页面,当为学生时,除非试卷已截止,或已提交才可以查看
def check_exercise_is_end
ex_status = @exercise . get_exercise_status ( current_user . id )
ex_status = @exercise . get_exercise_status ( current_user )
@ex_user = @exercise . exercise_users . find_by ( user_id : @exercise_current_user_id ) #该试卷的回答者
if @user_course_identity > Course :: ASSISTANT_PROFESSOR
if ex_status == 1
@ -1666,7 +1655,7 @@ class ExercisesController < ApplicationController
def check_exercise_public
if @user_course_identity > Course :: ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交
ex_user = @exercise . exercise_users . exercise_commit_users ( current_user . id ) . first
unless @exercise . get_exercise_status ( current_user . id ) == 3 && ex_user . present? && ex_user . commit_status == 1 &&
unless @exercise . get_exercise_status ( current_user ) == 3 && ex_user . present? && ex_user . commit_status == 1 &&
@exercise . show_statistic
normal_status ( - 1 , " 学生暂不能查看 " )
end
@ -1759,6 +1748,4 @@ class ExercisesController < ApplicationController
end
end
end