|
|
@ -819,38 +819,69 @@ 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
|
|
|
|
# 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭)
|
|
|
|
|
|
|
|
|
|
|
|
## 我的实训
|
|
|
|
|
|
|
|
@shixuns =
|
|
|
|
|
|
|
|
if params[:order_by] == 'mine'
|
|
|
|
|
|
|
|
current_user.my_shixuns.unhidden
|
|
|
|
|
|
|
|
else
|
|
|
|
if current_user.admin?
|
|
|
|
if current_user.admin?
|
|
|
|
@shixuns = Shixun.unhidden
|
|
|
|
Shixun.unhidden
|
|
|
|
else
|
|
|
|
else
|
|
|
|
none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id)
|
|
|
|
none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id)
|
|
|
|
|
|
|
|
|
|
|
|
@shixuns = Shixun.where.not(id: none_shixun_ids).unhidden
|
|
|
|
@shixuns = Shixun.where.not(id: none_shixun_ids).unhidden
|
|
|
|
end
|
|
|
|
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 ?",
|
|
|
|
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] || '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
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier]).reorder("shixuns.created_at desc")
|
|
|
|
@total_count = @shixuns.count
|
|
|
|
@shixuns_count = @shixuns.size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 分页参数
|
|
|
|
## 分页参数
|
|
|
|
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(:challenges, user: [user_extension: :school]).page(page).per(limit)
|
|
|
|
@homework_category = @main_catrgory.take.course_second_categories
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def create_shixun_homework
|
|
|
|
def create_shixun_homework
|
|
|
@ -876,30 +907,65 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
# 选用实训课程
|
|
|
|
# 选用实训课程
|
|
|
|
def subjects
|
|
|
|
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]
|
|
|
|
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 ?",
|
|
|
|
if select
|
|
|
|
"%#{search}%", "%#{search}%")
|
|
|
|
@subjects = @subjects.where(repertoire_id: select)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
unless type.blank? || type == "all"
|
|
|
|
if search.present?
|
|
|
|
@subjects = @subjects.where(repertoire_id: type)
|
|
|
|
@subjects = @subjects.where("name like ?", "%#{search}%")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@subjects = @subjects.reorder("subjects.created_at desc")
|
|
|
|
# 排序
|
|
|
|
@subjects_count = @subjects.size
|
|
|
|
order_str = "updated_at #{sort}"
|
|
|
|
|
|
|
|
@subjects = @subjects.reorder(order_str)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
## 分页参数
|
|
|
|
@total_count = @subjects.size
|
|
|
|
page = params[:page] || 1
|
|
|
|
|
|
|
|
@subjects = @subjects.page(page).per(10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def create_subject_homework
|
|
|
|
def create_subject_homework
|
|
|
|