|
|
@ -13,6 +13,8 @@ class Subject < ApplicationRecord
|
|
|
|
has_many :stage_shixuns, dependent: :destroy
|
|
|
|
has_many :stage_shixuns, dependent: :destroy
|
|
|
|
has_many :shixuns, through: :stage_shixuns
|
|
|
|
has_many :shixuns, through: :stage_shixuns
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
has_many :subject_appointments, dependent: :destroy
|
|
|
|
|
|
|
|
|
|
|
|
has_many :subject_members, ->{ order("subject_members.position asc")}, dependent: :destroy
|
|
|
|
has_many :subject_members, ->{ order("subject_members.position asc")}, dependent: :destroy
|
|
|
|
has_many :users, through: :subject_members
|
|
|
|
has_many :users, through: :subject_members
|
|
|
|
has_many :tidings, as: :container, dependent: :destroy
|
|
|
|
has_many :tidings, as: :container, dependent: :destroy
|
|
|
@ -44,6 +46,10 @@ class Subject < ApplicationRecord
|
|
|
|
courses.where("start_date <= '#{Date.today}' and end_date >= '#{Date.today}'").count > 0
|
|
|
|
courses.where("start_date <= '#{Date.today}' and end_date >= '#{Date.today}'").count > 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def has_participate?
|
|
|
|
|
|
|
|
subject_appointments.exists?(user_id: User.current.id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 挑战过路径的成员数(金课统计去重后的报名人数)
|
|
|
|
# 挑战过路径的成员数(金课统计去重后的报名人数)
|
|
|
|
def member_count
|
|
|
|
def member_count
|
|
|
|
excellent ? CourseMember.where(role: 4, course_id: courses.pluck(:id)).pluck(:user_id).length : shixuns.pluck(:myshixuns_count).sum
|
|
|
|
excellent ? CourseMember.where(role: 4, course_id: courses.pluck(:id)).pluck(:user_id).length : shixuns.pluck(:myshixuns_count).sum
|
|
|
@ -109,4 +115,10 @@ class Subject < ApplicationRecord
|
|
|
|
def learning? user_id
|
|
|
|
def learning? user_id
|
|
|
|
Myshixun.where(user_id: user_id, shixun_id: shixuns).exists?
|
|
|
|
Myshixun.where(user_id: user_id, shixun_id: shixuns).exists?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def start_course_notify
|
|
|
|
|
|
|
|
Tiding.create(user_id: user_id, trigger_user_id: 0, container_id: id,
|
|
|
|
|
|
|
|
container_type: 'SubjectStartCourse', belong_container_id: id,
|
|
|
|
|
|
|
|
belong_container_type: 'Subject', tiding_type: 'System')
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|