parent
a54d53eaf4
commit
862e6f06be
@ -0,0 +1,30 @@
|
||||
module Weapps::CoursesHelper
|
||||
require 'chinese_pinyin'
|
||||
|
||||
def teacher_list teachers
|
||||
data = []
|
||||
teachers.each do |teacher|
|
||||
if teacher.user.present?
|
||||
teacher_user = teacher.user
|
||||
name = teacher_user.real_name
|
||||
role = teacher.role == "CREATOR" ? "管理员" : teacher.role == "PROFESSOR" ? "教师" : "助教"
|
||||
item = {name: name, course_member_id: teacher.id, login: teacher_user.login, user_id: teacher.user_id, role: role,
|
||||
school: teacher_user.school_name, image_url: url_to_avatar(teacher_user)}
|
||||
pinyin = Pinyin.t(name.strip, splitter: '')
|
||||
first_char = pinyin[0]
|
||||
puts first_char
|
||||
if first_char.ord >= 97 && first_char.ord <= 122
|
||||
letter = (first_char.ord - 32).chr.to_s
|
||||
else
|
||||
letter = '#'
|
||||
end
|
||||
if data.pluck(:letter).include?(letter)
|
||||
data.select{|a|a[:letter]==letter}.first[:items] << item
|
||||
else
|
||||
data << {letter: letter, items: [item]}
|
||||
end
|
||||
end
|
||||
end
|
||||
return data
|
||||
end
|
||||
end
|
@ -1,16 +1,17 @@
|
||||
json.teacher_list do
|
||||
json.array! @teacher_list do |teacher|
|
||||
json.course_member_id teacher.id
|
||||
json.name teacher.user.real_name
|
||||
json.login teacher.user.login
|
||||
json.user_id teacher.user.id
|
||||
json.role teacher.role == "CREATOR" ? "管理员" : teacher.role == "PROFESSOR" ? "教师" : "助教"
|
||||
json.school teacher.user&.school_name
|
||||
json.image_url url_to_avatar(teacher.user)
|
||||
# if @user_course_identity < Course::ASSISTANT_PROFESSOR
|
||||
# json.member_roles teacher.user.course_role(@course)
|
||||
# end
|
||||
end
|
||||
end
|
||||
json.teacher_list teacher_list(@teacher_list)
|
||||
# do
|
||||
# json.array! @teacher_list do |teacher|
|
||||
# json.course_member_id teacher.id
|
||||
# json.name teacher.user.real_name
|
||||
# json.login teacher.user.login
|
||||
# json.user_id teacher.user.id
|
||||
# json.role teacher.role == "CREATOR" ? "管理员" : teacher.role == "PROFESSOR" ? "教师" : "助教"
|
||||
# json.school teacher.user&.school_name
|
||||
# json.image_url url_to_avatar(teacher.user)
|
||||
# # if @user_course_identity < Course::ASSISTANT_PROFESSOR
|
||||
# # json.member_roles teacher.user.course_role(@course)
|
||||
# # end
|
||||
# end
|
||||
# end
|
||||
json.teacher_list_size @teacher_list_size
|
||||
json.apply_size @applications_size
|
Loading…
Reference in new issue