|
|
|
@ -177,7 +177,7 @@ class Course < ActiveRecord::Base
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def member_count
|
|
|
|
|
Member.find_by_sql("select count(id) as count from members where course_id=#{self.id}").first.try(:count).to_i
|
|
|
|
|
CourseMember.find_by_sql("select count(id) as count from course_members where course_id=#{self.id}").first.try(:count).to_i
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.search(query)
|
|
|
|
@ -257,7 +257,7 @@ class Course < ActiveRecord::Base
|
|
|
|
|
|
|
|
|
|
# 选出教师数不为0的答辩组
|
|
|
|
|
def course_graduation_group
|
|
|
|
|
self.graduation_groups.select{|group| group.members.count > 0}
|
|
|
|
|
self.graduation_groups.select{|group| group.course_members.count > 0}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 课程的短描述信息
|
|
|
|
@ -420,11 +420,12 @@ class Course < ActiveRecord::Base
|
|
|
|
|
|
|
|
|
|
# 删除课程所有成员
|
|
|
|
|
def delete_all_members
|
|
|
|
|
if self.members && self.members.count > 0
|
|
|
|
|
me, mr = Member.table_name, MemberRole.table_name
|
|
|
|
|
connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.course_id = #{id})")
|
|
|
|
|
Member.delete_all(['course_id = ?', id])
|
|
|
|
|
end
|
|
|
|
|
CourseMember.delete_all(['course_id = ?', id])
|
|
|
|
|
# if self.members && self.members.count > 0
|
|
|
|
|
# me, mr = Member.table_name, MemberRole.table_name
|
|
|
|
|
# connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.course_id = #{id})")
|
|
|
|
|
# Member.delete_all(['course_id = ?', id])
|
|
|
|
|
# end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 创建课程模块
|
|
|
|
|