fix teacher/student search Identifier

This commit is contained in:
yanxd 2013-11-04 09:45:56 +08:00
parent 271153aa78
commit ce7b2ceba0
2 changed files with 45 additions and 12 deletions

View File

@ -1,31 +1,64 @@
## This helper be included in applicationHelper
module CoursesHelper
# 返回学生数量即roles表中定义的Reporter 返回结果 -1 为查询失败
=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]
# 返回学生数量即roles表中定义的Reporter
def studentCount project
searchCountByRoles project, 5
searchStudent(project).count
end
# 返回教师数量即roles表中定义的Manager 返回结果 -1 为查询失败
# 返回教师数量即roles表中定义的Manager
def teacherCount project
searchCountByRoles project, 3
searchTeacherAndAssistant(project).count
end
# 返回TA数量即roles表中定义的TA 返回结果 -1 为查询失败
def teacherAssistantCount project
searchCountByRoles project, 7
# =====================================================================================
def searchTeacherAndAssistant project
members = []
TeacherRoles.each do |role|
members += searchPeopleByRoles(project, role)
end
members
end
# 根据角色查询
def searchStudent project
members = []
StudentRoles.each do |role|
members += searchPeopleByRoles(project, role)
end
members
end
# =====================================================================================
#useless
def searchCountByRoles project, roles_id
people = searchPeopleByRoles project, roles_id
people.count
end
# 根据角色查人
#useless
def searchPeopleByRole project, role_id
people = []
begin
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
def searchPeopleByRoles project, roles_id
people = []
begin
people = project.members.joins(:member_roles).where("member_roles.role_id = :role_id", {:role_id => roles_id })
people = project.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => roles_id})
rescue Exception => e
logger.error "[CoursesHelper] ===> #{e}"
end

View File

@ -8,8 +8,8 @@
<% roles = Role.find_all_givable %>
<% members = @project.member_principals.includes(:roles, :principal).all.sort %>
<!-- 如果是课程且点击教师或者学生,则对成员进行过滤 -->
<% members = searchPeopleByRoles(@project, 3).sort if params[:role] == '1' %>
<% members = searchPeopleByRoles(@project, 5).sort if params[:role] == '2' %>
<% members = searchTeacherAndAssistant(@project) if params[:role] == '1' %>
<% members = searchStudent(@project) if params[:role] == '2' %>
<% if @project.project_type == 1 %>
<%= render :partial => 'member_list', :locals => {:members => members} %>
<% else %>