2013-11-06 16:43:07 +08:00
|
|
|
|
# encoding: utf-8
|
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
|
2013-11-06 16:43:07 +08:00
|
|
|
|
1. define TeacherRoles, StudentRoles
|
|
|
|
|
2. define count function
|
|
|
|
|
3. define search by roles
|
|
|
|
|
4. define search member function
|
2013-11-04 09:45:56 +08:00
|
|
|
|
=end
|
2013-11-06 16:43:07 +08:00
|
|
|
|
TeacherRoles = [3, 4, 7, 9]
|
|
|
|
|
StudentRoles = [5, 10]
|
|
|
|
|
|
|
|
|
|
## return people count
|
|
|
|
|
|
|
|
|
|
# 返回教师数量,即roles表中定义的Manager
|
|
|
|
|
def teacherCount project
|
|
|
|
|
# searchCountByRoles project, TeacherRoles
|
|
|
|
|
# or
|
|
|
|
|
searchTeacherAndAssistant(project).count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 返回学生数量,即roles表中定义的Reporter
|
|
|
|
|
def studentCount project
|
|
|
|
|
# searchCountByRoles project,StudentRoles
|
|
|
|
|
# or
|
|
|
|
|
searchStudent(project).count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# =====================================================================================
|
|
|
|
|
# return people list
|
|
|
|
|
def searchTeacherAndAssistant project
|
|
|
|
|
searchPeopleByRoles(project, TeacherRoles)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def searchStudent project
|
|
|
|
|
searchPeopleByRoles(project, StudentRoles)
|
|
|
|
|
end
|
|
|
|
|
# =====================================================================================
|
|
|
|
|
|
|
|
|
|
def searchCountByRoles project, roles_id
|
|
|
|
|
people = searchPeopleByRoles project, roles_id
|
|
|
|
|
people.count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def searchPeopleByRoles project, roles_id
|
|
|
|
|
people = []
|
|
|
|
|
begin
|
|
|
|
|
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
|
|
|
|
|
people
|
|
|
|
|
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 findCourseTime project
|
|
|
|
|
str = ""
|
|
|
|
|
begin
|
2013-11-07 14:38:37 +08:00
|
|
|
|
@course = Course.find_by_extra(@project.identifier)
|
|
|
|
|
date_format = l(:zh_date)[:formats][:default]
|
|
|
|
|
if @course
|
2013-11-06 16:43:07 +08:00
|
|
|
|
str = DateTime.parse(@course.setup_time.to_s).strftime("#{date_format}").to_s unless @course.setup_time.blank?
|
|
|
|
|
str << '-' unless @course.setup_time.blank?
|
|
|
|
|
str << DateTime.parse(@course.endup_time.to_s).strftime("#{date_format}").to_s unless @course.endup_time.blank?
|
|
|
|
|
end
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
logger.error "[CoursesHelper] ===> #{e}"
|
|
|
|
|
end
|
|
|
|
|
str
|
|
|
|
|
end
|
2013-10-31 10:57:46 +08:00
|
|
|
|
end
|