|
|
@ -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]
|
|
|
@ -49,30 +50,12 @@ class CoursesController < ApplicationController
|
|
|
|
@user = current_user
|
|
|
|
@user = current_user
|
|
|
|
# 根据分类查询课堂(全部,我的,最新,最热)
|
|
|
|
# 根据分类查询课堂(全部,我的,最新,最热)
|
|
|
|
@order = params[:order].present? ? params[:order] : "all"
|
|
|
|
@order = params[:order].present? ? params[:order] : "all"
|
|
|
|
order_str = @order != "course_members_count" && @order != "created_at" ? "updated_at" : @order
|
|
|
|
if @order == "visits"
|
|
|
|
|
|
|
|
order_str = "courses.id = 1309 DESC, courses.visits DESC"
|
|
|
|
# if @order == "all"
|
|
|
|
@courses = Course.where(is_delete: 0, is_hidden: 0)
|
|
|
|
# @course = Course.where(is_delete: 0, is_hidden: 0).select("select c.name, c.id, s.name, u.login, ifnull(concat(u.lastname,u.firstname),
|
|
|
|
|
|
|
|
# u.login), s.name from courses c, users u, user_extensions ue, schools s where c.is_delete=0 and
|
|
|
|
|
|
|
|
# c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @courses = Course.where(is_delete: 0, is_hidden: 0)
|
|
|
|
|
|
|
|
# .order("courses.id = 1309 desc, courses.created_at desc")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count,
|
|
|
|
|
|
|
|
# courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at)
|
|
|
|
|
|
|
|
# FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a")
|
|
|
|
|
|
|
|
# .order("courses.id = 1309 desc, a desc")
|
|
|
|
|
|
|
|
if @order == "mine"
|
|
|
|
|
|
|
|
tip_exception(401, "..") unless current_user.logged?
|
|
|
|
|
|
|
|
@courses = Course.joins(:course_members)
|
|
|
|
|
|
|
|
.where("is_delete = 0 AND is_hidden = 0 AND course_members.user_id = ?", @user.id).distinct
|
|
|
|
|
|
|
|
elsif @order == "created_at"
|
|
|
|
|
|
|
|
# REDO:Extension
|
|
|
|
|
|
|
|
@courses = Course.where(is_delete: 0, is_hidden: 0, is_end: 0).distinct
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
# REDO:Extension
|
|
|
|
order_str = "courses.id = 1309 DESC, courses.homepage_show DESC, courses.created_at desc"
|
|
|
|
@courses = Course.where(is_delete: 0, is_hidden: 0).distinct
|
|
|
|
@courses = Course.where(is_delete: 0, is_hidden: 0, is_end: 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 根据搜索关键字进一步筛选
|
|
|
|
# 根据搜索关键字进一步筛选
|
|
|
@ -92,7 +75,7 @@ class CoursesController < ApplicationController
|
|
|
|
.where("#{sql}", keyword: "%#{params[:search]}%").distinct
|
|
|
|
.where("#{sql}", keyword: "%#{params[:search]}%").distinct
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@courses_count = @courses.count("courses.id")
|
|
|
|
@courses_count = @courses.count("courses.id")
|
|
|
|
@courses = @courses.order("courses.id = 1309 DESC, courses.#{order_str} DESC")
|
|
|
|
@courses = @courses.order(order_str)
|
|
|
|
|
|
|
|
|
|
|
|
# 分页
|
|
|
|
# 分页
|
|
|
|
page = params[:page] || 1
|
|
|
|
page = params[:page] || 1
|
|
|
@ -135,13 +118,19 @@ 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
|
|
|
|
|
|
|
|
|
|
|
|
@course_list_name = params[:course_list_name].strip
|
|
|
|
if params[:subject_id].blank?
|
|
|
|
@course_list = CourseList.find_by(name: @course_list_name)
|
|
|
|
@course_list_name = params[:course_list_name].strip
|
|
|
|
if @course_list
|
|
|
|
@course_list = CourseList.find_by(name: @course_list_name)
|
|
|
|
@course.course_list_id = @course_list.id
|
|
|
|
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
|
|
|
|
else
|
|
|
|
new_course_list = CourseList.create!(name: @course_list_name, user_id: current_user.id, is_admin: 0)
|
|
|
|
@course.start_date = params[:start_date]
|
|
|
|
@course.course_list_id = new_course_list.id
|
|
|
|
@course.subject_id = params[:subject_id]
|
|
|
|
|
|
|
|
@course.excellent = true
|
|
|
|
end
|
|
|
|
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
|
|
|
@ -151,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
|
|
|
@ -169,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
|
|
|
@ -180,13 +175,18 @@ 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]
|
|
|
|
|
|
|
|
|
|
|
|
@course_list_name = params[:course_list_name].strip
|
|
|
|
if @course.subject
|
|
|
|
@course_list = CourseList.find_by(name: @course_list_name)
|
|
|
|
@course.start_date = params[:start_date]
|
|
|
|
if @course_list
|
|
|
|
|
|
|
|
extra_params[:course_list_id] = @course_list.id
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
new_course_list = CourseList.create(name: @course_list_name, user_id: current_user.id, is_admin: 0)
|
|
|
|
extra_params[:is_public] = params[:is_public].present? ? params[:is_public] : 0
|
|
|
|
extra_params[:course_list_id] = new_course_list.id
|
|
|
|
@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
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@course.update_attributes!(course_params.merge(extra_params))
|
|
|
|
@course.update_attributes!(course_params.merge(extra_params))
|
|
|
@ -201,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}")
|
|
|
@ -234,6 +270,8 @@ class CoursesController < ApplicationController
|
|
|
|
def destroy
|
|
|
|
def destroy
|
|
|
|
if @course.is_delete == 0
|
|
|
|
if @course.is_delete == 0
|
|
|
|
@course.delete!
|
|
|
|
@course.delete!
|
|
|
|
|
|
|
|
Tiding.create!(user_id: @course.tea_id, trigger_user_id: 1, container_id: @course.id,
|
|
|
|
|
|
|
|
container_type: 'Course', tiding_type: 'Delete', extra: @course.name)
|
|
|
|
normal_status(0, "成功")
|
|
|
|
normal_status(0, "成功")
|
|
|
|
else
|
|
|
|
else
|
|
|
|
normal_status(-1, "课堂已删除,无需重复操作")
|
|
|
|
normal_status(-1, "课堂已删除,无需重复操作")
|
|
|
@ -296,7 +334,13 @@ class CoursesController < ApplicationController
|
|
|
|
@applications = CourseMessage.unhandled_join_course_requests_by_course(@course).
|
|
|
|
@applications = CourseMessage.unhandled_join_course_requests_by_course(@course).
|
|
|
|
joins("join users on course_messages.course_message_id=users.id").
|
|
|
|
joins("join users on course_messages.course_message_id=users.id").
|
|
|
|
where("LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{search_str}%")
|
|
|
|
where("LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{search_str}%")
|
|
|
|
@teacher_list_size = @course.teachers.size
|
|
|
|
if @course.try(:id) != 1309 || current_user.admin? || current_user.try(:id) == 15582
|
|
|
|
|
|
|
|
teacher_list = @course.course_members.where("course_members.role in (1, 2, 3)")
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
teacher_list = @course.course_members.where("(course_members.role in (1, 3) or (course_members.user_id = #{current_user.id}
|
|
|
|
|
|
|
|
and course_members.role = 2))")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
@teacher_list_size = teacher_list.size
|
|
|
|
@applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size
|
|
|
|
@applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size
|
|
|
|
@is_admin = @user_course_identity < Course::PROFESSOR
|
|
|
|
@is_admin = @user_course_identity < Course::PROFESSOR
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -909,6 +953,7 @@ class CoursesController < ApplicationController
|
|
|
|
CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id])
|
|
|
|
CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id])
|
|
|
|
StudentJoinCourseNotifyJob.perform_later(current_user.id, course.id)
|
|
|
|
StudentJoinCourseNotifyJob.perform_later(current_user.id, course.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
student_role = 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 创建教师身份
|
|
|
|
# 创建教师身份
|
|
|
@ -921,24 +966,33 @@ class CoursesController < ApplicationController
|
|
|
|
course_message = CourseMessage.new(course_id: course.id, user_id: course.tea_id, status: 0,
|
|
|
|
course_message = CourseMessage.new(course_id: course.id, user_id: course.tea_id, status: 0,
|
|
|
|
course_message_id: current_user.id, course_message_type: "JoinCourseRequest",
|
|
|
|
course_message_id: current_user.id, course_message_type: "JoinCourseRequest",
|
|
|
|
viewed: false)
|
|
|
|
viewed: false)
|
|
|
|
course_message.content = 2 if params[:professor].present? && params[:professor].to_i == 1
|
|
|
|
if params[:professor].present? && params[:professor].to_i == 1
|
|
|
|
course_message.content = 3 if params[:assistant_professor].present? && params[:assistant_professor].to_i == 1
|
|
|
|
course_message.content = 2
|
|
|
|
|
|
|
|
role = 9
|
|
|
|
|
|
|
|
message = "教师申请已提交,请等待审核"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
course_message.content = 3
|
|
|
|
|
|
|
|
role = 7
|
|
|
|
|
|
|
|
message = "助教申请已提交,请等待审核"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
course_message.save!
|
|
|
|
course_message.save!
|
|
|
|
|
|
|
|
|
|
|
|
role = course_message.content == 2 ? '7' : '9' # 7:助教 9:教师
|
|
|
|
# role = course_message.content == 2 ? '9' : '7' # 7:助教 9:教师
|
|
|
|
ApplyTeacherRoleJoinCourseNotifyJob.perform_later(current_user.id, course.id, role)
|
|
|
|
ApplyTeacherRoleJoinCourseNotifyJob.perform_later(current_user.id, course.id, role)
|
|
|
|
message = "#{course_message.content == 2 ? '助教' : '教师'}申请已提交,请等待审核"
|
|
|
|
# message = "#{course_message.content == 2 ? '教师' : '助教'}申请已提交,请等待审核"
|
|
|
|
else
|
|
|
|
else
|
|
|
|
message = "#{existing_course_message.content == 2 ? '助教' : '教师'}申请已提交,请等待审核"
|
|
|
|
message = "#{existing_course_message.content == '2' ? '教师' : '助教'}申请已提交,请等待审核"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
message = "您已是课堂成员"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
teacher_role = 1
|
|
|
|
teacher_role = 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if teacher_role && current_user.student_of_course?(course)
|
|
|
|
if teacher_role && student_role
|
|
|
|
render json: { status: 0, message: message, course_id: course.id}
|
|
|
|
render json: { status: 0, message: message, course_id: course.id}
|
|
|
|
elsif current_user.student_of_course?(course)
|
|
|
|
elsif student_role
|
|
|
|
render json: { status: 0, message: "加入成功", course_id: course.id}
|
|
|
|
render json: { status: 0, message: "加入成功", course_id: course.id}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
normal_status(message)
|
|
|
|
normal_status(message)
|
|
|
@ -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?
|
|
|
|
tip_exception("课程名称不能为空!") if params[:course_list_name].blank?
|
|
|
|
if params[:subject_id].blank? || (@course && @course.subject.blank?)
|
|
|
|
tip_exception("课堂名称应以课程名称开头命名") unless params[:course][:name].index(params[:course_list_name]) &&
|
|
|
|
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
|
|
|
|
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
|
|
|
@ -1154,6 +1225,12 @@ class CoursesController < ApplicationController
|
|
|
|
#课堂的作业信息
|
|
|
|
#课堂的作业信息
|
|
|
|
shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业
|
|
|
|
shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业
|
|
|
|
shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"]
|
|
|
|
shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 更新实训作业成绩
|
|
|
|
|
|
|
|
shixun_homeworks.includes(:homework_challenge_settings, :published_settings, :homework_commons_shixun).each do |homework|
|
|
|
|
|
|
|
|
homework.update_homework_work_score
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
shixun_homeworks = shixun_homeworks&.includes(score_student_works: :user)
|
|
|
|
shixun_homeworks = shixun_homeworks&.includes(score_student_works: :user)
|
|
|
|
|
|
|
|
|
|
|
|
common_homeworks = homeworks.search_homework_type(1) #全部普通作业
|
|
|
|
common_homeworks = homeworks.search_homework_type(1) #全部普通作业
|
|
|
|