You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/controllers/users/shixuns_controller.rb

26 lines
1.0 KiB

6 years ago
class Users::ShixunsController < Users::BaseController
def index
shixuns = Users::ShixunService.new(observed_user, query_params).call
## 云上实验室过滤
if current_laboratory.main_site?
not_shixun_ids = Shixun.joins(:laboratory_shixuns).where("laboratory_shixuns.laboratory_id != #{current_laboratory.id}")
5 years ago
shixuns = shixuns.where.not(id: not_shixun_ids)
else
5 years ago
shixuns = shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: current_laboratory.id })
end
6 years ago
@count = shixuns.count
@shixuns = paginate(shixuns.includes(:first_tag_repertoire), special: observed_user.is_teacher?)
ids = @shixuns.map(&:id)
@finished_challenges_count_map = Game.joins(:myshixun).where(user_id: observed_user.id, status: 2)
.where(myshixuns: { shixun_id: ids }).group('myshixuns.shixun_id').count
6 years ago
end
private
def query_params
params.permit(:category, :status, :sort_by, :sort_direction)
end
end