dev_home
cxt 5 years ago
parent 2c048d1fcf
commit 91109b07bc

@ -40,11 +40,21 @@ class SearchService < ApplicationService
def extra_options
case params[:type].to_s.strip
when 'shixun' then
shixun_ids = Laboratory.current.shixuns.pluck(:id)
Laboratory.current.main_site? ? {} : { where: { id: shixun_ids } }
if Laboratory.current.main_site?
not_shixun_ids = Shixun.joins(:laboratory_shixuns).where("laboratory_shixuns.laboratory_id != #{Laboratory.current.id}")
shixun_ids = Shixun.where.not(id: not_shixun_ids).pluck(:id)
else
shixun_ids = Laboratory.current.shixuns.pluck(:id)
end
{ where: { id: shixun_ids } }
when 'subject' then
subject_ids = Laboratory.current.subjects.pluck(:id)
Laboratory.current.main_site? ? {} : { where: { id: subject_ids } }
if Laboratory.current.main_site?
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{Laboratory.current.id}")
subject_ids = Subject.where.not(id: not_subject_ids).pluck(:id)
else
subject_ids = Laboratory.current.subjects.pluck(:id)
end
{ where: { id: subject_ids } }
when 'course' then
{ where: { laboratory_id: Laboratory.current.id } }
else

@ -37,8 +37,11 @@ class ShixunSearchService < ApplicationService
end
## 云上实验室过滤
unless laboratory.main_site?
@shixuns = @shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: @laboratory.id })
if laboratory.main_site?
not_shixun_ids = Shixun.joins(:laboratory_shixuns).where("laboratory_shixuns.laboratory_id != #{laboratory.id}")
@shixuns = @shixuns.where.not(id: not_shixun_ids)
else
@shixuns = @shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: laboratory.id })
end
# laboratory = Laboratory.find_by_subdomain(subdomain)

@ -22,7 +22,10 @@ class SubjectSearchService < ApplicationService
# @subjects = @subjects.where(id: laboratory.subjects) if laboratory
## 云上实验室过滤
unless laboratory.main_site?
if laboratory.main_site?
not_subject_ids = Subject.joins(:laboratory_subjects).where("laboratory_subjects.laboratory_id != #{laboratory.id}")
@subjects = @subjects.where.not(id: not_subject_ids)
else
@subjects = @subjects.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: laboratory.id })
end

Loading…
Cancel
Save