You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/helpers/weapps/courses_helper.rb

30 lines
1.0 KiB

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