From 31cdcff85384ab0b2c172f63762fecfec0f7b998 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 24 Jun 2019 10:33:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E9=A3=8E?= =?UTF-8?q?=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 72 +++++++++++++++++-------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index e4204d9d1..e1a5ce826 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -53,8 +53,11 @@ class ExercisesController < ApplicationController @exercises = member_show_exercises.present? ? 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.present? ? member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) : [] + 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.present? ? + member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) + : [] end else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 @is_teacher_or = 0 @@ -65,13 +68,20 @@ class ExercisesController < ApplicationController 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_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.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 - @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 else @exercises = @exercises.exercise_by_status(choose_type) @@ -412,7 +422,8 @@ class ExercisesController < ApplicationController @user_permission = 2 @user_course_groups = @course.teacher_group(current_user.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_publish_count = get_user_permission_course(exercise_ids,2).count #判断当前用户是否有试卷已发布的分班,用于显示立即截止/撤销发布 @exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断当前用户是否有试卷未发布的分班,用户显示立即发布 @@ -451,7 +462,7 @@ class ExercisesController < ApplicationController # 统一设置或者分班为0,则更新试卷,并删除试卷分组 if unified_setting || (course_group_ids.size == 0) - params_publish_time = params[:publish_time].blank? ? nil : params[:publish_time].to_time + params_publish_time = params[:publish_time].blank? ? nil : params[:publish_time].to_time params_end_time = nil if params[:end_time].blank? if params_publish_time.present? @@ -507,10 +518,12 @@ class ExercisesController < ApplicationController end # 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) #判断该分班是否存在 - 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 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 end if error_count == 0 @@ -692,7 +705,8 @@ class ExercisesController < ApplicationController if exercise.unified_setting ex_status = exercise.exercise_status #则为试卷的状态 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 if ex_status == 1 #如果试卷存在已发布的,或者是已截止的,那么则直接跳过 g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改 @@ -891,11 +905,13 @@ class ExercisesController < ApplicationController if exercise_user.present? 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) - 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_answers = exercise_user.user.exercise_answers.search_answer_users("exercise_question_id",ex_question_ids) 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 normal_status(0,"撤销回答成功") else @@ -923,11 +939,13 @@ class ExercisesController < ApplicationController if params[:realname].present? search_name = params[:realname] #搜索用户的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 if params[:student_id].present? 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 sort = params[:sort] ? params[:sort] : "asc" @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.update_all(redo_option) 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 - ExerciseShixunAnswer.search_shixun_answers("user_id",user_ids).search_shixun_answers("exercise_question_id",exercise_question_ids).destroy_all + ExerciseAnswer.search_answer_users("user_id",user_ids) + .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,"已成功打回重做!") else @@ -1005,13 +1025,17 @@ class ExercisesController < ApplicationController @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 #当前用户为老师/试卷已截止/试卷已提交不可编辑 else @user_exercise_status = 0 #可编辑 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 @exercise_questions = @exercise_questions.order("RAND()") @@ -1266,7 +1290,8 @@ class ExercisesController < ApplicationController tip_exception(403,"无权限操作") else 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} end } @@ -1426,7 +1451,8 @@ class ExercisesController < ApplicationController def validates_exercise_params normal_status(-1, "试卷标题不能为空!") if params[:exercise_name].blank? 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 #判断设置的时间是否合理 @@ -1619,7 +1645,8 @@ class ExercisesController < ApplicationController @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id).first #查找当前用户是否有过答题 if @user_course_identity == Course::STUDENT 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] 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 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 && @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,"学生暂不能查看") end end