|
|
@ -1,6 +1,7 @@
|
|
|
|
class QuestionBanksController < ApplicationController
|
|
|
|
class QuestionBanksController < ApplicationController
|
|
|
|
before_action :require_login, :check_auth
|
|
|
|
before_action :require_login, :check_auth
|
|
|
|
before_action :params_filter, except: [:my_courses]
|
|
|
|
before_action :params_filter, except: [:my_courses]
|
|
|
|
|
|
|
|
before_action :teacher_or_admin, except: [:bank_list]
|
|
|
|
|
|
|
|
|
|
|
|
# 题库选用列表
|
|
|
|
# 题库选用列表
|
|
|
|
# object_type: # normal 普通作业题库; group 分组作业题库; poll问卷题库; exercise试卷题库; gtask 毕设选题题库;gtopic 毕设任务
|
|
|
|
# object_type: # normal 普通作业题库; group 分组作业题库; poll问卷题库; exercise试卷题库; gtask 毕设选题题库;gtopic 毕设任务
|
|
|
@ -81,24 +82,29 @@ class QuestionBanksController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
def my_courses
|
|
|
|
def my_courses
|
|
|
|
@courses = current_user.manage_courses.where(is_delete: 0, is_end: 0)
|
|
|
|
@courses = current_user.manage_courses.where(is_delete: 0, is_end: 0)
|
|
|
|
|
|
|
|
unless params[:search].blank?
|
|
|
|
|
|
|
|
@courses = @courses.where("name like ?", "%#{params[:search].strip}%")
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def send_to_course
|
|
|
|
def send_to_course
|
|
|
|
bank = current_bank
|
|
|
|
banks = object_banks
|
|
|
|
course = current_user.manage_courses.find_by(id: params[:course_id])
|
|
|
|
course = current_user.manage_courses.find_by!(id: params[:course_id])
|
|
|
|
case @object_type
|
|
|
|
banks.each do |bank|
|
|
|
|
when 'HomeworkBank' # 作业
|
|
|
|
case @object_type
|
|
|
|
quote_homework_bank bank, course
|
|
|
|
when 'HomeworkBank' # 作业
|
|
|
|
when 'ExerciseBank'
|
|
|
|
quote_homework_bank bank, course
|
|
|
|
if bank.container_type == 'Exercise' # 试卷
|
|
|
|
when 'ExerciseBank'
|
|
|
|
quote_exercise_bank bank, course
|
|
|
|
if bank.container_type == 'Exercise' # 试卷
|
|
|
|
else # 问卷
|
|
|
|
quote_exercise_bank bank, course
|
|
|
|
quote_poll_bank bank, course
|
|
|
|
else # 问卷
|
|
|
|
|
|
|
|
quote_poll_bank bank, course
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
when 'GtaskBank'
|
|
|
|
|
|
|
|
quote_gtask_bank bank, course
|
|
|
|
|
|
|
|
when 'GtopicBank'
|
|
|
|
|
|
|
|
quote_gtopic_bank bank, course
|
|
|
|
end
|
|
|
|
end
|
|
|
|
when 'GtaskBank'
|
|
|
|
|
|
|
|
quote_gtask_bank bank, course
|
|
|
|
|
|
|
|
when 'GtopicBank'
|
|
|
|
|
|
|
|
quote_gtopic_bank bank, course
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
normal_status("发送成功")
|
|
|
|
normal_status("发送成功")
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -106,7 +112,7 @@ class QuestionBanksController < ApplicationController
|
|
|
|
def destroy
|
|
|
|
def destroy
|
|
|
|
bank = current_bank
|
|
|
|
bank = current_bank
|
|
|
|
|
|
|
|
|
|
|
|
unless user.admin? || bank.user_id == user.id
|
|
|
|
unless current_user.admin? || bank.user_id == current_user.id
|
|
|
|
render_forbidden
|
|
|
|
render_forbidden
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -121,11 +127,32 @@ class QuestionBanksController < ApplicationController
|
|
|
|
render_ok
|
|
|
|
render_ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def multi_delete
|
|
|
|
|
|
|
|
@objects = object_banks
|
|
|
|
|
|
|
|
@objects.destroy_all
|
|
|
|
|
|
|
|
normal_status("删除成功")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def multi_public
|
|
|
|
|
|
|
|
@objects = object_banks
|
|
|
|
|
|
|
|
@objects.update_all(is_public: true)
|
|
|
|
|
|
|
|
normal_status("更新成功")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def object_banks
|
|
|
|
|
|
|
|
banks ||= @object_type.classify.constantize.where(@object_filter).where(id: params[:object_id])
|
|
|
|
|
|
|
|
unless current_user.admin?
|
|
|
|
|
|
|
|
banks = banks.where(user_id: current_user.id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
banks
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def current_bank
|
|
|
|
def current_bank
|
|
|
|
@_current_bank ||= @object_type.classify.constantize.where(@object_filter).find(params[:id])
|
|
|
|
@_current_bank ||= @object_type.classify.constantize.where(@object_filter).find(params[:id])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def params_filter
|
|
|
|
def params_filter
|
|
|
|
type = ["normal", "group", "poll", "exercise", "gtask", "gtopic"]
|
|
|
|
type = ["normal", "group", "poll", "exercise", "gtask", "gtopic"]
|
|
|
|
tip_exception("object_type类型不正确") unless type.include?(params[:object_type])
|
|
|
|
tip_exception("object_type类型不正确") unless type.include?(params[:object_type])
|
|
|
@ -152,6 +179,10 @@ class QuestionBanksController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def teacher_or_admin
|
|
|
|
|
|
|
|
tip_exception(403, "无权限操作") unless current_user.is_certification_teacher || current_user.admin?
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def quote_homework_bank homework, course
|
|
|
|
def quote_homework_bank homework, course
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
# 复制作业的基本信息
|
|
|
|
# 复制作业的基本信息
|
|
|
|