socialforge/app/helpers/courses_helper.rb

64 lines
1.6 KiB
Ruby
Raw Normal View History

## This helper be included in applicationHelper
module CoursesHelper
2013-11-04 09:45:56 +08:00
=begin
1. define TeacherRoles, StudentRoles
2. define count function
3. define search by roles
4. define search member function
=end
TeacherRoles = [3, 4, 7, 9]
StudentRoles = [5, 10]
2013-11-04 15:00:08 +08:00
## return people count
2013-11-04 09:45:56 +08:00
# 返回教师数量即roles表中定义的Manager
def teacherCount project
2013-11-04 15:00:08 +08:00
# searchCountByRoles project, TeacherRoles
# or
2013-11-04 09:45:56 +08:00
searchTeacherAndAssistant(project).count
end
2013-11-04 15:00:08 +08:00
# 返回学生数量即roles表中定义的Reporter
def studentCount project
# searchCountByRoles project,StudentRoles
# or
searchStudent(project).count
end
2013-11-04 09:45:56 +08:00
# =====================================================================================
2013-11-04 15:00:08 +08:00
# return people list
2013-11-04 09:45:56 +08:00
def searchTeacherAndAssistant project
2013-11-04 15:00:08 +08:00
searchPeopleByRoles(project, TeacherRoles)
end
2013-11-04 09:45:56 +08:00
def searchStudent project
2013-11-04 15:00:08 +08:00
searchPeopleByRoles(project, StudentRoles)
2013-11-04 09:45:56 +08:00
end
# =====================================================================================
2013-11-04 15:00:08 +08:00
def searchCountByRoles project, roles_id
people = searchPeopleByRoles project, roles_id
people.count
end
2013-11-04 15:00:08 +08:00
def searchPeopleByRoles project, roles_id
2013-11-04 09:45:56 +08:00
people = []
begin
2013-11-04 15:00:08 +08:00
people = project.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => roles_id})
2013-11-04 09:45:56 +08:00
rescue Exception => e
logger.error "[CoursesHelper] ===> #{e}"
end
people
end
2013-11-04 15:00:08 +08:00
#useless
def searchPeopleByRole project, role_id
people = []
begin
2013-11-04 15:00:08 +08:00
people = project.members.joins(:member_roles).where("member_roles.role_id = :role_id", {:role_id => role_id })
rescue Exception => e
logger.error "[CoursesHelper] ===> #{e}"
end
people
end
end