Module: UserProfile

Extended by:
ActiveSupport::Concern
Included in:
User
Defined in:
app/models/concerns/user_profile.rb

Overview

This module contains all the profile-related methods of a User.

Instance Method Summary collapse

Instance Method Details

#academic_degreeObject



62
63
64
# File 'app/models/concerns/user_profile.rb', line 62

def academic_degree
  cached { profile_field_value 'academic_degree' }
end

#fill_in_template_profile_informationObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/models/concerns/user_profile.rb', line 83

def fill_in_template_profile_information
  self.profile_fields.create(label: :personal_title, type: "ProfileFieldTypes::General")
  self.profile_fields.create(label: :academic_degree, type: "ProfileFieldTypes::AcademicDegree")

  self.profile_fields.create(label: :work_address, type: "ProfileFieldTypes::Address")
  self.profile_fields.create(label: :phone, type: "ProfileFieldTypes::Phone") unless self.phone
  self.profile_fields.create(label: :mobile, type: "ProfileFieldTypes::Phone") unless self.mobile
  self.profile_fields.create(label: :fax, type: "ProfileFieldTypes::Phone")
  self.profile_fields.create(label: :homepage, type: "ProfileFieldTypes::Homepage")

  pf = self.profile_fields.build(label: :bank_account, type: "ProfileFieldTypes::BankAccount")
  pf.becomes(ProfileFieldTypes::BankAccount).save

  pf = self.profile_fields.create(label: :name_field, type: "ProfileFieldTypes::NameSurrounding")
    .becomes(ProfileFieldTypes::NameSurrounding)
  pf.text_above_name = ""; pf.name_prefix = "Herrn"; pf.name_suffix = ""; pf.text_below_name = ""
  pf.save
end

#landline_profile_fieldsObject



32
33
34
# File 'app/models/concerns/user_profile.rb', line 32

def landline_profile_fields
  phone_profile_fields - mobile_phone_profile_fields
end

#mobileObject



48
49
50
# File 'app/models/concerns/user_profile.rb', line 48

def mobile
  (mobile_phone_profile_fields + phone_profile_fields).first.try(:value)
end

#mobile=(new_number) ⇒ Object



51
52
53
# File 'app/models/concerns/user_profile.rb', line 51

def mobile=(new_number)
  (mobile_phone_profile_fields.first || profile_fields.create(label: I18n.t(:mobile), type: 'ProfileFieldTypes::Phone')).update_attributes(value: new_number)
end

#mobile_phone_profile_fieldsObject



35
36
37
38
39
# File 'app/models/concerns/user_profile.rb', line 35

def mobile_phone_profile_fields
  phone_profile_fields.select do |field|
    field.label.downcase.include?('mobil') or field.label.downcase.include?('handy')
  end
end

#name_surrounding_profile_fieldObject



66
67
68
# File 'app/models/concerns/user_profile.rb', line 66

def name_surrounding_profile_field
  profile_fields.where(type: "ProfileFieldTypes::NameSurrounding").first
end

#personal_titleObject



58
59
60
# File 'app/models/concerns/user_profile.rb', line 58

def personal_title
  cached { profile_field_value 'personal_title' }
end

#phoneObject



41
42
43
# File 'app/models/concerns/user_profile.rb', line 41

def phone
  (landline_profile_fields + phone_profile_fields).first.try(:value)
end

#phone=(new_number) ⇒ Object



44
45
46
# File 'app/models/concerns/user_profile.rb', line 44

def phone=(new_number)
  (landline_profile_fields.first || profile_fields.create(label: I18n.t(:phone), type: 'ProfileFieldTypes::Phone')).update_attributes(value: new_number)
end

#phone_profile_fieldsObject



26
27
28
29
30
# File 'app/models/concerns/user_profile.rb', line 26

def phone_profile_fields
  profile_fields.where(type: 'ProfileFieldTypes::Phone').select do |field|
    not field.label.downcase.include? 'fax'
  end
end

#profile_field_value(label) ⇒ Object



55
56
57
# File 'app/models/concerns/user_profile.rb', line 55

def profile_field_value(label)
  profile_fields.where(label: label).first.try(:value).try(:strip)
end

#text_above_nameObject



69
70
71
# File 'app/models/concerns/user_profile.rb', line 69

def text_above_name
  name_surrounding_profile_field.try(:text_above_name).try(:strip)
end

#text_after_nameObject



78
79
80
# File 'app/models/concerns/user_profile.rb', line 78

def text_after_name
  name_surrounding_profile_field.try(:name_suffix).try(:strip)
end

#text_before_nameObject



75
76
77
# File 'app/models/concerns/user_profile.rb', line 75

def text_before_name
  name_surrounding_profile_field.try(:name_prefix).try(:strip)
end

#text_below_nameObject



72
73
74
# File 'app/models/concerns/user_profile.rb', line 72

def text_below_name
  name_surrounding_profile_field.try(:text_below_name).try(:strip)
end