From 26e6ecba6dc09350e78263d5d3769147421cd5a9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 20 Jun 2019 18:53:56 +0800 Subject: [PATCH] fix bug --- app/controllers/exercises_controller.rb | 17 +++++++++-------- app/controllers/polls_controller.rb | 2 +- app/models/course.rb | 2 +- app/models/exercise.rb | 2 +- app/models/poll.rb | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 762c12797..2239f570d 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -436,7 +436,7 @@ class ExercisesController < ApplicationController exercise_status = @exercise.get_exercise_status(current_user.id) - if exercise_status == 1 && (course_group_ids - [0]).count > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 + if exercise_status == 1 && course_group_ids.size > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 unified_setting = params[:unified_setting] else unified_setting = @exercise.unified_setting @@ -450,7 +450,7 @@ class ExercisesController < ApplicationController answer_open = params[:answer_open] ? true : false #答案是否公开 # 统一设置或者分班为0,则更新试卷,并删除试卷分组 - if unified_setting || (course_group_ids.count == 0) + if unified_setting || (course_group_ids.size == 0) params_publish_time = params[:publish_time].blank? ? nil : params[:publish_time].to_time params_end_time = nil if params[:end_time].blank? @@ -798,12 +798,13 @@ class ExercisesController < ApplicationController if exercise_status == 2 #跳过已截止的或未发布的 g_course = params[:group_ids] if g_course.present? - user_course_groups= @course.teacher_course_groups.get_user_groups(current_user.id) - if user_course_groups.present? - teacher_course_group_ids = user_course_groups.pluck(:course_group_id) - else - teacher_course_group_ids = @course.course_groups.pluck(:id) - end + # user_course_groups= @course.teacher_course_groups.get_user_groups(current_user.id) + # if user_course_groups.present? + # teacher_course_group_ids = user_course_groups.pluck(:course_group_id) + # else + # teacher_course_group_ids = @course.course_groups.pluck(:id) + # end + teacher_course_group_ids = @course.charge_group_ids(current_user) if g_course.map(&:to_i).sort == teacher_course_group_ids.sort #开始为统一设置 exercise.exercise_group_settings.destroy_all new_ex_status = set_exercise_status(exercise.publish_time,Time.now) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 38fa973b5..ae93357cc 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -691,7 +691,7 @@ class PollsController < ApplicationController course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组 poll_status = @poll.get_poll_status(current_user.id) - if poll_status == 1 && (course_group_ids - [0]).count > 0 # 问卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按poll默认的来处理 + if poll_status == 1 && course_group_ids.size > 0 # 问卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按poll默认的来处理 unified_setting = params[:unified_setting] else unified_setting = @poll.unified_setting diff --git a/app/models/course.rb b/app/models/course.rb index dd2248d7c..dec8c1b50 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -121,7 +121,7 @@ class Course < ApplicationRecord end #当前老师的班级id - def teacher_course_group_ids(user_id) + def teacher_course_ids(user_id) course_teacher_member = teacher_course_groups.get_user_groups(user_id) #获取当前老师的分班 if course_teacher_member.blank? if none_group_count > 0 #有未分班的,则发布到未发布分班 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index e2623c692..b3feec12c 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -66,7 +66,7 @@ class Exercise < ApplicationRecord #当前用户已发布的班级id和试卷分组已发布的班级id的交集 def common_published_ids(user_id) - current_user_groups = course.teacher_course_group_ids(user_id) + current_user_groups = course.teacher_course_ids(user_id) if unified_setting if course.none_group_count > 0 #有未分班的,则发布到未发布分班 un_group_ids = [0] diff --git a/app/models/poll.rb b/app/models/poll.rb index fd9093fcc..b498eda4e 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -62,7 +62,7 @@ class Poll < ApplicationRecord #当前用户已发布的班级id和试卷分组已发布的班级id的交集 def poll_published_ids(user_id) - current_user_groups = course.teacher_course_group_ids(user_id) + current_user_groups = course.teacher_course_ids(user_id) if unified_setting if course.none_group_count > 0 #有未分班的,则发布到未发布 un_group_ids = [0]