|
|
|
@ -98,6 +98,39 @@ class ShixunsController < ApplicationController
|
|
|
|
|
.each_with_object({}) { |r, obj| obj[r.shixun_id] = r.name }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def shixun_list
|
|
|
|
|
type = params[:type] || "all"
|
|
|
|
|
|
|
|
|
|
# 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭)
|
|
|
|
|
if current_user.admin?
|
|
|
|
|
@shixuns = Shixun.unhidden
|
|
|
|
|
else
|
|
|
|
|
none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id)
|
|
|
|
|
|
|
|
|
|
@shixuns = Shixun.where.not(id: none_shixun_ids).unhidden
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
## 搜索关键字创建者、实训名称、院校名称
|
|
|
|
|
unless params[:search].blank?
|
|
|
|
|
keyword = params[:search].strip
|
|
|
|
|
@shixuns = @shixuns.joins(user: [user_extenison: :school]).
|
|
|
|
|
where("schools.name like '%#{keyword}%'
|
|
|
|
|
or concat(lastname, firstname) like '%#{keyword}%'
|
|
|
|
|
or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
## 筛选 难度
|
|
|
|
|
if params[:diff].present? && params[:diff].to_i != 0
|
|
|
|
|
@shixuns = @shixuns.where(trainee: params[:diff])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@total_count = @shixuns.count
|
|
|
|
|
page = params[:page] || 1
|
|
|
|
|
limit = params[:limit] || 15
|
|
|
|
|
|
|
|
|
|
@shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
## 获取顶部菜单
|
|
|
|
|
def menus
|
|
|
|
|
@repertoires = Repertoire.includes(sub_repertoires: [:tag_repertoires]).order("updated_at asc")
|
|
|
|
|