Merge branch 'dev_course' into dev_aliyun

dev_forum
cxt 5 years ago
commit c6d6b44660

@ -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

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

@ -1,12 +1,15 @@
json.tags @tags do |tag| json.shixun_list @shixuns do |shixun|
json.tag_id tag.id json.shixun_identifier shixun.identifier
json.tag_name tag.name 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 end
json.shixun_list do json.shixuns_count @total_count
json.partial! 'shixuns/choose_shixun', locals: {shixuns: @shixuns} json.search_tags @search_tags
end
json.shixuns_count @shixuns_count
json.partial! 'homework_commons/second_category', locals: {main_catrgory: @main_catrgory, homework_category: @homework_category} 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_list @subjects do |subject|
json.subject_id subject.id json.subject_id subject.id
json.subject_name subject.name json.subject_name subject.name
json.challenge_tags subject.shixun_tags
json.shixun_count subject.shixuns.unhidden.size json.shixun_count subject.shixuns.unhidden.size
json.myshixun_count subject.shixuns.pluck(:myshixuns_count).sum 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 end
json.subjects_count @subjects_count json.subjects_count @total_count
Loading…
Cancel
Save