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