加入题库报错

dev_haigong
cxt 6 years ago
parent 904880044c
commit b66140bcfe

@ -1677,7 +1677,8 @@ class StudentWorkController < ApplicationController
def student_work_project
project = Project.where(:id => params[:projectName].to_i).first
if project.present?
@work = @homework.student_works.where("user_id = #{User.current.id} and work_status = 0").first
@work = @homework.student_works.where("user_id = #{User.current.id} and work_status = 0").first ||
StudentWork.create(homework_common_id: @homework.id, user_id: User.current.id)
if @work
@work.update_column('project_id', params[:projectName].to_i)
end

@ -6920,148 +6920,154 @@ def quote_resource_bank resource, course
end
def quote_homework_bank homework, course
new_homework = HomeworkCommon.new(:name => homework.name, :user_id => User.current.id, :description => homework.description, :homework_type => homework.homework_type, :late_penalty => 5,
:course_id => course.id, :teacher_priority => 1, :anonymous_comment => 1, :quotes => 0, :is_open => 0, :homework_bank_id => homework.id, :score_open => 1,
:anonymous_appeal => 0, :is_public => 0, :reference_answer => homework.reference_answer, :answer_public => 1, :allow_late => 1)
new_homework.homework_detail_manual = HomeworkDetailManual.new
new_homework_detail_manual = new_homework.homework_detail_manual
new_homework_detail_manual.te_proportion = 1.0
new_homework_detail_manual.ta_proportion = 0
new_homework_detail_manual.comment_status = 0
new_homework_detail_manual.evaluation_num = 0
new_homework_detail_manual.absence_penalty = 0
if new_homework.homework_type == 2
new_homework.homework_detail_programing = HomeworkDetailPrograming.new
new_homework.homework_detail_programing.ta_proportion = 0
new_homework.homework_detail_programing.language = homework.language
homework.homework_bank_tests.each_with_index do |homework_test|
new_homework.homework_tests << HomeworkTest.new(
input: homework_test.input,
output: homework_test.output
)
ActiveRecord::Base.transaction do
new_homework = HomeworkCommon.new(:name => homework.name, :user_id => User.current.id, :description => homework.description, :homework_type => homework.homework_type, :late_penalty => 5,
:course_id => course.id, :teacher_priority => 1, :anonymous_comment => 1, :quotes => 0, :is_open => 0, :homework_bank_id => homework.id, :score_open => 1,
:anonymous_appeal => 0, :is_public => 0, :reference_answer => homework.reference_answer, :answer_public => 1, :allow_late => 1)
new_homework.homework_detail_manual = HomeworkDetailManual.new
new_homework_detail_manual = new_homework.homework_detail_manual
new_homework_detail_manual.te_proportion = 1.0
new_homework_detail_manual.ta_proportion = 0
new_homework_detail_manual.comment_status = 0
new_homework_detail_manual.evaluation_num = 0
new_homework_detail_manual.absence_penalty = 0
if new_homework.homework_type == 2
new_homework.homework_detail_programing = HomeworkDetailPrograming.new
new_homework.homework_detail_programing.ta_proportion = 0
new_homework.homework_detail_programing.language = homework.language
homework.homework_bank_tests.each_with_index do |homework_test|
new_homework.homework_tests << HomeworkTest.new(
input: homework_test.input,
output: homework_test.output
)
end
homework.homework_bank_samples.each_with_index do |homework_test|
new_homework.homework_samples << HomeworkSample.new(
input: homework_test.input,
output: homework_test.output
)
end
end
homework.homework_bank_samples.each_with_index do |homework_test|
new_homework.homework_samples << HomeworkSample.new(
input: homework_test.input,
output: homework_test.output
)
if new_homework.homework_type == 3
new_homework.homework_detail_group = HomeworkDetailGroup.new
new_homework.homework_detail_group.min_num = homework.min_num
new_homework.homework_detail_group.max_num = homework.max_num
new_homework.homework_detail_group.base_on_project = homework.base_on_project
end
end
if new_homework.homework_type == 3
new_homework.homework_detail_group = HomeworkDetailGroup.new
new_homework.homework_detail_group.min_num = homework.min_num
new_homework.homework_detail_group.max_num = homework.max_num
new_homework.homework_detail_group.base_on_project = homework.base_on_project
end
homework.attachments.each do |attachment|
att = attachment.copy
att.container_id = nil
att.container_type = nil
att.author_id = homework.user_id
att.copy_from = attachment.id
att.save
new_homework.attachments << att
end
homework.attachments.each do |attachment|
att = attachment.copy
att.container_id = nil
att.container_type = nil
att.author_id = homework.user_id
att.copy_from = attachment.id
att.save
new_homework.attachments << att
end
if new_homework.save
if new_homework.homework_type == 4
HomeworkCommonsShixuns.create(:homework_common_id => new_homework.id, :shixun_id => homework.homework_bank_shixun.shixun_id)
end
new_homework_detail_manual.save if new_homework_detail_manual
new_homework.homework_detail_programing.save if new_homework.homework_detail_programing
new_homework.homework_detail_group.save if new_homework.homework_detail_group
create_works_list new_homework
if new_homework.save
if new_homework.homework_type == 4
HomeworkCommonsShixuns.create(:homework_common_id => new_homework.id, :shixun_id => homework.homework_bank_shixun.shixun_id)
homework.update_column(:quotes, homework.quotes+1)
QuestionBank.where(:container_id => homework.id, :container_type => ["Common", "Shixun", "Group"]).update_all(:quotes => homework.quotes)
end
new_homework_detail_manual.save if new_homework_detail_manual
new_homework.homework_detail_programing.save if new_homework.homework_detail_programing
new_homework.homework_detail_group.save if new_homework.homework_detail_group
create_works_list new_homework
homework.update_column(:quotes, homework.quotes+1)
QuestionBank.where(:container_id => homework.id, :container_type => ["Common", "Shixun", "Group"]).update_all(:quotes => homework.quotes)
return new_homework
end
return new_homework
end
def quote_exercise_bank exercise, course
new_exercise = Exercise.new(:exercise_name => exercise.name, :exercise_description => exercise.description, :user_id => User.current.id, :is_public => 0,
:exercise_status => 1, :show_result => 1, :course_id => course.id, :time => -1, :exercise_bank_id => exercise.id)
exercise.exercise_bank_questions.each do |q|
option = {
:question_title => q[:question_title],
:question_type => q[:question_type] || 1,
:question_number => q[:question_number],
:question_score => q[:question_score],
:shixun_id => q[:shixun_id]
}
exercise_question = new_exercise.exercise_questions.new option
if q.question_type != 5
for i in 1..q.exercise_bank_choices.count
choice_option = {
:choice_position => i,
:choice_text => q.exercise_bank_choices[i-1][:choice_text]
}
exercise_question.exercise_choices.new choice_option
end
ActiveRecord::Base.transaction do
new_exercise = Exercise.new(:exercise_name => exercise.name, :exercise_description => exercise.description, :user_id => User.current.id, :is_public => 0,
:exercise_status => 1, :show_result => 1, :course_id => course.id, :time => -1, :exercise_bank_id => exercise.id)
exercise.exercise_bank_questions.each do |q|
option = {
:question_title => q[:question_title],
:question_type => q[:question_type] || 1,
:question_number => q[:question_number],
:question_score => q[:question_score],
:shixun_id => q[:shixun_id]
}
exercise_question = new_exercise.exercise_questions.new option
if q.question_type != 5
for i in 1..q.exercise_bank_choices.count
choice_option = {
:choice_position => i,
:choice_text => q.exercise_bank_choices[i-1][:choice_text]
}
exercise_question.exercise_choices.new choice_option
end
for i in 1..q.exercise_bank_standard_answers.count
standard_answer_option = {
:exercise_choice_id => q.exercise_bank_standard_answers[i-1][:exercise_bank_choice_id],
:answer_text => q.exercise_bank_standard_answers[i-1][:answer_text]
}
exercise_question.exercise_standard_answers.new standard_answer_option
end
else
for i in 1..q.exercise_bank_shixun_challenges.count
challenge_option = {
:position => i,
:challenge_id => q.exercise_bank_shixun_challenges[i-1][:challenge_id],
:shixun_id => q.exercise_bank_shixun_challenges[i-1][:shixun_id],
:question_score => q.exercise_bank_shixun_challenges[i-1][:question_score]
}
exercise_question.exercise_shixun_challenges.new challenge_option
for i in 1..q.exercise_bank_standard_answers.count
standard_answer_option = {
:exercise_choice_id => q.exercise_bank_standard_answers[i-1][:exercise_bank_choice_id],
:answer_text => q.exercise_bank_standard_answers[i-1][:answer_text]
}
exercise_question.exercise_standard_answers.new standard_answer_option
end
else
for i in 1..q.exercise_bank_shixun_challenges.count
challenge_option = {
:position => i,
:challenge_id => q.exercise_bank_shixun_challenges[i-1][:challenge_id],
:shixun_id => q.exercise_bank_shixun_challenges[i-1][:shixun_id],
:question_score => q.exercise_bank_shixun_challenges[i-1][:question_score]
}
exercise_question.exercise_shixun_challenges.new challenge_option
end
end
end
if new_exercise.save
create_exercises_list new_exercise
exercise.update_column(:quotes, exercise.quotes+1)
QuestionBank.where(:container_id => exercise.id, :container_type => "Exercise").update_all(:quotes => exercise.quotes)
end
return new_exercise
end
if new_exercise.save
create_exercises_list new_exercise
exercise.update_column(:quotes, exercise.quotes+1)
QuestionBank.where(:container_id => exercise.id, :container_type => "Exercise").update_all(:quotes => exercise.quotes)
end
return new_exercise
end
def quote_poll_bank poll, course
new_poll = Poll.new(:polls_name => poll.name, :polls_description => poll.description, :user_id => User.current.id, :is_public => 0,
:polls_status => 1, :show_result => 1, :polls_type => 'Course', :course_id => course.id, :exercise_bank_id => poll.id)
poll.exercise_bank_questions.each do |q|
option = {
:question_title => q[:question_title],
:question_type => q[:question_type] || 1,
:is_necessary => q[:is_necessary],
:question_number => q[:question_number],
:max_choices => q[:max_choices],
:min_choices => q[:min_choices]
}
poll_question = new_poll.poll_questions.new option
for i in 1..q.exercise_bank_choices.count
choice_option = {
:answer_position => i,
:answer_text => q.exercise_bank_choices[i-1][:choice_text]
ActiveRecord::Base.transaction do
new_poll = Poll.new(:polls_name => poll.name, :polls_description => poll.description, :user_id => User.current.id, :is_public => 0,
:polls_status => 1, :show_result => 1, :polls_type => 'Course', :course_id => course.id, :exercise_bank_id => poll.id)
poll.exercise_bank_questions.each do |q|
option = {
:question_title => q[:question_title],
:question_type => q[:question_type] || 1,
:is_necessary => q[:is_necessary],
:question_number => q[:question_number],
:max_choices => q[:max_choices],
:min_choices => q[:min_choices]
}
poll_question.poll_answers.new choice_option
poll_question = new_poll.poll_questions.new option
for i in 1..q.exercise_bank_choices.count
choice_option = {
:answer_position => i,
:answer_text => q.exercise_bank_choices[i-1][:choice_text]
}
poll_question.poll_answers.new choice_option
end
end
if new_poll.save
create_polls_list new_poll
poll.update_column(:quotes, poll.quotes+1)
QuestionBank.where(:container_id => poll.id, :container_type => "Poll").update_all(:quotes => poll.quotes)
end
return new_poll
end
if new_poll.save
create_polls_list new_poll
poll.update_column(:quotes, poll.quotes+1)
QuestionBank.where(:container_id => poll.id, :container_type => "Poll").update_all(:quotes => poll.quotes)
end
return new_poll
end
def major_level_option

@ -15,7 +15,7 @@ class HomeworkCommon < ActiveRecord::Base
belongs_to :homework_bank
has_many :homework_group_settings, :dependent => :destroy
has_one :homework_detail_manual, :dependent => :destroy
# has_one :homework_detail_programing, :dependent => :destroy
has_one :homework_detail_programing, :dependent => :destroy
has_one :homework_detail_group, :dependent => :destroy
has_one :homework_commons_shixuns, :dependent => :destroy
has_many :homework_challenge_settings, :dependent => :destroy

@ -113,7 +113,7 @@
<% elsif work.present? && work.try(:work_status) != 0 %>
<%= link_to "查看作品", student_work_path(work), :class => 'white-btn orange-btn fr mr20 mt8', :target => "_blank" %>
<% elsif ((work.present? && work.try(:work_status) == 0) || work.nil?) && setting_time.end_time > Time.now %>
<% if homework_common.homework_type == 3 && homework_common.homework_detail_group.base_on_project == 1 && (work.project_id.nil? || work.project_id == 0 || work.project_id = -1) %>
<% if homework_common.homework_type == 3 && homework_common.homework_detail_group.base_on_project == 1 && (work.try(:project_id).nil? || work.try(:project_id) == 0 || work.try(:project_id) == -1) %>
<%= link_to "关联项目", new_student_work_project_student_work_index_path(:homework => homework_common.id, :user_activity_id=> homework_common.id, :hw_status => 1), :remote => true, :class=> 'white-btn orange-btn fr mr20 mt8', :title=> '请各组长关联作业项目' %>
<% else %>
<%= link_to "提交作品", new_student_work_path(:homework => homework_common.id), :class => 'white-btn orange-btn fr mr20 mt8', :target => "_blank" %>

Loading…
Cancel
Save