|
|
|
@ -117,13 +117,18 @@ class CoursesController < ApplicationController
|
|
|
|
|
authentication: params[:authentication], professional_certification: params[:professional_certification])
|
|
|
|
|
@course.tea_id = current_user.id
|
|
|
|
|
|
|
|
|
|
@course_list_name = params[:course_list_name].strip
|
|
|
|
|
@course_list = CourseList.find_by(name: @course_list_name)
|
|
|
|
|
if @course_list
|
|
|
|
|
@course.course_list_id = @course_list.id
|
|
|
|
|
if params[:subject_id].blank?
|
|
|
|
|
@course_list_name = params[:course_list_name].strip
|
|
|
|
|
@course_list = CourseList.find_by(name: @course_list_name)
|
|
|
|
|
if @course_list
|
|
|
|
|
@course.course_list_id = @course_list.id
|
|
|
|
|
else
|
|
|
|
|
new_course_list = CourseList.create!(name: @course_list_name, user_id: current_user.id, is_admin: 0)
|
|
|
|
|
@course.course_list_id = new_course_list.id
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
new_course_list = CourseList.create!(name: @course_list_name, user_id: current_user.id, is_admin: 0)
|
|
|
|
|
@course.course_list_id = new_course_list.id
|
|
|
|
|
@course.start_date = params[:start_date]
|
|
|
|
|
@course.subject_id = params[:subject_id]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@course.is_end = @course.end_date.present? && @course.end_date < Date.today
|
|
|
|
@ -151,7 +156,6 @@ class CoursesController < ApplicationController
|
|
|
|
|
begin
|
|
|
|
|
extra_params = Hash.new
|
|
|
|
|
extra_params[:school_id] = @school.id
|
|
|
|
|
extra_params[:is_public] = params[:is_public].present? ? params[:is_public] : 0
|
|
|
|
|
|
|
|
|
|
if @course.is_end && (course_params[:end_date].blank? || course_params[:end_date].to_date > Date.today)
|
|
|
|
|
extra_params[:is_end] = 0
|
|
|
|
@ -162,13 +166,18 @@ class CoursesController < ApplicationController
|
|
|
|
|
extra_params[:authentication] = params[:authentication]
|
|
|
|
|
extra_params[:professional_certification] = params[:professional_certification]
|
|
|
|
|
|
|
|
|
|
@course_list_name = params[:course_list_name].strip
|
|
|
|
|
@course_list = CourseList.find_by(name: @course_list_name)
|
|
|
|
|
if @course_list
|
|
|
|
|
extra_params[:course_list_id] = @course_list.id
|
|
|
|
|
if @course.subject
|
|
|
|
|
@course.start_date = params[:start_date]
|
|
|
|
|
else
|
|
|
|
|
new_course_list = CourseList.create(name: @course_list_name, user_id: current_user.id, is_admin: 0)
|
|
|
|
|
extra_params[:course_list_id] = new_course_list.id
|
|
|
|
|
extra_params[:is_public] = params[:is_public].present? ? params[:is_public] : 0
|
|
|
|
|
@course_list_name = params[:course_list_name].strip
|
|
|
|
|
@course_list = CourseList.find_by(name: @course_list_name)
|
|
|
|
|
if @course_list
|
|
|
|
|
extra_params[:course_list_id] = @course_list.id
|
|
|
|
|
else
|
|
|
|
|
new_course_list = CourseList.create(name: @course_list_name, user_id: current_user.id, is_admin: 0)
|
|
|
|
|
extra_params[:course_list_id] = new_course_list.id
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@course.update_attributes!(course_params.merge(extra_params))
|
|
|
|
@ -1075,9 +1084,18 @@ class CoursesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
def validate_course_name
|
|
|
|
|
tip_exception("课堂名称不能为空!") if params[:course][:name].blank?
|
|
|
|
|
tip_exception("课程名称不能为空!") if params[:course_list_name].blank?
|
|
|
|
|
tip_exception("课堂名称应以课程名称开头命名") unless params[:course][:name].index(params[:course_list_name]) &&
|
|
|
|
|
if params[:subject_id].blank?
|
|
|
|
|
tip_exception("课程名称不能为空!") if params[:course_list_name].blank?
|
|
|
|
|
tip_exception("课堂名称应以课程名称开头命名") unless params[:course][:name].index(params[:course_list_name]) &&
|
|
|
|
|
params[:course][:name].index(params[:course_list_name]) == 0
|
|
|
|
|
else
|
|
|
|
|
@subject = Subject.find_by!(id: params[:subject_id])
|
|
|
|
|
tip_exception("开始时间不能为空") if params[:start_date].blank?
|
|
|
|
|
tip_exception("结束时间不能为空") if params[:end_date].blank?
|
|
|
|
|
tip_exception("结束时间必须晚于开始时间") if params[:end_date] <= params[:start_date]
|
|
|
|
|
tip_exception("开始时间和结束时间不能与往期开课时间重叠") if @subject.max_course_end_date && params[:start_date] <= strf_date(@subject.max_course_end_date)
|
|
|
|
|
tip_exception("开放课堂必须包含公告栏和在线学习模块") unless params[:course_module_types].include?("announcement") && params[:course_module_types].include?("online_learning")
|
|
|
|
|
end
|
|
|
|
|
tip_exception("课堂所属单位不能为空!") if params[:school].blank?
|
|
|
|
|
tip_exception("请至少添加一个课堂模块") if params[:course_module_types].blank?
|
|
|
|
|
@school = School.find_by!(name: params[:school].strip)
|
|
|
|
|