|
|
@ -13,7 +13,7 @@ class CoursesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups,
|
|
|
|
before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups,
|
|
|
|
:left_banner, :top_banner]
|
|
|
|
:left_banner, :top_banner]
|
|
|
|
before_action :check_account, only: [:new, :create, :apply_to_join_course]
|
|
|
|
before_action :check_account, only: [:new, :create, :apply_to_join_course, :join_excellent_course]
|
|
|
|
before_action :check_auth, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups,
|
|
|
|
before_action :check_auth, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups,
|
|
|
|
:left_banner, :top_banner, :apply_to_join_course, :exit_course]
|
|
|
|
:left_banner, :top_banner, :apply_to_join_course, :exit_course]
|
|
|
|
before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt,
|
|
|
|
before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt,
|
|
|
@ -25,12 +25,13 @@ class CoursesController < ApplicationController
|
|
|
|
:transfer_to_course_group, :delete_from_course, :search_users, :add_students_by_search,
|
|
|
|
:transfer_to_course_group, :delete_from_course, :search_users, :add_students_by_search,
|
|
|
|
:base_info, :get_historical_courses, :create_group_by_importing_file,
|
|
|
|
:base_info, :get_historical_courses, :create_group_by_importing_file,
|
|
|
|
:attahcment_category_list,:export_member_scores_excel, :duplicate_course,
|
|
|
|
:attahcment_category_list,:export_member_scores_excel, :duplicate_course,
|
|
|
|
:switch_to_teacher, :switch_to_assistant, :switch_to_student, :exit_course]
|
|
|
|
:switch_to_teacher, :switch_to_assistant, :switch_to_student, :exit_course,
|
|
|
|
|
|
|
|
:informs, :update_informs, :join_excellent_course, :online_learning]
|
|
|
|
before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate,
|
|
|
|
before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate,
|
|
|
|
:transfer_to_course_group, :delete_from_course,
|
|
|
|
:transfer_to_course_group, :delete_from_course,
|
|
|
|
:search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher]
|
|
|
|
:search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher]
|
|
|
|
before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin,
|
|
|
|
before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin,
|
|
|
|
:set_course_group, :create_group_by_importing_file]
|
|
|
|
:set_course_group, :create_group_by_importing_file, :update_informs]
|
|
|
|
before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group,
|
|
|
|
before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group,
|
|
|
|
:change_course_teacher, :export_member_scores_excel, :course_group_list,
|
|
|
|
:change_course_teacher, :export_member_scores_excel, :course_group_list,
|
|
|
|
:teacher_application_review, :apply_teachers, :delete_course_teacher]
|
|
|
|
:teacher_application_review, :apply_teachers, :delete_course_teacher]
|
|
|
@ -117,6 +118,7 @@ class CoursesController < ApplicationController
|
|
|
|
authentication: params[:authentication], professional_certification: params[:professional_certification])
|
|
|
|
authentication: params[:authentication], professional_certification: params[:professional_certification])
|
|
|
|
@course.tea_id = current_user.id
|
|
|
|
@course.tea_id = current_user.id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if params[:subject_id].blank?
|
|
|
|
@course_list_name = params[:course_list_name].strip
|
|
|
|
@course_list_name = params[:course_list_name].strip
|
|
|
|
@course_list = CourseList.find_by(name: @course_list_name)
|
|
|
|
@course_list = CourseList.find_by(name: @course_list_name)
|
|
|
|
if @course_list
|
|
|
|
if @course_list
|
|
|
@ -125,6 +127,11 @@ class CoursesController < ApplicationController
|
|
|
|
new_course_list = CourseList.create!(name: @course_list_name, user_id: current_user.id, is_admin: 0)
|
|
|
|
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.course_list_id = new_course_list.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
@course.start_date = params[:start_date]
|
|
|
|
|
|
|
|
@course.subject_id = params[:subject_id]
|
|
|
|
|
|
|
|
@course.excellent = true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@course.is_end = @course.end_date.present? && @course.end_date < Date.today
|
|
|
|
@course.is_end = @course.end_date.present? && @course.end_date < Date.today
|
|
|
|
|
|
|
|
|
|
|
@ -133,6 +140,13 @@ class CoursesController < ApplicationController
|
|
|
|
CourseInfo.create!(user_id: current_user.id, course_id: @course.id)
|
|
|
|
CourseInfo.create!(user_id: current_user.id, course_id: @course.id)
|
|
|
|
CourseMember.create!(course_id: @course.id, user_id: current_user.id, role: 1)
|
|
|
|
CourseMember.create!(course_id: @course.id, user_id: current_user.id, role: 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 将实践课程的教学团队成员以教师身份加入课堂
|
|
|
|
|
|
|
|
if @course.subject
|
|
|
|
|
|
|
|
@course.subject.subject_members.where.not(user_id: current_user.id).each do |s_member|
|
|
|
|
|
|
|
|
CourseMember.create!(course_id: @course.id, user_id: s_member.user_id, role: 2)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
course_module_types = params[:course_module_types]
|
|
|
|
course_module_types = params[:course_module_types]
|
|
|
|
@course.create_course_modules(course_module_types)
|
|
|
|
@course.create_course_modules(course_module_types)
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -151,7 +165,6 @@ class CoursesController < ApplicationController
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
extra_params = Hash.new
|
|
|
|
extra_params = Hash.new
|
|
|
|
extra_params[:school_id] = @school.id
|
|
|
|
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)
|
|
|
|
if @course.is_end && (course_params[:end_date].blank? || course_params[:end_date].to_date > Date.today)
|
|
|
|
extra_params[:is_end] = 0
|
|
|
|
extra_params[:is_end] = 0
|
|
|
@ -162,6 +175,10 @@ class CoursesController < ApplicationController
|
|
|
|
extra_params[:authentication] = params[:authentication]
|
|
|
|
extra_params[:authentication] = params[:authentication]
|
|
|
|
extra_params[:professional_certification] = params[:professional_certification]
|
|
|
|
extra_params[:professional_certification] = params[:professional_certification]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if @course.subject
|
|
|
|
|
|
|
|
@course.start_date = params[:start_date]
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
extra_params[:is_public] = params[:is_public].present? ? params[:is_public] : 0
|
|
|
|
@course_list_name = params[:course_list_name].strip
|
|
|
|
@course_list_name = params[:course_list_name].strip
|
|
|
|
@course_list = CourseList.find_by(name: @course_list_name)
|
|
|
|
@course_list = CourseList.find_by(name: @course_list_name)
|
|
|
|
if @course_list
|
|
|
|
if @course_list
|
|
|
@ -170,6 +187,7 @@ class CoursesController < ApplicationController
|
|
|
|
new_course_list = CourseList.create(name: @course_list_name, user_id: current_user.id, is_admin: 0)
|
|
|
|
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[:course_list_id] = new_course_list.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@course.update_attributes!(course_params.merge(extra_params))
|
|
|
|
@course.update_attributes!(course_params.merge(extra_params))
|
|
|
|
@course.update_course_modules(params[:course_module_types])
|
|
|
|
@course.update_course_modules(params[:course_module_types])
|
|
|
@ -183,6 +201,42 @@ class CoursesController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def join_excellent_course
|
|
|
|
|
|
|
|
tip_exception("您已是课堂成员") if current_user.member_of_course?(@course)
|
|
|
|
|
|
|
|
tip_exception("请通过邀请码加入课堂") unless @course.excellent
|
|
|
|
|
|
|
|
tip_exception("该课堂已结束") if @course.is_end
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
new_student = CourseMember.new(user_id: current_user.id, course_id: @course.id, role: 4)
|
|
|
|
|
|
|
|
new_student.save!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CourseAddStudentCreateWorksJob.perform_later(@course.id, [current_user.id])
|
|
|
|
|
|
|
|
StudentJoinCourseNotifyJob.perform_later(current_user.id, @course.id)
|
|
|
|
|
|
|
|
normal_status(0, "加入成功")
|
|
|
|
|
|
|
|
rescue => e
|
|
|
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|
|
|
|
tip_exception(e.message)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def informs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_informs
|
|
|
|
|
|
|
|
tip_exception("公告内容不能为空") if params[:description].blank?
|
|
|
|
|
|
|
|
inform = @course.inform || Inform.new(container: @course)
|
|
|
|
|
|
|
|
inform.description = params[:description]
|
|
|
|
|
|
|
|
inform.save!
|
|
|
|
|
|
|
|
normal_status("更新成功")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def online_learning
|
|
|
|
|
|
|
|
@subject = @course.subject
|
|
|
|
|
|
|
|
@stages = @subject&.stages
|
|
|
|
|
|
|
|
@user = current_user
|
|
|
|
|
|
|
|
@start_learning = @user_course_identity == Course::STUDENT && @subject&.learning?(current_user.id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def search_course_list
|
|
|
|
def search_course_list
|
|
|
|
search = params[:search] ? "%#{params[:search].strip}%" : "%%"
|
|
|
|
search = params[:search] ? "%#{params[:search].strip}%" : "%%"
|
|
|
|
@course_lists = CourseList.where("name like ?", "#{search}")
|
|
|
|
@course_lists = CourseList.where("name like ?", "#{search}")
|
|
|
@ -1075,14 +1129,31 @@ class CoursesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
def validate_course_name
|
|
|
|
def validate_course_name
|
|
|
|
tip_exception("课堂名称不能为空!") if params[:course][:name].blank?
|
|
|
|
tip_exception("课堂名称不能为空!") if params[:course][:name].blank?
|
|
|
|
|
|
|
|
if params[:subject_id].blank? || (@course && @course.subject.blank?)
|
|
|
|
tip_exception("课程名称不能为空!") if params[:course_list_name].blank?
|
|
|
|
tip_exception("课程名称不能为空!") if params[:course_list_name].blank?
|
|
|
|
tip_exception("课堂名称应以课程名称开头命名") unless params[:course][:name].index(params[:course_list_name]) &&
|
|
|
|
tip_exception("课堂名称应以课程名称开头命名") unless params[:course][:name].index(params[:course_list_name]) &&
|
|
|
|
params[:course][:name].index(params[:course_list_name]) == 0
|
|
|
|
params[:course][:name].index(params[:course_list_name]) == 0
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
@subject = @course.present? ? @course.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 @course.nil? && @subject.max_course_end_date && params[:start_date] <= strf_date(@subject.max_course_end_date)
|
|
|
|
|
|
|
|
validate_start_end_date if @course.present?
|
|
|
|
|
|
|
|
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[:school].blank?
|
|
|
|
tip_exception("请至少添加一个课堂模块") if params[:course_module_types].blank?
|
|
|
|
tip_exception("请至少添加一个课堂模块") if params[:course_module_types].blank?
|
|
|
|
@school = School.find_by!(name: params[:school].strip)
|
|
|
|
@school = School.find_by!(name: params[:school].strip)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_start_end_date
|
|
|
|
|
|
|
|
prev_course = @subject.courses.where("id < #{@course.id}").last
|
|
|
|
|
|
|
|
next_course = @subject.courses.where("id > #{@course.id}").first
|
|
|
|
|
|
|
|
tip_exception("开始时间和结束时间不能与其他期开课时间重叠") if prev_course && params[:start_date] <= strf_date(prev_course.end_date)
|
|
|
|
|
|
|
|
tip_exception("开始时间和结束时间不能与其他期开课时间重叠") if next_course && params[:end_date] >= strf_date(next_course.start_date)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 超级管理员和课堂管理员的权限判断
|
|
|
|
# 超级管理员和课堂管理员的权限判断
|
|
|
|
def admin_allowed
|
|
|
|
def admin_allowed
|
|
|
|
unless @user_course_identity < Course::PROFESSOR
|
|
|
|
unless @user_course_identity < Course::PROFESSOR
|
|
|
|