You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/models/student_graduation_topic.rb

60 lines
1.6 KiB

6 years ago
class StudentGraduationTopic < ApplicationRecord
# status 0待确认 1已同意 2已拒绝
belongs_to :user
belongs_to :course
# belongs_to course_member, optional: true
belongs_to :graduation_topic
belongs_to :course_member
has_many :tidings, as: :container, dependent: :destroy
# 毕设确认数
scope :confirmation_count, ->{ where(:status => [1, 2]).count }
#用户的选题
scope :user_topics_accept, lambda{|user_id| where(user_id:user_id,status:[0,1])}
scope :is_refused, -> {where(status: 2)}
scope :is_accepted, -> {where(status: 1)}
scope :is_accepting, -> {where(status: 0)}
6 years ago
after_create :send_tiding
6 years ago
6 years ago
def send_tiding
self.tidings << Tiding.new(:user_id => self.graduation_topic.tea_id, :trigger_user_id => self.user_id, :parent_container_id => self.graduation_topic_id, :parent_container_type => "GraduationTopic",
5 years ago
:belong_container_id => self.graduation_topic.course_id, :belong_container_type => "Course", :viewed => 0, :status => 0, :tiding_type => "Apply")
6 years ago
end
6 years ago
# 学生名称
def name
self.user.real_name
end
# 学生学号
def student_id
self.user.student_id
end
# 学生班级名称
def class_group_name
self.course_member.try(:course_group).try(:name)
end
# 学生选题时间
def selected_time
format_time self.created_at
end
# 学生选题状态名
def status_name
case self.status
when 0
"待确认"
when 1
"已同意"
when 2
"已拒绝"
end
end
end