socialforge/app/helpers/courses_helper.rb

29 lines
828 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 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