2013-10-31 10:57:46 +08:00
|
|
|
|
## This helper be included in applicationHelper
|
|
|
|
|
module CoursesHelper
|
|
|
|
|
# 返回学生数量,即roles表中定义的Reporter, 返回结果 -1 为查询失败
|
|
|
|
|
def studentCount project
|
|
|
|
|
searchCountByRoles project, 5
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 返回教师数量,即roles表中定义的Manager, 返回结果 -1 为查询失败
|
|
|
|
|
def teacherCount project
|
|
|
|
|
searchCountByRoles project, 3
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 返回TA数量,即roles表中定义的TA, 返回结果 -1 为查询失败
|
|
|
|
|
def teacherAssistantCount project
|
|
|
|
|
searchCountByRoles project, 7
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 根据角色查询
|
|
|
|
|
def searchCountByRoles project, roles_id
|
2013-10-31 16:52:06 +08:00
|
|
|
|
people = searchPeopleByRoles project, roles_id
|
|
|
|
|
people.count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 根据角色查人
|
|
|
|
|
def searchPeopleByRoles project, roles_id
|
|
|
|
|
people = []
|
2013-10-31 10:57:46 +08:00
|
|
|
|
begin
|
2013-10-31 16:52:06 +08:00
|
|
|
|
people = project.members.joins(:member_roles).where("member_roles.role_id = :role_id", {:role_id => roles_id })
|
2013-10-31 10:57:46 +08:00
|
|
|
|
rescue Exception => e
|
|
|
|
|
logger.error "[CoursesHelper] ===> #{e}"
|
|
|
|
|
end
|
2013-10-31 16:52:06 +08:00
|
|
|
|
people
|
2013-10-31 10:57:46 +08:00
|
|
|
|
end
|
|
|
|
|
end
|