socialforge/app/models/user_extensions.rb

87 lines
2.3 KiB
Ruby
Raw Normal View History

2014-01-16 10:34:39 +08:00
# encoding: utf-8
=begin
identity字段含义
0
1
2
3
=end
2013-08-14 21:37:55 +08:00
class UserExtensions < ActiveRecord::Base
2014-05-22 19:58:13 +08:00
validate :school, presence: true
2013-08-19 17:28:59 +08:00
belongs_to :user
belongs_to :school, :class_name => 'School', :foreign_key => :school_id
attr_accessible :user_id,:birthday,:brief_introduction,:gender,:location,:occupation,:work_experience,:zip_code,:identity, :technical_title,:student_id
2014-01-20 20:56:37 +08:00
TEACHER = 0
STUDENT = 1
ENTERPRISE = 2
DEVELOPER = 3
2013-08-14 21:37:55 +08:00
#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
# added by meng
2014-01-09 10:58:05 +08:00
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_enterprise)
when 3
user_identity = l(:label_account_identity_developer)
else
user_identity = ''
end
2014-01-09 10:58:05 +08:00
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_enterprise)
when 3
user_identity = l(:label_account_identity_developer)
else
user_identity = ''
end
2014-01-09 10:58:05 +08:00
end
return user_identity
end
# end
2013-09-14 17:22:44 +08:00
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
2014-01-09 10:58:05 +08:00
2013-08-14 21:37:55 +08:00
end