Merge branch 'dev_course' into dev_aliyun

dev_forum
cxt 5 years ago
commit c6d6b44660

@ -819,38 +819,69 @@ 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 = Shixun.where.not(id: none_shixun_ids).unhidden
## 我的实训
@shixuns =
if params[:order_by] == 'mine'
current_user.my_shixuns.unhidden
else
if current_user.admin?
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)
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(: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}%")
end
# 类型
if select
@subjects = @subjects.where(repertoire_id: select)
end
unless type.blank? || type == "all"
@subjects = @subjects.where(repertoire_id: type)
end
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

@ -91,4 +91,9 @@ class Subject < ApplicationRecord
def published?
status == 2
end
def shixun_tags
challenges = Challenge.where(shixun_id: shixuns.unhidden)
@tags = ChallengeTag.where(challenge_id: challenges).pluck(:name).uniq
end
end

@ -1,12 +1,15 @@
json.tags @tags do |tag|
json.tag_id tag.id
json.tag_name tag.name
json.shixun_list @shixuns do |shixun|
json.shixun_identifier shixun.identifier
json.name shixun.name
json.creator shixun.user&.full_name
json.creator_login shixun.user&.login
json.school shixun.user&.school_name
json.myshixuns_count shixun.myshixuns_count
json.level level_to_s(shixun.trainee)
json.challenge_tags shixun.challenge_tags_name
end
json.shixun_list do
json.partial! 'shixuns/choose_shixun', locals: {shixuns: @shixuns}
end
json.shixuns_count @shixuns_count
json.shixuns_count @total_count
json.search_tags @search_tags
json.partial! 'homework_commons/second_category', locals: {main_catrgory: @main_catrgory, homework_category: @homework_category}

@ -6,8 +6,12 @@ end
json.subject_list @subjects do |subject|
json.subject_id subject.id
json.subject_name subject.name
json.challenge_tags subject.shixun_tags
json.shixun_count subject.shixuns.unhidden.size
json.myshixun_count subject.shixuns.pluck(:myshixuns_count).sum
json.creator subject.user&.full_name
json.creator_login subject.user&.login
json.school subject.user&.school_name
end
json.subjects_count @subjects_count
json.subjects_count @total_count
Loading…
Cancel
Save