|
|
|
|
# encoding: utf-8
|
|
|
|
|
=begin
|
|
|
|
|
identity字段含义
|
|
|
|
|
0 教师教授
|
|
|
|
|
1 学生
|
|
|
|
|
2 专业人士
|
|
|
|
|
#3 开发者
|
|
|
|
|
|
|
|
|
|
gender 0:男 1:女
|
|
|
|
|
=end
|
|
|
|
|
class UserExtensions < ActiveRecord::Base
|
|
|
|
|
validate :school, presence: true
|
|
|
|
|
|
|
|
|
|
belongs_to :user
|
|
|
|
|
belongs_to :school, :class_name => 'School', :foreign_key => :school_id
|
|
|
|
|
belongs_to :department
|
|
|
|
|
attr_accessible :user_id,:birthday,:brief_introduction,:gender,:location, :location_city, :occupation,:work_experience,:zip_code,:identity, :technical_title,:student_id,:school_id,:department_id
|
|
|
|
|
validates_length_of :description, :maximum => 255
|
|
|
|
|
validates_length_of :brief_introduction, :maximum => 255
|
|
|
|
|
TEACHER = 0
|
|
|
|
|
STUDENT = 1
|
|
|
|
|
ENTERPRISE = 2
|
|
|
|
|
DEVELOPER = 3
|
|
|
|
|
#this method was used to update the table user_extensions
|
|
|
|
|
def update_user_extensions(birthday=nil,brief_introduction=nil,
|
|
|
|
|
gender=nil,location=nil,occupation=nil,work_experience=nil,zip_code=nil)
|
|
|
|
|
self.birthday = birthday
|
|
|
|
|
self.brief_introduction = brief_introduction
|
|
|
|
|
self.gender = gender
|
|
|
|
|
self.location = location
|
|
|
|
|
self.occupation = occupation
|
|
|
|
|
self.work_experience = work_experience
|
|
|
|
|
self.zip_code = zip_code
|
|
|
|
|
self.save
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def get_brief_introduction
|
|
|
|
|
return self.brief_introduction
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def job_title
|
|
|
|
|
self.identity == 1 ? "" :self.try(:technical_title)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# added by meng
|
|
|
|
|
def show_identity
|
|
|
|
|
if User.current.language == 'zh'||User.current.language == ''
|
|
|
|
|
case self.identity
|
|
|
|
|
when 0
|
|
|
|
|
user_identity = l(:label_account_identity_teacher)
|
|
|
|
|
when 1
|
|
|
|
|
user_identity = l(:label_account_identity_student)
|
|
|
|
|
when 2
|
|
|
|
|
user_identity = l(:label_account_identity_professional)
|
|
|
|
|
when 3
|
|
|
|
|
user_identity = l(:label_account_identity_professional)
|
|
|
|
|
else
|
|
|
|
|
user_identity = ''
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
case self.identity
|
|
|
|
|
when 0
|
|
|
|
|
user_identity = l(:label_account_identity_teacher)
|
|
|
|
|
when 1
|
|
|
|
|
user_identity = l(:label_account_identity_student)
|
|
|
|
|
when 2
|
|
|
|
|
user_identity = l(:label_account_identity_professional)
|
|
|
|
|
when 3
|
|
|
|
|
user_identity = l(:label_account_identity_professional)
|
|
|
|
|
else
|
|
|
|
|
user_identity = ''
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return user_identity
|
|
|
|
|
end
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def self.introduction(user, message)
|
|
|
|
|
unless user.user_extensions.nil?
|
|
|
|
|
info = user.user_extensions
|
|
|
|
|
info.brief_introduction = message
|
|
|
|
|
info.save
|
|
|
|
|
else
|
|
|
|
|
info = UserExtensions.new
|
|
|
|
|
info.user_id = user.id
|
|
|
|
|
info.brief_introduction = message
|
|
|
|
|
info.save
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def user_technical_title
|
|
|
|
|
if self.identity == 1
|
|
|
|
|
title = self.student_id
|
|
|
|
|
elsif self.technical_title
|
|
|
|
|
title = self.technical_title
|
|
|
|
|
else
|
|
|
|
|
title = ''
|
|
|
|
|
end
|
|
|
|
|
title
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|