子站同步实践课程和实训

chromesetting
cxt 5 years ago
parent d829679137
commit 008b15a967

@ -10,7 +10,7 @@ module LaboratoryHelper
end end
def current_laboratory def current_laboratory
@_current_laboratory ||= (Laboratory.find_by_subdomain(request.subdomain) || Laboratory.find(2)) @_current_laboratory ||= (Laboratory.find_by_subdomain(request.subdomain) || Laboratory.find(1))
end end
def default_laboratory def default_laboratory

@ -26,22 +26,7 @@ class ShixunsController < ApplicationController
## 获取课程列表 ## 获取课程列表
def index def index
## 我的实训 @shixuns = current_laboratory.shixuns.unhidden
@shixuns =
if params[:order_by] == 'mine'
tip_exception(401, "..") unless current_user.logged?
current_user.my_shixuns
else
Shixun.unhidden
end
## 云上实验室过滤
unless current_laboratory.main_site?
@shixuns = @shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: current_laboratory.id })
else
not_shixun_ids = Shixun.joins(:laboratory_shixuns).where("laboratory_shixuns.laboratory_id != #{current_laboratory.id}")
@shixuns = @shixuns.where.not(id: not_shixun_ids)
end
## 方向 ## 方向
if params[:tag_level].present? && params[:tag_id].present? if params[:tag_level].present? && params[:tag_id].present?

@ -1,14 +1,6 @@
class Users::ShixunsController < Users::BaseController class Users::ShixunsController < Users::BaseController
def index def index
shixuns = Users::ShixunService.new(observed_user, query_params).call shixuns = Users::ShixunService.new(observed_user, query_params, current_laboratory).call
## 云上实验室过滤
if current_laboratory.main_site?
not_shixun_ids = Shixun.joins(:laboratory_shixuns).where("laboratory_shixuns.laboratory_id != #{current_laboratory.id}")
shixuns = shixuns.where.not(id: not_shixun_ids)
else
shixuns = shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: current_laboratory.id })
end
@count = shixuns.count @count = shixuns.count
@shixuns = paginate(shixuns.includes(:first_tag_repertoire), special: observed_user.is_teacher?) @shixuns = paginate(shixuns.includes(:first_tag_repertoire), special: observed_user.is_teacher?)

@ -40,13 +40,7 @@ class SearchService < ApplicationService
def extra_options def extra_options
case params[:type].to_s.strip case params[:type].to_s.strip
when 'shixun' then when 'shixun' then
if Laboratory.current.main_site? { where: { id: Laboratory.current.shixuns.pluck(:id) } }
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 when 'subject' then
{ where: { id: Laboratory.current.subjects.pluck(:id) } } { where: { id: Laboratory.current.subjects.pluck(:id) } }
when 'course' then when 'course' then

@ -14,16 +14,18 @@ class ShixunSearchService < ApplicationService
# 状态:已发布/未发布 # 状态:已发布/未发布
status = params[:status] || "all" status = params[:status] || "all"
@shixuns = laboratory.shixuns.none_closed
# 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭) # 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭)
if type == "mine" if type == "mine"
@shixuns = User.current.shixuns.none_closed @shixuns = @shixuns.where(id: User.current.shixuns)
else else
if User.current.admin? || User.current.business? if User.current.admin? || User.current.business?
@shixuns = Shixun.none_closed.where(hidden: 0) @shixuns = @shixuns.where(hidden: 0)
else else
none_shixun_ids = ShixunSchool.where("school_id != #{User.current.school_id}").pluck(:shixun_id) none_shixun_ids = ShixunSchool.where("school_id != #{User.current.school_id}").pluck(:shixun_id)
@shixuns = Shixun.where.not(id: none_shixun_ids).none_closed.where(hidden: 0) @shixuns = @shixuns.where.not(id: none_shixun_ids).where(hidden: 0)
end end
end end
@ -36,17 +38,6 @@ class ShixunSearchService < ApplicationService
@shixuns = @shixuns.where(trainee: params[:diff]) @shixuns = @shixuns.where(trainee: params[:diff])
end end
## 云上实验室过滤
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)
# @shixuns = @shixuns.where(id: laboratory.shixuns) if laboratory
Shixun.search(keyword, search_options) Shixun.search(keyword, search_options)
end end

@ -1,12 +1,14 @@
class Users::ShixunService class Users::ShixunService
attr_reader :user, :params attr_reader :user, :params, :laboratory
def initialize(user, params) def initialize(user, params, laboratory)
@user = user @user = user
@params = params @params = params
@laboratory = laboratory
end end
def call def call
shixuns = category_scope_shixuns shixuns = category_scope_shixuns
shixuns = user_policy_filter(shixuns) shixuns = user_policy_filter(shixuns)
@ -19,12 +21,12 @@ class Users::ShixunService
def category_scope_shixuns def category_scope_shixuns
case params[:category] case params[:category]
when 'study' then when 'study' then
user.study_shixuns laboratory.shixuns.where(id: user.study_shixuns)
when 'manage' then when 'manage' then
user.shixuns laboratory.shixuns.where(id: user.shixuns)
else else
ids = user.study_shixuns.pluck(:id) + user.shixuns.pluck(:id) ids = user.study_shixuns.pluck(:id) + user.shixuns.pluck(:id)
Shixun.where(id: ids) laboratory.shixuns.where(id: ids)
end end
end end

Loading…
Cancel
Save