Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_course
SylorHuang 5 years ago
commit 79cdbc5925

@ -53,8 +53,11 @@ class ExercisesController < ApplicationController
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : [] @exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : []
else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷
# 已发布 当前用户班级分组的 试卷id # 已发布 当前用户班级分组的 试卷id
exercise_settings_ids = @course.exercise_group_settings.exercise_group_published.where(course_group_id: member_group_id).pluck(:exercise_id).uniq exercise_settings_ids = @course.exercise_group_settings.exercise_group_published
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) : [] .where(course_group_id: member_group_id).pluck(:exercise_id).uniq
@exercises = member_show_exercises.present? ?
member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids))
: []
end end
else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁
@is_teacher_or = 0 @is_teacher_or = 0
@ -65,13 +68,20 @@ class ExercisesController < ApplicationController
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
if @is_teacher_or == 2 && member_group_id > 0 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_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_settings_ids = exercise_groups_sets.pluck(:exercise_id)
exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq
if choose_type == 2 if choose_type == 2
@exercises = @exercises_all.present? ? @exercises_all.exercise_by_status(2).unified_setting.or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq)) : [] @exercises = @exercises_all.present? ?
@exercises_all.exercise_by_status(2).unified_setting
.or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq))
: []
elsif choose_type == 3 elsif choose_type == 3
@exercises = @exercises_all.present? ? @exercises_all.exercise_by_status(3).unified_setting.or(@exercises_all.where(id: exercise_ended_ids)) : [] @exercises = @exercises_all.present? ?
@exercises_all.exercise_by_status(3).unified_setting
.or(@exercises_all.where(id: exercise_ended_ids))
: []
end end
else else
@exercises = @exercises.exercise_by_status(choose_type) @exercises = @exercises.exercise_by_status(choose_type)
@ -412,7 +422,8 @@ class ExercisesController < ApplicationController
@user_permission = 2 @user_permission = 2
@user_course_groups = @course.teacher_group(current_user.id) #当前老师的分班 @user_course_groups = @course.teacher_group(current_user.id) #当前老师的分班
@being_setting_course_ids = @exercise.common_published_ids(current_user.id) #当前用户已发布的班级的id @being_setting_course_ids = @exercise.common_published_ids(current_user.id) #当前用户已发布的班级的id
@user_published_setting = @exercise.exercise_group_settings.find_in_exercise_group("course_group_id",@being_setting_course_ids) #当前用户已发布班级的试卷设置 @user_published_setting = @exercise.exercise_group_settings
.find_in_exercise_group("course_group_id",@being_setting_course_ids) #当前用户已发布班级的试卷设置
exercise_ids = [@exercise.id] exercise_ids = [@exercise.id]
@exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断当前用户是否有试卷已发布的分班,用于显示立即截止/撤销发布 @exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断当前用户是否有试卷已发布的分班,用于显示立即截止/撤销发布
@exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断当前用户是否有试卷未发布的分班,用户显示立即发布 @exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断当前用户是否有试卷未发布的分班,用户显示立即发布
@ -507,10 +518,12 @@ class ExercisesController < ApplicationController
end end
# exercise_end_time = t[:end_time].present? ? t[:end_time].to_time : nil # exercise_end_time = t[:end_time].present? ? t[:end_time].to_time : nil
exercise_group = exercise_groups.find_in_exercise_group("course_group_id",course_id) #判断该分班是否存在 exercise_group = exercise_groups.find_in_exercise_group("course_group_id",course_id) #判断该分班是否存在
if exercise_group.present? && exercise_group.first.end_time <= Time.now && (exercise_end_time != exercise_group.first.end_time || exercise_publish_time != exercise_group.first.publish_time) #已截止且时间改变的,则提示错误 if exercise_group.present? && exercise_group.first.end_time <= Time.now &&
(exercise_end_time != exercise_group.first.end_time || exercise_publish_time != exercise_group.first.publish_time) #已截止且时间改变的,则提示错误
error_count += 1 error_count += 1
end end
if exercise_group.present? && exercise_group.first.publish_time < Time.now && exercise_publish_time != exercise_group.first.publish_time if exercise_group.present? && exercise_group.first.publish_time <
Time.now && exercise_publish_time != exercise_group.first.publish_time
error_count += 1 error_count += 1
end end
if error_count == 0 if error_count == 0
@ -692,7 +705,8 @@ class ExercisesController < ApplicationController
if exercise.unified_setting if exercise.unified_setting
ex_status = exercise.exercise_status #则为试卷的状态 ex_status = exercise.exercise_status #则为试卷的状态
else else
ex_status = exercise.exercise_group_settings.find_in_exercise_group("course_group_id",params[:group_ids]).exercise_group_not_published.present? ? 1 : 0 ex_status = exercise.exercise_group_settings.find_in_exercise_group("course_group_id",params[:group_ids])
.exercise_group_not_published.present? ? 1 : 0
end end
if ex_status == 1 #如果试卷存在已发布的,或者是已截止的,那么则直接跳过 if ex_status == 1 #如果试卷存在已发布的,或者是已截止的,那么则直接跳过
g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改 g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改
@ -891,11 +905,13 @@ class ExercisesController < ApplicationController
if exercise_user.present? 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.id) == 2 #用户已提交且试卷提交中
if @exercise.time == -1 || ((Time.now.to_i - exercise_user.start_at.to_i) < @exercise.time.to_i * 60) 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) exercise_user.update_attributes(: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_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) exercise_answers = exercise_user.user.exercise_answers.search_answer_users("exercise_question_id",ex_question_ids)
exercise_answers.update_all(:score => -1.0) exercise_answers.update_all(:score => -1.0)
all_answer_comment = ExerciseAnswerComment.search_answer_comments("exercise_question_id",ex_question_ids).search_answer_comments("exercise_answer_id",exercise_answers.pluck(:id)) all_answer_comment = ExerciseAnswerComment.search_answer_comments("exercise_question_id",ex_question_ids)
.search_answer_comments("exercise_answer_id",exercise_answers.pluck(:id))
all_answer_comment.destroy_all all_answer_comment.destroy_all
normal_status(0,"撤销回答成功") normal_status(0,"撤销回答成功")
else else
@ -923,11 +939,13 @@ class ExercisesController < ApplicationController
if params[:realname].present? if params[:realname].present?
search_name = params[:realname] search_name = params[:realname]
#搜索用户的nickname,如果存在则返回,否则继续查询用户的真实姓名或学生号 #搜索用户的nickname,如果存在则返回,否则继续查询用户的真实姓名或学生号
@exercise_users = @exercise_users.includes(:user).where("LOWER(concat(users.lastname, users.firstname)) like ?","%#{search_name}%") @exercise_users = @exercise_users.includes(:user).where("LOWER(concat(users.lastname, users.firstname)) like ?",
"%#{search_name}%")
end end
if params[:student_id].present? if params[:student_id].present?
search_st_id = params[:student_id].to_i search_st_id = params[:student_id].to_i
@exercise_users = @exercise_users.includes(user: [:user_extension]).where('user_extensions.student_id like ?',"%#{search_st_id}%") @exercise_users = @exercise_users.includes(user: [:user_extension])
.where('user_extensions.student_id like ?',"%#{search_st_id}%")
end end
sort = params[:sort] ? params[:sort] : "asc" sort = params[:sort] ? params[:sort] : "asc"
@exercise_users = @exercise_users.order("score #{sort}") @exercise_users = @exercise_users.order("score #{sort}")
@ -962,8 +980,10 @@ class ExercisesController < ApplicationController
redo_exercise_users = @exercise_users.exercise_commit_users(user_ids) redo_exercise_users = @exercise_users.exercise_commit_users(user_ids)
redo_exercise_users.update_all(redo_option) redo_exercise_users.update_all(redo_option)
exercise_question_ids = @exercise.exercise_questions.pluck(:id).uniq exercise_question_ids = @exercise.exercise_questions.pluck(:id).uniq
ExerciseAnswer.search_answer_users("user_id",user_ids).search_answer_users("exercise_question_id",exercise_question_ids).destroy_all ExerciseAnswer.search_answer_users("user_id",user_ids)
ExerciseShixunAnswer.search_shixun_answers("user_id",user_ids).search_shixun_answers("exercise_question_id",exercise_question_ids).destroy_all .search_answer_users("exercise_question_id",exercise_question_ids).destroy_all
ExerciseShixunAnswer.search_shixun_answers("user_id",user_ids)
.search_shixun_answers("exercise_question_id",exercise_question_ids).destroy_all
normal_status(0,"已成功打回重做!") normal_status(0,"已成功打回重做!")
else else
@ -1005,13 +1025,17 @@ class ExercisesController < ApplicationController
@t_user_exercise_status = @exercise.get_exercise_status(current_user.id) @t_user_exercise_status = @exercise.get_exercise_status(current_user.id)
if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || (@exercise_user_current.present? && @exercise_user_current.commit_status == 1) if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) ||
(@exercise_user_current.present? && @exercise_user_current.commit_status == 1)
@user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑 @user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑
else else
@user_exercise_status = 0 #可编辑 @user_exercise_status = 0 #可编辑
end end
@exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,:exercise_shixun_answers,:exercise_answers,:exercise_standard_answers) @exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,
:exercise_shixun_answers,
:exercise_answers,
:exercise_standard_answers)
if @exercise.question_random if @exercise.question_random
@exercise_questions = @exercise_questions.order("RAND()") @exercise_questions = @exercise_questions.order("RAND()")
@ -1266,7 +1290,8 @@ class ExercisesController < ApplicationController
tip_exception(403,"无权限操作") tip_exception(403,"无权限操作")
else else
get_export_users(@exercise,@course,@export_ex_users) get_export_users(@exercise,@course,@export_ex_users)
exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @exercise.exercise_name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') 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
} }
@ -1426,7 +1451,8 @@ class ExercisesController < ApplicationController
def validates_exercise_params def validates_exercise_params
normal_status(-1, "试卷标题不能为空!") if params[:exercise_name].blank? normal_status(-1, "试卷标题不能为空!") if params[:exercise_name].blank?
normal_status(-1, "试卷标题不能超过60个字符") if (params[:exercise_name].length > 60) normal_status(-1, "试卷标题不能超过60个字符") if (params[:exercise_name].length > 60)
normal_status(-1, "试卷须知不能超过100个字符") if (params[:exercise_description].present? && params[:exercise_description].length > 100) normal_status(-1, "试卷须知不能超过100个字符") if (params[:exercise_description].present? &&
params[:exercise_description].length > 100)
end end
#判断设置的时间是否合理 #判断设置的时间是否合理
@ -1619,7 +1645,8 @@ class ExercisesController < ApplicationController
@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) && ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) 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)
#当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制
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
@ -1669,7 +1696,8 @@ class ExercisesController < ApplicationController
def check_exercise_public def check_exercise_public
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交 if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交
ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first 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 && @exercise.show_statistic unless @exercise.get_exercise_status(current_user.id) == 3 && ex_user.present? && ex_user.commit_status == 1 &&
@exercise.show_statistic
normal_status(-1,"学生暂不能查看") normal_status(-1,"学生暂不能查看")
end end
end end

Loading…
Cancel
Save