29 lines
828 B
Ruby
29 lines
828 B
Ruby
## 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
|
||
count = -1
|
||
begin
|
||
count = project.members.joins(:member_roles).where("member_roles.role_id = :role_id", {:role_id => roles_id }).count
|
||
rescue Exception => e
|
||
logger.error "[CoursesHelper] ===> #{e}"
|
||
end
|
||
count
|
||
end
|
||
end
|