选用实训的调整

dev_course
cxt 5 years ago
parent 2a5b43eb12
commit 69c8b92dd1

@ -822,38 +822,72 @@ class HomeworkCommonsController < ApplicationController
# 选用实训
def shixuns
search = params[:search]
type = params[:type]
# 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭)
if current_user.admin?
@shixuns = Shixun.unhidden
else
none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id)
@main_catrgory = @course.course_modules.where(module_type: "shixun_homework")
@homework_category = @main_catrgory.take.course_second_categories
## 我的实训
@shixuns =
if params[:order_by] == 'mine'
current_user.my_shixuns
else
Shixun.unhidden
end
## 方向
if params[:tag_level].present? && params[:tag_id].present?
@shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i)
case params[:tag_level].to_i
when 1 #大类
@search_tags = Repertoire.find(params[:tag_id].to_i).name
when 2 #子类
@search_tags = SubRepertoire.find(params[:tag_id].to_i).name
when 3 #tag
tag = TagRepertoire.find(params[:tag_id].to_i)
@search_tags = "#{tag.sub_repertoire.name} / #{tag.name}"
end
end
@shixuns = Shixun.where.not(id: none_shixun_ids).unhidden
## 搜索关键字创建者、实训名称、院校名称
if params[:keyword].present?
keyword = params[:keyword].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
# 实训的所有标签
@tags = TagRepertoire.select([:id, :name]).joins(:shixuns).where(shixuns: {id: @shixuns}).distinct
## 筛选 状态
if params[:status].present? && params[:status].to_i != 0
params[:status] = [0, 1] if params[:status].to_i == 1
@shixuns = @shixuns.where(status: params[:status])
end
if params[:search] && params[:search].strip != ""
@shixuns = @shixuns.joins(:user).where("shixuns.name like ? or concat(users.lastname, users.firstname) like ?",
"%#{search}%", "%#{search}%").distinct
## 筛选 难度
if params[:diff].present? && params[:diff].to_i != 0
@shixuns = @shixuns.where(trainee: params[:diff])
end
unless type.blank? || type == "all"
@shixuns = @shixuns.joins(:shixun_tag_repertoires).where(shixun_tag_repertoires: {tag_repertoire_id: type}).distinct
## 排序参数
bsort = params[:sort] || 'desc'
case params[:order_by] || 'myshixuns_count'
when 'new'
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}")
when 'hot'
@shixuns = @shixuns.order("shixuns.status = 2 desc, myshixuns_count #{bsort}")
when 'mine'
@shixuns = @shixuns.order("shixuns.created_at #{bsort}")
else
@shixuns = @shixuns.order("shixuns.status = 2 desc, myshixuns_count #{bsort}")
end
@shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier]).reorder("shixuns.created_at desc")
@shixuns_count = @shixuns.size
@total_count = @shixuns.count
## 分页参数
page = params[:page] || 1
@shixuns = @shixuns.page(page).per(10)
page = params[:page] || 1
limit = params[:limit] || 15
@main_catrgory = @course.course_modules.where(module_type: "shixun_homework")
@homework_category = @main_catrgory.take.course_second_categories
@shixuns = @shixuns.includes(:tag_repertoires, :challenges).page(page).per(limit)
end
def create_shixun_homework

Loading…
Cancel
Save