2013-10-31 10:57:46 +08:00
|
|
|
|
## 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-10-31 10:57:46 +08:00
|
|
|
|
|
2013-11-04 09:45:56 +08:00
|
|
|
|
# 返回教师数量,即roles表中定义的Manager
|
2013-10-31 10:57:46 +08:00
|
|
|
|
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
|
2013-10-31 10:57:46 +08:00
|
|
|
|
end
|
2013-11-04 15:00:08 +08:00
|
|
|
|
# 返回学生数量,即roles表中定义的Reporter
|
|
|
|
|
def studentCount project
|
|
|
|
|
# searchCountByRoles project,StudentRoles
|
|
|
|
|
# or
|
|
|
|
|
searchStudent(project).count
|
|
|
|
|
end
|
2013-10-31 10:57:46 +08:00
|
|
|
|
|
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)
|
2013-10-31 10:57:46 +08:00
|
|
|
|
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
|
|
|
|
|
2013-10-31 10:57:46 +08:00
|
|
|
|
def searchCountByRoles project, roles_id
|
2013-10-31 16:52:06 +08:00
|
|
|
|
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
|
2013-10-31 16:52:06 +08:00
|
|
|
|
people = []
|
2013-10-31 10:57:46 +08:00
|
|
|
|
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 })
|
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
|