选用实训的调整

dev_course
cxt 5 years ago
parent 2a5b43eb12
commit 69c8b92dd1

@ -822,38 +822,72 @@ class HomeworkCommonsController < ApplicationController
# 选用实训 # 选用实训
def shixuns def shixuns
search = params[:search] @main_catrgory = @course.course_modules.where(module_type: "shixun_homework")
type = params[:type] @homework_category = @main_catrgory.take.course_second_categories
# 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭)
if current_user.admin? ## 我的实训
@shixuns = Shixun.unhidden @shixuns =
if params[:order_by] == 'mine'
current_user.my_shixuns
else else
none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) 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 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 ?", if params[:diff].present? && params[:diff].to_i != 0
"%#{search}%", "%#{search}%").distinct @shixuns = @shixuns.where(trainee: params[:diff])
end 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 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 page = params[:page] || 1
@shixuns = @shixuns.page(page).per(10) limit = params[:limit] || 15
@main_catrgory = @course.course_modules.where(module_type: "shixun_homework") @shixuns = @shixuns.includes(:tag_repertoires, :challenges).page(page).per(limit)
@homework_category = @main_catrgory.take.course_second_categories
end end
def create_shixun_homework def create_shixun_homework

Loading…
Cancel
Save