diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index fa1d06d77..159650c38 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -13,7 +13,7 @@ class CoursesController < ApplicationController before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner] before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt, - :set_public_or_private, :search_teacher_candidate, :teachers, + :set_public_or_private, :search_teacher_candidate, :teachers, :apply_teachers, :top_banner, :left_banner, :add_teacher_popup, :add_teacher, :graduation_group_list, :create_graduation_group, :join_graduation_group, :course_group_list, :set_course_group, :change_course_admin, :change_course_teacher, @@ -26,10 +26,10 @@ class CoursesController < ApplicationController :transfer_to_course_group, :delete_from_course, :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, - :set_course_group, :delete_course_teacher, :teacher_application_review, - :create_group_by_importing_file] + :set_course_group, :delete_course_teacher, :create_group_by_importing_file] 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] before_action :validate_course_name, only: [:create, :update] before_action :find_board, only: :board_list before_action :validate_page_size, only: :mine @@ -251,46 +251,52 @@ class CoursesController < ApplicationController if @course.try(:id) != 1309 || current_user.admin? || current_user.try(:id) == 15582 @teacher_list = @course.course_members.joins(:user).where("course_members.role in (1, 2, 3) - and LOWER(concat(users.lastname, users.firstname)) LIKE '%#{@search_str}%'") + and LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{@search_str}%") else @teacher_list = @course.course_members.joins(:user).where("(course_members.role in (1, 3) or (course_members.user_id = #{current_user.id} and course_members.role = 2)) and LOWER(concat(users.lastname, users.firstname)) - LIKE '%#{@search_str}%'") + LIKE ?", "%#{@search_str}%") end @teacher_list_size = @teacher_list.size @has_graduation_design = @course.course_modules.graduation_module_not_hidden.any? + sort = params[:sort] || "desc" @order = params[:order].to_i if @order.present? case @order when 1 - @teacher_list = @teacher_list.includes(:user).order("CONVERT(CONCAT(users.lastname, users.firstname) USING gbk) COLLATE gbk_chinese_ci asc") + @teacher_list = @teacher_list.order("role #{sort}") when 2 - @teacher_list = @teacher_list.order("created_at") + @teacher_list = @teacher_list.includes(:user).order("CONVERT(CONCAT(users.lastname, users.firstname) USING gbk) COLLATE gbk_chinese_ci #{sort}") when 3 - @teacher_list = @teacher_list.includes(:course, :graduation_group).order("graduation_groups.name") + @teacher_list = @teacher_list.includes(:course, :graduation_group).order("graduation_groups.name #{sort}") else - @teacher_list = @teacher_list.order("created_at") + @teacher_list = @teacher_list.order("role #{sort}") end else - if @has_graduation_design - @teacher_list = @teacher_list.includes(:course, :graduation_group).order("graduation_groups.name") - else - @teacher_list = @teacher_list.order("created_at") - end + @teacher_list = @teacher_list.order("role #{sort}") end @is_admin = @user_course_identity < Course::PROFESSOR - @applications = @is_admin ? CourseMessage.unhandled_join_course_requests_by_course(@course) : CourseMessage.none + @applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size page = params[:page] || 1 limit = params[:limit] || 20 @teacher_list = @teacher_list.page(page).per(limit) end + def apply_teachers + search_str = params[:search].present? ? params[:search].strip : "" + @applications = CourseMessage.unhandled_join_course_requests_by_course(@course).joins(:user). + where("LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{search_str}%") + @teacher_list_size = @course.teachers.size + @applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size + @is_admin = @user_course_identity < Course::PROFESSOR + end + # 打开添加教师或助教弹窗时访问的接口(需要返回该课堂所有答辩组和所有) def add_teacher_popup @graduation_groups = @course.graduation_groups @@ -577,6 +583,18 @@ class CoursesController < ApplicationController end new_teacher.save! + + # 课堂管理员才有分配权限,且课堂分班数大于0 + if @user_course_identity < Course::PROFESSOR && @course.course_groups_count > 0 && params[:group_id] && params[:group_id].size > 0 + # 分班全选则是不限,不需要做处理 + unless @course.course_groups.where(id: params[:group_id]).size == @course.course_groups_count + @course.course_groups.where(id: params[:group_id]).each do |group| + unless TeacherCourseGroup.where(course_id: @course.id, user_id: applier_user.id, course_group_id: group.id, course_member_id: new_teacher.id).exists? + TeacherCourseGroup.create(course_id: @course.id, user_id: applier_user.id, course_member_id: new_teacher.id, course_group_id: group.id) + end + end + end + end elsif approval == 2 course_message.reject! else diff --git a/app/views/courses/apply_teachers.json.jbuilder b/app/views/courses/apply_teachers.json.jbuilder new file mode 100644 index 000000000..aee0803b4 --- /dev/null +++ b/app/views/courses/apply_teachers.json.jbuilder @@ -0,0 +1,13 @@ +json.teacher_list_size @teacher_list_size +json.apply_size @applications_size +json.is_admin @is_admin +json.application_list do + json.array! @applications do |application| + json.application_id application.id + json.user_id application.course_message_id + json.name application.application_user.real_name + json.name_link user_path(application.application_user) + json.login application.application_user.login + json.role application.content.to_i == 3 || application.content.to_i == 7 ? "助教" : application.content.to_i == 2 || application.content.to_i == 9 ? "教师" : "" + end +end \ No newline at end of file diff --git a/app/views/courses/teachers.json.jbuilder b/app/views/courses/teachers.json.jbuilder index 1be1ce16c..6a8505964 100644 --- a/app/views/courses/teachers.json.jbuilder +++ b/app/views/courses/teachers.json.jbuilder @@ -17,14 +17,5 @@ json.teacher_list do end end json.teacher_list_size @teacher_list_size -json.application_list do - json.array! @applications do |application| - json.application_id application.id - json.user_id application.course_message_id - json.name application.application_user.real_name - json.name_link user_path(application.application_user) - json.login application.application_user.login - json.role application.content.to_i == 3 || application.content.to_i == 7 ? "助教" : application.content.to_i == 2 || application.content.to_i == 9 ? "教师" : "" - end -end -json.is_admin @is_admin +json.apply_size @applications_size +json.is_admin @is_admin \ No newline at end of file