From bbf087fa67452482f07bae27d4bf75ab0fcccdc2 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 13 Nov 2015 14:40:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BB=A5=E5=8F=8Amodel=E6=95=B0=E6=8D=AE=E5=85=B3?= =?UTF-8?q?=E7=B3=BB=E7=9A=84=E7=A1=AE=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 7 +++++++ app/models/exercise_answer.rb | 8 ++++++++ app/models/exercise_choices.rb | 7 +++++++ app/models/exercise_question.rb | 8 ++++++++ app/models/exercise_standard_answer.rb | 7 +++++++ app/models/exercise_user.rb | 6 ++++++ app/models/user.rb | 6 ++++++ db/migrate/20151113025341_exercise.rb | 3 +-- db/migrate/20151113025459_exercise_question.rb | 1 + db/migrate/20151113025751_user_exercise.rb | 5 +++-- 10 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 app/models/exercise.rb create mode 100644 app/models/exercise_answer.rb create mode 100644 app/models/exercise_choices.rb create mode 100644 app/models/exercise_question.rb create mode 100644 app/models/exercise_standard_answer.rb create mode 100644 app/models/exercise_user.rb diff --git a/app/models/exercise.rb b/app/models/exercise.rb new file mode 100644 index 000000000..752441947 --- /dev/null +++ b/app/models/exercise.rb @@ -0,0 +1,7 @@ +class Exercise < ActiveRecord::Base + include Redmine::SafeAttributes + belongs_to :user + has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number" + has_many :exercise_users, :dependent => :destroy + has_many :users, :through => :exercise_users #该文件被哪些用户提交答案过 +end diff --git a/app/models/exercise_answer.rb b/app/models/exercise_answer.rb new file mode 100644 index 000000000..14b60982a --- /dev/null +++ b/app/models/exercise_answer.rb @@ -0,0 +1,8 @@ +class ExerciseAnswer < ActiveRecord::Base + #学生答题 + include Redmine::SafeAttributes + + belongs_to :user + belongs_to :exercise_question + belongs_to :exercise_choices +end diff --git a/app/models/exercise_choices.rb b/app/models/exercise_choices.rb new file mode 100644 index 000000000..8e67a8c0a --- /dev/null +++ b/app/models/exercise_choices.rb @@ -0,0 +1,7 @@ +class ExerciseChoices < ActiveRecord::Base + include Redmine::SafeAttributes + + belongs_to :exercise_question + has_many :exercise_answers, :dependent => :destroy + has_many :exercise_standard_answers, :dependent => :destroy +end diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb new file mode 100644 index 000000000..64ec53e4c --- /dev/null +++ b/app/models/exercise_question.rb @@ -0,0 +1,8 @@ +class ExerciseQuestion < ActiveRecord::Base + include Redmine::SafeAttributes + + belongs_to :exercise + has_many :exercise_choiceses, :order => "#{ExerciseChoices.table_name}.choice_position",:dependent => :destroy + has_many :exercise_answers, :dependent => :destroy + has_many :exercise_standard_answers, :dependent => :destroy +end diff --git a/app/models/exercise_standard_answer.rb b/app/models/exercise_standard_answer.rb new file mode 100644 index 000000000..2b67a83a2 --- /dev/null +++ b/app/models/exercise_standard_answer.rb @@ -0,0 +1,7 @@ +class ExerciseStandardAnswer < ActiveRecord::Base + #标准答案 + include Redmine::SafeAttributes + + belongs_to :exercise_question + belongs_to :exercise_choices +end diff --git a/app/models/exercise_user.rb b/app/models/exercise_user.rb new file mode 100644 index 000000000..2d5da5d95 --- /dev/null +++ b/app/models/exercise_user.rb @@ -0,0 +1,6 @@ +class ExerciseUser < ActiveRecord::Base + include Redmine::SafeAttributes + + belongs_to :user + belongs_to :exercise +end diff --git a/app/models/user.rb b/app/models/user.rb index edc29c015..9e470380d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -81,6 +81,12 @@ class User < Principal has_many :poll, :dependent => :destroy #用户创建的问卷 has_many :answers, :source => :poll, :through => :poll_users, :dependent => :destroy #用户已经完成问答的问卷 # end + #在线测验相关关系 + has_many :exercise_users, :dependent => :destroy #答卷中间表 + has_many :exercise_answers, :dependent => :destroy #针对每个题目学生的答案 + has_many :exercises, :dependent => :destroy #创建的试卷 + has_many :exercises_answers, :source => :exercises, :through => :exercise_users, :dependent => :destroy #用户已经完成问答的试卷 + #end #作业相关关系 has_many :homework_commons, :dependent => :destroy has_many :student_works, :dependent => :destroy diff --git a/db/migrate/20151113025341_exercise.rb b/db/migrate/20151113025341_exercise.rb index 8fdcf0a9e..696f8d953 100644 --- a/db/migrate/20151113025341_exercise.rb +++ b/db/migrate/20151113025341_exercise.rb @@ -6,8 +6,7 @@ class Exercise < ActiveRecord::Migration t.integer :course_id t.integer :exercise_status t.integer :user_id - t.datetime :start_at - t.datetime :end_at + t.integer :time t.timestamps end end diff --git a/db/migrate/20151113025459_exercise_question.rb b/db/migrate/20151113025459_exercise_question.rb index 3ab084f13..5e83504c5 100644 --- a/db/migrate/20151113025459_exercise_question.rb +++ b/db/migrate/20151113025459_exercise_question.rb @@ -3,6 +3,7 @@ class ExerciseQuestion < ActiveRecord::Migration create_table :exercise_question do |t| t.string :question_title t.integer :question_type + t.integer :question_number t.integer :exercise_id t.timestamps end diff --git a/db/migrate/20151113025751_user_exercise.rb b/db/migrate/20151113025751_user_exercise.rb index b0a003d1d..a49053146 100644 --- a/db/migrate/20151113025751_user_exercise.rb +++ b/db/migrate/20151113025751_user_exercise.rb @@ -1,14 +1,15 @@ class UserExercise < ActiveRecord::Migration def up - create_table :user_exercise do |t| + create_table :exercise_user do |t| t.integer :user_id t.integer :exercise_id t.integer :score + t.datetime :start_at t.timestamps end end def down - drop_table :user_exercise + drop_table :exercise_user end end