|
|
|
@ -448,7 +448,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
tip_exception("发布时间不能早于当前时间") if params[:publish_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
tip_exception("截止时间不能早于当前时间") if params[:end_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
tip_exception("截止时间不能早于发布时间") if params[:publish_time] > params[:end_time]
|
|
|
|
|
tip_exception("截止时间不能早于课堂结束时间") if @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day
|
|
|
|
|
|
|
|
|
|
@homework.unified_setting = 1
|
|
|
|
|
@homework.homework_group_settings.destroy_all
|
|
|
|
@ -470,7 +470,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
tip_exception("发布时间不能早于当前时间") if setting[:publish_time] <= strf_time(Time.now)
|
|
|
|
|
tip_exception("截止时间不能早于当前时间") if setting[:end_time] <= strf_time(Time.now)
|
|
|
|
|
tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time]
|
|
|
|
|
tip_exception("截止时间不能早于课堂结束时间") if @course.end_date.present? && setting[:end_time] > @course.end_date.end_of_day
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && setting[:end_time] > @course.end_date.end_of_day
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
publish_time = setting[:publish_time] == "" ? Time.now : setting[:publish_time]
|
|
|
|
@ -504,7 +504,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
if @homework.end_time > Time.now && @homework.unified_setting
|
|
|
|
|
tip_exception("截止时间不能为空") if params[:end_time].blank?
|
|
|
|
|
tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now)
|
|
|
|
|
tip_exception("截止时间不能早于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day)
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day)
|
|
|
|
|
|
|
|
|
|
@homework.end_time = params[:end_time]
|
|
|
|
|
|
|
|
|
@ -522,7 +522,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
tip_exception("截止时间不能早于等于当前时间") if setting[:end_time] <= strf_time(Time.now)
|
|
|
|
|
tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time]
|
|
|
|
|
tip_exception("截止时间不能早于课堂结束时间") if setting[:end_time] > strf_time(@course.end_date.end_of_day)
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && setting[:end_time] > strf_time(@course.end_date.end_of_day)
|
|
|
|
|
|
|
|
|
|
group_settings.none_published.update_all(publish_time: setting[:publish_time])
|
|
|
|
|
group_settings.none_end.update_all(end_time: setting[:end_time])
|
|
|
|
@ -822,66 +822,98 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
@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?
|
|
|
|
|
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
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
## 方向
|
|
|
|
|
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
|
|
|
|
|
@shixuns = Shixun.where.not(id: none_shixun_ids).unhidden
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
## 搜索关键字创建者、实训名称、院校名称
|
|
|
|
|
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
|
|
|
|
|
# 实训的所有标签
|
|
|
|
|
@tags = TagRepertoire.select([:id, :name]).joins(:shixuns).where(shixuns: {id: @shixuns}).distinct
|
|
|
|
|
|
|
|
|
|
## 筛选 难度
|
|
|
|
|
if params[:diff].present? && params[:diff].to_i != 0
|
|
|
|
|
@shixuns = @shixuns.where(trainee: params[:diff])
|
|
|
|
|
if params[:search] && params[:search].strip != ""
|
|
|
|
|
@shixuns = @shixuns.joins(:user).where("shixuns.name like ? or concat(users.lastname, users.firstname) like ?",
|
|
|
|
|
"%#{search}%", "%#{search}%").distinct
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
## 排序参数
|
|
|
|
|
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}")
|
|
|
|
|
unless type.blank? || type == "all"
|
|
|
|
|
@shixuns = @shixuns.joins(:shixun_tag_repertoires).where(shixun_tag_repertoires: {tag_repertoire_id: type}).distinct
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@total_count = @shixuns.count
|
|
|
|
|
@shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier, :user_id, :trainee]).reorder("shixuns.created_at desc")
|
|
|
|
|
@shixuns_count = @shixuns.size
|
|
|
|
|
|
|
|
|
|
## 分页参数
|
|
|
|
|
page = params[:page] || 1
|
|
|
|
|
limit = params[:limit] || 15
|
|
|
|
|
|
|
|
|
|
@shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit)
|
|
|
|
|
page = params[:page] || 1
|
|
|
|
|
@shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(10)
|
|
|
|
|
|
|
|
|
|
# 新版用下面的代码
|
|
|
|
|
# ## 我的实训
|
|
|
|
|
# @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
|
|
|
|
|
#
|
|
|
|
|
# ## 搜索关键字创建者、实训名称、院校名称
|
|
|
|
|
# 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[:diff].present? && params[:diff].to_i != 0
|
|
|
|
|
# @shixuns = @shixuns.where(trainee: params[:diff])
|
|
|
|
|
# end
|
|
|
|
|
#
|
|
|
|
|
# ## 排序参数
|
|
|
|
|
# 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
|
|
|
|
|
#
|
|
|
|
|
# @total_count = @shixuns.count
|
|
|
|
|
#
|
|
|
|
|
# ## 分页参数
|
|
|
|
|
# page = params[:page] || 1
|
|
|
|
|
# limit = params[:limit] || 15
|
|
|
|
|
#
|
|
|
|
|
# @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit)
|
|
|
|
|
#
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create_shixun_homework
|
|
|
|
@ -1016,7 +1048,8 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
def publish_homework
|
|
|
|
|
tip_exception("请至少选择一个分班") if params[:group_ids].blank? && @course.course_groups.size != 0
|
|
|
|
|
tip_exception("缺少截止时间参数") if params[:end_time].blank?
|
|
|
|
|
tip_exception("截止时间必须晚于当前时间") if params[:end_time] <= strf_time(Time.now)
|
|
|
|
|
tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now)
|
|
|
|
|
tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day)
|
|
|
|
|
|
|
|
|
|
homeworks = @course.homework_commons.where(id: params[:homework_ids])
|
|
|
|
|
homeworks = homeworks.includes(:homework_group_settings, :homework_detail_manual)
|
|
|
|
@ -1035,6 +1068,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
if @course.course_groups.where(id: publish_groups).size == @course.course_groups.size
|
|
|
|
|
homework.homework_group_settings.destroy_all
|
|
|
|
|
homework.unified_setting = true
|
|
|
|
|
homework.end_time = params[:end_time]
|
|
|
|
|
else
|
|
|
|
|
homework.unified_setting = false
|
|
|
|
|
# 创建作业分班设置:homework_group_setting
|
|
|
|
@ -1053,7 +1087,7 @@ class HomeworkCommonsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
homework.publish_time = Time.now
|
|
|
|
|
|
|
|
|
|
# 截止时间不为空的保持原状,为空的改为一个月后, 非统一设置的更新为最大分班截止时间
|
|
|
|
|
# 截止时间的处理
|
|
|
|
|
if homework.end_time.nil?
|
|
|
|
|
homework.end_time = params[:end_time]
|
|
|
|
|
elsif homework.max_group_end_time
|
|
|
|
|