|
|
|
@ -12,10 +12,10 @@ class CoursesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups,
|
|
|
|
|
:left_banner, :top_banner, :informs, :online_learning]
|
|
|
|
|
:left_banner, :top_banner, :informs, :online_learning, :course_groups]
|
|
|
|
|
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,
|
|
|
|
|
:left_banner, :top_banner, :apply_to_join_course, :exit_course]
|
|
|
|
|
:left_banner, :top_banner, :apply_to_join_course, :exit_course, :course_groups]
|
|
|
|
|
before_action :set_course, only: [:show, :update, :destroy, :settings, :set_invite_code_halt,
|
|
|
|
|
:set_public_or_private, :search_teacher_candidate, :teachers, :apply_teachers,
|
|
|
|
|
:top_banner, :left_banner, :add_teacher_popup, :add_teacher,
|
|
|
|
@ -27,7 +27,8 @@ class CoursesController < ApplicationController
|
|
|
|
|
:attahcment_category_list,:export_member_scores_excel, :duplicate_course,
|
|
|
|
|
:switch_to_teacher, :switch_to_assistant, :switch_to_student, :exit_course,
|
|
|
|
|
:informs, :update_informs, :online_learning, :update_task_position, :tasks_list,
|
|
|
|
|
:join_excellent_course, :export_couser_info, :export_member_act_score, :new_informs, :delete_informs]
|
|
|
|
|
:join_excellent_course, :export_couser_info, :export_member_act_score, :new_informs,
|
|
|
|
|
:delete_informs, :change_member_role, :course_groups, :join_course_group]
|
|
|
|
|
before_action :user_course_identity, except: [:join_excellent_course, :index, :create, :new, :apply_to_join_course,
|
|
|
|
|
:search_course_list, :get_historical_course_students, :mine, :search_slim, :board_list]
|
|
|
|
|
before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate,
|
|
|
|
@ -39,7 +40,7 @@ class CoursesController < ApplicationController
|
|
|
|
|
:set_course_group, :create_group_by_importing_file,
|
|
|
|
|
:update_task_position, :tasks_list]
|
|
|
|
|
before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group,
|
|
|
|
|
:change_course_teacher, :course_group_list,
|
|
|
|
|
:change_course_teacher, :course_group_list, :change_member_role,
|
|
|
|
|
:teacher_application_review, :apply_teachers, :delete_course_teacher]
|
|
|
|
|
before_action :validate_course_name, only: [:create, :update]
|
|
|
|
|
before_action :find_board, only: :board_list
|
|
|
|
@ -340,8 +341,8 @@ class CoursesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
@has_graduation_design = @course.course_modules.graduation_module_not_hidden.any?
|
|
|
|
|
|
|
|
|
|
sort = params[:sort] || "desc"
|
|
|
|
|
@order = params[:order].to_i
|
|
|
|
|
sort = params[:sort] || "asc"
|
|
|
|
|
@order = params[:order] ? params[:order].to_i : 1
|
|
|
|
|
if @order.present?
|
|
|
|
|
case @order
|
|
|
|
|
when 1
|
|
|
|
@ -547,6 +548,61 @@ class CoursesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 修改角色
|
|
|
|
|
def change_member_role
|
|
|
|
|
tip_exception("请至少选择一个角色") if params[:roles].blank?
|
|
|
|
|
tip_exception("不能具有老师、助教两种角色") if params[:roles].include?("PROFESSOR") && params[:roles].include?("ASSISTANT_PROFESSOR")
|
|
|
|
|
tip_exception("管理员不能切换为助教或老师") if params[:user_id].to_i == @course.tea_id &&
|
|
|
|
|
(params[:roles].include?("PROFESSOR") || params[:roles].include?("ASSISTANT_PROFESSOR"))
|
|
|
|
|
|
|
|
|
|
course_members = @course.course_members.where(user_id: params[:user_id])
|
|
|
|
|
tip_exception("非课堂成员不能修改角色") if course_members.blank?
|
|
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
# 第一次修改为教师或助教身份时直接创建数据
|
|
|
|
|
if params[:roles].include?("CREATOR")
|
|
|
|
|
teacher_member = course_members.where(role: %i[CREATOR]).take
|
|
|
|
|
elsif (params[:roles].include?("PROFESSOR") || params[:roles].include?("ASSISTANT_PROFESSOR")) && !course_members.exists?(role: %i[PROFESSOR ASSISTANT_PROFESSOR])
|
|
|
|
|
teacher_member = CourseMember.create!(course_id: @course.id, user_id: params[:user_id], role: params[:roles].include?("PROFESSOR") ? 2 : 3)
|
|
|
|
|
elsif course_members.exists?(role: %i[PROFESSOR ASSISTANT_PROFESSOR])
|
|
|
|
|
teacher_member = course_members.where(role: %i[PROFESSOR ASSISTANT_PROFESSOR]).take
|
|
|
|
|
if params[:roles].include?("PROFESSOR") || params[:roles].include?("ASSISTANT_PROFESSOR")
|
|
|
|
|
# 如果之前有老师身份且老师身份要调整时,只需要修改role字段
|
|
|
|
|
if !params[:roles].include?(teacher_member.role) && params[:roles].include?("PROFESSOR")
|
|
|
|
|
teacher_member.PROFESSOR!
|
|
|
|
|
elsif !params[:roles].include?(teacher_member.role) && params[:roles].include?("ASSISTANT_PROFESSOR")
|
|
|
|
|
teacher_member.ASSISTANT_PROFESSOR!
|
|
|
|
|
end
|
|
|
|
|
teacher_member.save!
|
|
|
|
|
else
|
|
|
|
|
# 不含教师的参数时删除记录
|
|
|
|
|
teacher_member.destroy!
|
|
|
|
|
# CourseDeleteStudentNotifyJob.perform_later(@course.id, [teacher_member.user_id], current_user.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 学生身份的处理
|
|
|
|
|
student_member = course_members.where(role: %i[STUDENT]).take
|
|
|
|
|
if params[:roles].include?("STUDENT") && student_member.blank?
|
|
|
|
|
correspond_teacher_exist = CourseMember.exists?(user_id: params[:user_id], is_active: 1, course_id: @course.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR])
|
|
|
|
|
new_student = CourseMember.new(user_id: params[:user_id], course_id: @course.id, role: 4)
|
|
|
|
|
new_student.is_active = 0 if correspond_teacher_exist
|
|
|
|
|
new_student.save!
|
|
|
|
|
|
|
|
|
|
CourseAddStudentCreateWorksJob.perform_later(@course.id, [params[:user_id]])
|
|
|
|
|
# StudentJoinCourseNotifyJob.perform_later(current_user.id, course.id)
|
|
|
|
|
elsif !params[:roles].include?("STUDENT") && student_member.present?
|
|
|
|
|
# 删除学生身份时激活老师身份
|
|
|
|
|
teacher_member.update_attributes!(is_active: 1) if student_member.is_active && teacher_member.present?
|
|
|
|
|
student_member.destroy!
|
|
|
|
|
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [params[:user_id]])
|
|
|
|
|
# CourseDeleteStudentNotifyJob.perform_later(@course.id, [params[:user_id]], current_user.id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
normal_status(0, "修改成功")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 教师和助教角色转换的接口
|
|
|
|
|
def change_course_teacher
|
|
|
|
|
begin
|
|
|
|
@ -715,8 +771,8 @@ class CoursesController < ApplicationController
|
|
|
|
|
# 学生列表(包括各个子分班的学生列表)及搜索
|
|
|
|
|
def students
|
|
|
|
|
search = params[:search].present? ? params[:search].strip : nil
|
|
|
|
|
order = params[:order].present? ? params[:order].to_i : 0
|
|
|
|
|
sort = params[:sort].present? ? params[:sort] : "desc"
|
|
|
|
|
order = params[:order].present? ? params[:order].to_i : 1
|
|
|
|
|
sort = params[:sort].present? ? params[:sort] : "asc"
|
|
|
|
|
course_group_id = params[:course_group_id].present? ? params[:course_group_id].to_i : nil
|
|
|
|
|
|
|
|
|
|
@students = CourseMember.students(@course)
|
|
|
|
@ -766,6 +822,26 @@ class CoursesController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 分班列表
|
|
|
|
|
def course_groups
|
|
|
|
|
@course_groups = @course.course_groups
|
|
|
|
|
@course_groups = @course_groups.where("name like ?", "%#{params[:search]}%") unless params[:search].blank?
|
|
|
|
|
@all_group_count = @course_groups.size
|
|
|
|
|
@teachers = @course.teachers.includes(:user, :teacher_course_groups) if @user_course_identity < Course::NORMAL
|
|
|
|
|
@current_group_id = @course.students.where(user_id: current_user.id).take&.course_group_id if @user_course_identity == Course::STUDENT
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 学生自动加入分班
|
|
|
|
|
def join_course_group
|
|
|
|
|
tip_exception("学生才能加入分班") if @user_course_identity != Course::STUDENT
|
|
|
|
|
course_group = CourseGroup.find_by!(id: params[:course_group_id], course_id: @course.id)
|
|
|
|
|
member = CourseMember.find_by!(user_id: current_user.id, course_id: @course.id, role: 4)
|
|
|
|
|
if course_group && member
|
|
|
|
|
member.update_attributes!(course_group_id: course_group.id)
|
|
|
|
|
normal_status(0, "加入成功")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 将学生批量移动到某个分班
|
|
|
|
|
def transfer_to_course_group
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|