diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 066771570..ddb0f3ce1 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -91,29 +91,43 @@ class QuestionBanksController < ApplicationController banks = @object_type.classify.constantize.where(id: params[:object_id]) course = current_user.manage_courses.find_by!(id: params[:course_id]) task_ids = [] + homework_type = "" + container_type = "" banks.each do |bank| case @object_type when 'HomeworkBank' # 作业 task = quote_homework_bank bank, course - category_id = course.course_modules.find_by(module_type: task.homework_type == "normal" ? "common_homework" : "group_homework")&.id + homework_type = task.homework_type when 'ExerciseBank' - if bank.container_type == 'Exercise' # 试卷 + container_type = bank.container_type + if container_type == 'Exercise' # 试卷 task = quote_exercise_bank bank, course - category_id = course.course_modules.find_by(module_type: "exercise")&.id else # 问卷 task = quote_poll_bank bank, course - category_id = course.course_modules.find_by(module_type: "poll")&.id end when 'GtaskBank' task = quote_gtask_bank bank, course - category_id = course.course_modules.find_by(module_type: "graduation")&.id when 'GtopicBank' task = quote_gtopic_bank bank, course - category_id = course.course_modules.find_by(module_type: "graduation")&.id end task_ids << task.id if task end + case @object_type + when 'HomeworkBank' # 作业 + category_id = course.course_modules.find_by(module_type: homework_type == "normal" ? "common_homework" : "group_homework")&.id + when 'ExerciseBank' + if container_type == 'Exercise' # 试卷 + category_id = course.course_modules.find_by(module_type: "exercise")&.id + else # 问卷 + category_id = course.course_modules.find_by(module_type: "poll")&.id + end + when 'GtaskBank' + category_id = course.course_modules.find_by(module_type: "graduation")&.id + when 'GtopicBank' + category_id = course.course_modules.find_by(module_type: "graduation")&.id + end + render :json => {task_ids: task_ids, category_id: category_id, status: 0, message: "发送成功"} end