From a43a6289e44ecca8c389cf4f195bb0dc6590cf47 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Tue, 19 May 2015 09:49:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=9A=84=E8=80=81=E5=B8=88=E5=B8=83?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E4=BD=9C=E4=B8=9A=E8=A1=A8=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E5=8F=8A=E7=9B=B8=E5=85=B3=E5=85=B3=E7=B3=BB?= =?UTF-8?q?=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 6 +++-- app/models/homework_common.rb | 7 ++++++ app/models/user.rb | 18 ++++---------- .../20150519012744_create_homework_commons.rb | 16 +++++++++++++ db/schema.rb | 24 ++++++++++++------- 5 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 app/models/homework_common.rb create mode 100644 db/migrate/20150519012744_create_homework_commons.rb diff --git a/app/models/course.rb b/app/models/course.rb index 610f52f71..6265a90e1 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -10,7 +10,7 @@ class Course < ActiveRecord::Base #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 - has_many :bid + # has_many :bid has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}" has_many :memberships, :class_name => 'Member' has_many :member_principals, :class_name => 'Member', @@ -18,7 +18,7 @@ class Course < ActiveRecord::Base :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})" has_many :principals, :through => :member_principals, :source => :principal has_many :users, :through => :members - has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy + # has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :homework_for_courses, :dependent => :destroy has_many :student, :class_name => 'StudentsForCourse', :source => :user @@ -29,6 +29,8 @@ class Course < ActiveRecord::Base has_many :news, :dependent => :destroy, :include => :author has_one :course_status, :class_name => "CourseStatus", :dependent => :destroy + has_many :homework_commons, :dependent => :destroy + has_many :course_groups, :dependent => :destroy acts_as_taggable diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb new file mode 100644 index 000000000..326e1fe35 --- /dev/null +++ b/app/models/homework_common.rb @@ -0,0 +1,7 @@ +#老师布置的作业表 +class HomeworkCommon < ActiveRecord::Base + attr_accessible :name, :user_id, :description, :publish_time, :end_time, :homework_type, :late_penalty, :course_id + + belongs_to :course + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb index 7b232bf13..ac8eed0b7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -75,13 +75,15 @@ class User < Principal has_many :homework_users has_many :homework_attaches, :through => :homework_users has_many :homework_evaluations - #问卷相关关关系 has_many :poll_users, :dependent => :destroy has_many :poll_votes, :dependent => :destroy has_many :poll, :dependent => :destroy #用户创建的问卷 has_many :answers, :source => :poll, :through => :poll_users, :dependent => :destroy #用户已经完成问答的问卷 # end + #作业相关关系 + has_many :homework_commons, :dependent => :destroy + #end has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, :after_remove => Proc.new {|user, group| group.user_removed(user)} @@ -92,7 +94,7 @@ class User < Principal belongs_to :auth_source belongs_to :ucourse, :class_name => 'Course', :foreign_key => :id #huang ## added by xianbo for delete - has_many :biding_projects, :dependent => :destroy + # has_many :biding_projects, :dependent => :destroy has_many :contesting_projects, :dependent => :destroy belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy ##ended by xianbo @@ -100,7 +102,7 @@ class User < Principal #####fq has_many :jours, :class_name => 'JournalsForMessage', :dependent => :destroy has_many :journals_messages, :class_name => 'JournalsForMessage', :foreign_key => "user_id", :dependent => :destroy - has_many :bids, :foreign_key => 'author_id', :dependent => :destroy + # has_many :bids, :foreign_key => 'author_id', :dependent => :destroy has_many :contests, :foreign_key => 'author_id', :dependent => :destroy has_many :softapplications, :foreign_key => 'user_id', :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy @@ -257,16 +259,6 @@ class User < Principal end end - # 判断用户是否加入了竞赛中 fq - def join_in_contest?(bid) - joined = JoinInContest.where('user_id = ? and bid_id =?', self.id, bid.id) - if joined.size > 0 - true - else - false - end - end - ### fq def join_in?(course) joined = StudentsForCourse.where('student_id = ? and course_id = ?', self.id, course.id) diff --git a/db/migrate/20150519012744_create_homework_commons.rb b/db/migrate/20150519012744_create_homework_commons.rb new file mode 100644 index 000000000..75c68e49f --- /dev/null +++ b/db/migrate/20150519012744_create_homework_commons.rb @@ -0,0 +1,16 @@ +class CreateHomeworkCommons < ActiveRecord::Migration + def change + create_table :homework_commons do |t| + t.string :name + t.integer :user_id + t.text :description + t.date :publish_time + t.date :end_time + t.integer :homework_type, default: 1 + t.string :late_penalty + t.integer :course_id + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 601963956..6bb0b3900 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150514133640) do +ActiveRecord::Schema.define(:version => 20150519012744) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -541,9 +541,21 @@ ActiveRecord::Schema.define(:version => 20150514133640) do t.integer "is_teacher_score", :default => 0 end - add_index "homework_attaches", ["bid_id"], :name => "bid_id" add_index "homework_attaches", ["bid_id"], :name => "index_homework_attaches_on_bid_id" + create_table "homework_commons", :force => true do |t| + t.string "name" + t.integer "user_id" + t.text "description" + t.date "publish_time" + t.date "end_time" + t.integer "type", :default => 1 + t.string "late_penalty" + t.integer "course_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "homework_evaluations", :force => true do |t| t.string "user_id" t.string "homework_attach_id" @@ -556,9 +568,7 @@ ActiveRecord::Schema.define(:version => 20150514133640) do t.integer "bid_id" end - add_index "homework_for_courses", ["bid_id"], :name => "bid_id" add_index "homework_for_courses", ["bid_id"], :name => "index_homework_for_courses_on_bid_id" - add_index "homework_for_courses", ["course_id"], :name => "course_id" add_index "homework_for_courses", ["course_id"], :name => "index_homework_for_courses_on_course_id" create_table "homework_users", :force => true do |t| @@ -1163,14 +1173,12 @@ ActiveRecord::Schema.define(:version => 20150514133640) do create_table "students_for_courses", :force => true do |t| t.integer "student_id" t.integer "course_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.integer "student_idCopy" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "students_for_courses", ["course_id"], :name => "index_students_for_courses_on_course_id" add_index "students_for_courses", ["student_id"], :name => "index_students_for_courses_on_student_id" - add_index "students_for_courses", ["student_id"], :name => "student_id" create_table "taggings", :force => true do |t| t.integer "tag_id"