|
|
|
@ -819,38 +819,69 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
# 选用实训
|
|
|
|
|
def shixuns
|
|
|
|
|
search = params[:search]
|
|
|
|
|
type = params[:type]
|
|
|
|
|
# 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭)
|
|
|
|
|
@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.unhidden
|
|
|
|
|
else
|
|
|
|
|
if current_user.admin?
|
|
|
|
|
@shixuns = Shixun.unhidden
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
# 实训的所有标签
|
|
|
|
|
@tags = TagRepertoire.select([:id, :name]).joins(:shixuns).where(shixuns: {id: @shixuns}).distinct
|
|
|
|
|
## 搜索关键字创建者、实训名称、院校名称
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
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] || 'hot'
|
|
|
|
|
when 'hot'
|
|
|
|
|
@shixuns = @shixuns.order("myshixuns_count #{bsort}")
|
|
|
|
|
when 'mine'
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.created_at #{bsort}")
|
|
|
|
|
else
|
|
|
|
|
@shixuns = @shixuns.order("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)
|
|
|
|
|
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(:challenges, user: [user_extension: :school]).page(page).per(limit)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create_shixun_homework
|
|
|
|
@ -876,30 +907,65 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
# 选用实训课程
|
|
|
|
|
def subjects
|
|
|
|
|
@tags = Repertoire.where(nil).order("updated_at desc")
|
|
|
|
|
select = params[:select] # 路径导航类型
|
|
|
|
|
reorder = params[:order] || "myshixun_count"
|
|
|
|
|
sort = params[:sort] || "desc"
|
|
|
|
|
search = params[:search]
|
|
|
|
|
type = params[:type]
|
|
|
|
|
# 显示所有未隐藏的、已发布的实训课程
|
|
|
|
|
@subjects = Subject.select([:id, :name, :status, :repertoire_id]).visible.unhidden
|
|
|
|
|
|
|
|
|
|
@tags = Repertoire.select([:id, :name]).where(id: @subjects.pluck(:repertoire_id).uniq).order("updated_at desc")
|
|
|
|
|
## 分页参数
|
|
|
|
|
page = params[:page] || 1
|
|
|
|
|
limit = params[:limit] || 15
|
|
|
|
|
offset = (page.to_i-1) * limit
|
|
|
|
|
|
|
|
|
|
# 最热排序
|
|
|
|
|
if reorder == "myshixun_count"
|
|
|
|
|
if select
|
|
|
|
|
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
|
|
|
|
|
subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns
|
|
|
|
|
on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where
|
|
|
|
|
subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%'
|
|
|
|
|
AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}")
|
|
|
|
|
else
|
|
|
|
|
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status,
|
|
|
|
|
subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns
|
|
|
|
|
on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where
|
|
|
|
|
`subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%'
|
|
|
|
|
GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}")
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
# 我的路径
|
|
|
|
|
if reorder == "mine"
|
|
|
|
|
mine_subject_id = StageShixun.find_by_sql("select DISTINCT(subject_id) from stage_shixuns where shixun_id in
|
|
|
|
|
(select distinct(shixun_id) from myshixuns where user_id=#{current_user.id})").map(&:subject_id)
|
|
|
|
|
manage_subject_id = SubjectMember.where(user_id: current_user.id).pluck(:subject_id)
|
|
|
|
|
total_subject_id = (mine_subject_id + manage_subject_id).uniq
|
|
|
|
|
@subjects = Subject.where(id: total_subject_id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if params[:search] && params[:search].strip != ""
|
|
|
|
|
@subjects = @subjects.joins(:user).where("subjects.name like ? or concat(users.lastname, users.firstname) like ?",
|
|
|
|
|
"%#{search}%", "%#{search}%")
|
|
|
|
|
# 类型
|
|
|
|
|
if select
|
|
|
|
|
@subjects = @subjects.where(repertoire_id: select)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
unless type.blank? || type == "all"
|
|
|
|
|
@subjects = @subjects.where(repertoire_id: type)
|
|
|
|
|
if search.present?
|
|
|
|
|
@subjects = @subjects.where("name like ?", "%#{search}%")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@subjects = @subjects.reorder("subjects.created_at desc")
|
|
|
|
|
@subjects_count = @subjects.size
|
|
|
|
|
# 排序
|
|
|
|
|
order_str = "updated_at #{sort}"
|
|
|
|
|
@subjects = @subjects.reorder(order_str)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
## 分页参数
|
|
|
|
|
page = params[:page] || 1
|
|
|
|
|
@subjects = @subjects.page(page).per(10)
|
|
|
|
|
@total_count = @subjects.size
|
|
|
|
|
|
|
|
|
|
@subjects = @subjects.includes(:shixuns)
|
|
|
|
|
if reorder != "myshixun_count"
|
|
|
|
|
@subjects = @subjects.page(page).per(limit).includes(:shixuns, user: [user_extension: :school])
|
|
|
|
|
else
|
|
|
|
|
@subjects = @subjects[offset, limit]
|
|
|
|
|
subject_ids = @subjects.pluck(:id)
|
|
|
|
|
@subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns, user: [user_extension: :school])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create_subject_homework
|
|
|
|
|