diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index eaeb458a3..513f980d8 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -188,7 +188,7 @@ module ExercisesHelper if ex_ordered all_user_answers = effictive_users.pluck(:answer_text) null_stand_choice.each_with_index do |s,index| - s_choice_text = null_stand_text[index] + s_choice_text = null_stand_text[index].to_s.strip user_count = 0 # user_count = user_count + effictive_users.where("exercise_choice_id = ? and answer_text = ?",s,s_choice_text).pluck(:user_id).uniq.size user_count = user_count + effictive_users.select{|answer| answer.exercise_choice_id == s && answer.answer_text == s_choice_text}.size diff --git a/app/services/shixun_search_service.rb b/app/services/shixun_search_service.rb index 710910100..32488a7c3 100644 --- a/app/services/shixun_search_service.rb +++ b/app/services/shixun_search_service.rb @@ -23,10 +23,9 @@ class ShixunSearchService < ApplicationService if User.current.admin? || User.current.business? || !User.current.school_id @shixuns = @shixuns.where(hidden: 0) else - shixun_ids = ShixunSchool.where(school_id: User.current.school_id).pluck(:shixun_id) - shixun_ids = shixun_ids.reject(&:blank?).length == 0 ? -1 : shixun_ids.join(",") + none_shixun_ids = ShixunSchool.where("school_id != #{User.current.school_id}").pluck(:shixun_id) - @shixuns = @shixuns.where("use_scope = 1 or id in (#{shixun_ids})").unhidden.published.or(@shixuns.where(id: User.current.shixuns)) + @shixuns = @shixuns.where.not(id: none_shixun_ids).where(hidden: 0, status: 2, public: 2).or(@shixuns.where(id: User.current.shixuns)) end end diff --git a/db/migrate/20200114062353_migrate_coures_member_group.rb b/db/migrate/20200114062353_migrate_coures_member_group.rb new file mode 100644 index 000000000..b9992cb50 --- /dev/null +++ b/db/migrate/20200114062353_migrate_coures_member_group.rb @@ -0,0 +1,25 @@ +class MigrateCouresMemberGroup < ActiveRecord::Migration[5.2] + def change + course_ids = [377, 657, 715, 777, 973, 1093, 1131, 1180, 1309, 1920, 2037, 2346, 2354, 2493, 2752, 2920, 3000, + 3141, 3240, 3350, 3351, 3353, 3387, 3533, 3796] + + courses = Course.where(id: course_ids) + + courses.each do |course| + group_ids = course.course_groups.pluck(:id) + [0] + course.course_members.where.not(course_group_id: group_ids).each do |member| + if CourseGroup.where(course_id: course.id, name: member.course_group_name).exists? + new_group = CourseGroup.where(course_id: course.id, name: member.course_group_name).first + else + # position = CourseGroup.where(course_id: course.id).order("position desc").first&.position.to_i + 1 + new_group = course.course_groups.create!(name: member.course_group_name) + course.exercise_group_settings.where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id) + course.attachment_group_settings.where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id) + HomeworkGroupReview.where(homework_common_id: course.homework_commons.pluck(:id)).where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id) + course.homework_group_settings.where(course_group_id: member.course_group_id).update_all(course_group_id: new_group.id) + end + member.update!(course_group_id: new_group.id) + end + end + end +end diff --git a/db/migrate/20200114071420_migrate_course_group_member_count.rb b/db/migrate/20200114071420_migrate_course_group_member_count.rb new file mode 100644 index 000000000..aad9dcc9c --- /dev/null +++ b/db/migrate/20200114071420_migrate_course_group_member_count.rb @@ -0,0 +1,4 @@ +class MigrateCourseGroupMemberCount < ActiveRecord::Migration[5.2] + def change + end +end diff --git a/db/migrate/20200114071917_migrate_coure_group_position.rb b/db/migrate/20200114071917_migrate_coure_group_position.rb new file mode 100644 index 000000000..fc04e1bcb --- /dev/null +++ b/db/migrate/20200114071917_migrate_coure_group_position.rb @@ -0,0 +1,14 @@ +class MigrateCoureGroupPosition < ActiveRecord::Migration[5.2] + def change + course_ids = [377, 657, 715, 777, 973, 1093, 1131, 1180, 1309, 1920, 2037, 2346, 2354, 2493, 2752, 2920, 3000, + 3141, 3240, 3350, 3351, 3353, 3387, 3533, 3796] + + courses = Course.where(id: course_ids) + + courses.each do |course| + CourseGroup.where(course_id: course.id).reorder("position ASC, CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").each_with_index do |group, index| + group.update!(position: index+1) + end + end + end +end