2015-01-20 17:42:18 +08:00
|
|
|
module ApiHelper
|
|
|
|
#获取用户的工作单位
|
|
|
|
def get_user_work_unit user
|
|
|
|
work_unit = ""
|
|
|
|
if user.user_extensions.identity == 0 || user.user_extensions.identity == 1
|
|
|
|
work_unit = user.user_extensions.school.name unless user.user_extensions.school.nil?
|
|
|
|
elsif user.user_extensions.identity == 3
|
|
|
|
work_unit = user.user_extensions.occupation
|
|
|
|
elsif user.user_extensions.identity == 2
|
|
|
|
work_unit = user.firstname
|
|
|
|
end
|
|
|
|
work_unit
|
|
|
|
end
|
|
|
|
|
|
|
|
#获取用户地区
|
|
|
|
def get_user_location user
|
|
|
|
location = ""
|
|
|
|
location << (user.user_extensions.location || '')
|
|
|
|
location << (user.user_extensions.location_city || '')
|
|
|
|
location
|
|
|
|
end
|
2015-01-21 15:29:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
def get_assigned_homeworks(homeworks, n, index)
|
|
|
|
homeworks += homeworks
|
|
|
|
homeworks[index + 1 .. index + n]
|
|
|
|
end
|
2015-01-22 17:21:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
def stars_to_json_like starts,show_jour,homework,show_name
|
|
|
|
result = []
|
|
|
|
starts.each do |s|
|
|
|
|
comment = get_homework_review homework,show_jour,s.rater
|
|
|
|
rater_name = show_name ? s.rater.login : l(:label_anonymous)
|
|
|
|
rater_id = show_name ? s.rater.id : ''
|
|
|
|
result << {:rater_id =>rater_id ,:rater_name => rater_name,:created_at => format_time(s.created_at),:stars => s.stars,:comment => comment}
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
2015-02-06 11:22:29 +08:00
|
|
|
|
|
|
|
#########################################################
|
|
|
|
#sw
|
|
|
|
#获取课程未匿评数量
|
|
|
|
#param: user => "用户", course_id => "查询的课程ID"
|
|
|
|
#return: 作业的数量
|
|
|
|
#########################################################
|
2015-02-06 15:52:34 +08:00
|
|
|
def get_course_anonymous_evaluation user,course
|
2015-02-06 11:22:29 +08:00
|
|
|
count = 0
|
|
|
|
if course
|
|
|
|
is_teacher = is_course_teacher user,course
|
|
|
|
if is_teacher #如果是老师,显示学生提交的作业数
|
|
|
|
course.homeworks.each do |bid|
|
|
|
|
count += bid.homeworks.count
|
|
|
|
end
|
|
|
|
else #如果是学生,显示未匿评的数量
|
|
|
|
course.homeworks.each do |bid|
|
|
|
|
count += get_student_not_batch_homework_list bid,user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-02-06 15:52:34 +08:00
|
|
|
[count,is_teacher]
|
2015-02-06 11:22:29 +08:00
|
|
|
end
|
2015-01-20 17:42:18 +08:00
|
|
|
end
|