From a34b0683c8b43300288cf383bb45d78ae3f535a3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 15 Nov 2019 13:56:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=91=E4=B8=8A=E5=AE=9E=E9=AA=8C=E5=AE=A4?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E8=AE=AD=E5=92=8C=E5=AE=9E=E8=B7=B5=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 10 ++++++++-- app/controllers/subjects_controller.rb | 4 ++++ app/models/laboratory.rb | 4 ++-- app/services/shixun_search_service.rb | 9 +++++++-- app/services/subject_search_service.rb | 9 +++++++-- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 15ee2a712..d48034051 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -974,8 +974,14 @@ class ShixunsController < ApplicationController end - @course_count = course_ids.length - @courses = Course.where(:id => course_ids).page(page).per(limit) + @courses = Course.where(:id => course_ids) + ## 云上实验室过滤 + unless current_laboratory.main_site? + @courses = @courses.where(laboratory_id: current_laboratory.id ) + end + + @course_count = @courses.count + @courses = @courses.page(page).per(limit) end # 将实训发送到课程 diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index c1a8b15cd..a5e64daaa 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -204,6 +204,10 @@ class SubjectsController < ApplicationController WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) @courses = Course.where(id: course_ids) + ## 云上实验室过滤 + unless current_laboratory.main_site? + @courses = @courses.where(laboratory_id: current_laboratory.id ) + end @none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id).to_i}").pluck(:shixun_id) end diff --git a/app/models/laboratory.rb b/app/models/laboratory.rb index 8b42c630f..45ef0c76e 100644 --- a/app/models/laboratory.rb +++ b/app/models/laboratory.rb @@ -9,10 +9,10 @@ class Laboratory < ApplicationRecord has_many :portal_images, dependent: :destroy has_many :laboratory_shixuns, dependent: :destroy - has_many :shixuns, through: :laboratory_shixuns, source: :shixun + # has_many :shixuns, through: :laboratory_shixuns, source: :shixun has_many :laboratory_subjects, dependent: :destroy - has_many :subjects, through: :laboratory_subjects, source: :subject + # has_many :subjects, through: :laboratory_subjects, source: :subject has_many :courses, dependent: :destroy has_many :competitions, dependent: :destroy diff --git a/app/services/shixun_search_service.rb b/app/services/shixun_search_service.rb index 86ffc6d95..e1eec9f50 100644 --- a/app/services/shixun_search_service.rb +++ b/app/services/shixun_search_service.rb @@ -36,8 +36,13 @@ class ShixunSearchService < ApplicationService @shixuns = @shixuns.where(trainee: params[:diff]) end - laboratory = Laboratory.find_by_subdomain(subdomain) - @shixuns = @shixuns.where(id: laboratory.shixuns) if laboratory + ## 云上实验室过滤 + unless current_laboratory.main_site? + @shixuns = @shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: current_laboratory.id }) + end + + # laboratory = Laboratory.find_by_subdomain(subdomain) + # @shixuns = @shixuns.where(id: laboratory.shixuns) if laboratory Shixun.search(keyword, search_options) end diff --git a/app/services/subject_search_service.rb b/app/services/subject_search_service.rb index aa0498e69..314763ceb 100644 --- a/app/services/subject_search_service.rb +++ b/app/services/subject_search_service.rb @@ -18,8 +18,13 @@ class SubjectSearchService < ApplicationService @subjects = Subject.visible.unhidden end - laboratory = Laboratory.find_by_subdomain(subdomain) - @subjects = @subjects.where(id: laboratory.subjects) if laboratory + # laboratory = Laboratory.find_by_subdomain(subdomain) + # @subjects = @subjects.where(id: laboratory.subjects) if laboratory + + ## 云上实验室过滤 + unless current_laboratory.main_site? + subjects = subjects.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: current_laboratory.id }) + end Subject.search(keyword, search_options) end