Guest User

Untitled

a guest
Mar 7th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.06 KB | None | 0 0
  1. class Contact < ActiveRecord::Base
  2. set_table_name 'TCONTACT'
  3. set_primary_key 'ETL_ID'
  4.  
  5. # sets up the relationship where data sync'd with Salesforce
  6. # is stored in this table and the authentication information
  7. # is stored in the student table
  8. has_one :user
  9.  
  10. before_create :set_created_at
  11. before_update :set_modified_at
  12. before_update :set_recalculated_gpa
  13.  
  14. # Begin validations for creating the user
  15. validates_presence_of :email
  16. validates_length_of :email, :within => 3..240
  17. validates_format_of :email, :with => %r{^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$}i
  18. # not sure why this one doesn't work with remapped attributes...any ideas?
  19. validates_uniqueness_of :EMAIL, :case_sensitive => false, :allow_nil => true
  20.  
  21. validates_presence_of :first_name
  22. validates_length_of :first_name, :maximum => 120 # based on mysql schema
  23.  
  24. validates_presence_of :last_name
  25. validates_length_of :last_name, :maximum => 240 # based on mysql schema
  26.  
  27. validates_presence_of :current_street
  28.  
  29. validates_presence_of :current_city
  30. validates_length_of :current_city, :maximum => 120 # based on mysql schema
  31.  
  32. validates_presence_of :current_state
  33. validates_length_of :current_state, :maximum => 60 # based on mysql schema
  34.  
  35. validates_presence_of :current_zip
  36. validates_length_of :current_zip, :within => 5..60 # based on mysql schema
  37. # End validations for creating the user
  38.  
  39. # Begin validations for updating the user
  40. # in the personal info section of the application
  41. # THESE ARE ON UPDATE BECAUSE IT WILL BREAK THE REG PROCESS IF THEY ARE NOT
  42. validates_presence_of :current_country, :on => :update
  43. validates_length_of :current_country, :on => :update, :maximum => 120 # based on mysql schema
  44.  
  45. validates_presence_of :current_home_phone, :on => :update
  46. validates_length_of :current_home_phone, :on => :update, :maximum => 120 # based on mysql schema
  47.  
  48. validates_presence_of :current_mobile_phone, :on => :update
  49. validates_length_of :current_mobile_phone, :on => :update, :maximum => 120 # based on mysql schema
  50.  
  51.  
  52.  
  53. validates_presence_of :permanent_street, :on => :update
  54.  
  55. validates_presence_of :permanent_city, :on => :update
  56. validates_length_of :permanent_city, :on => :update, :maximum => 120 # based on mysql schema
  57.  
  58. validates_presence_of :permanent_state, :on => :update
  59. validates_length_of :permanent_state, :on => :update, :maximum => 60 # based on mysql schema
  60.  
  61. validates_presence_of :permanent_zip, :on => :update
  62. validates_length_of :permanent_zip, :on => :update, :within => 5..30 # based on mysql schema
  63.  
  64. validates_presence_of :permanent_country, :on => :update
  65. validates_length_of :permanent_country, :on => :update, :maximum => 120 # based on mysql schema
  66.  
  67. validates_presence_of :permanent_home_phone, :on => :update
  68. validates_length_of :permanent_home_phone, :on => :update, :maximum => 120 # based on mysql schema
  69.  
  70. validates_presence_of :permanent_mobile_phone, :on => :update
  71. validates_length_of :permanent_mobile_phone, :on => :update, :maximum => 120 # based on mysql schema
  72.  
  73. validates_presence_of :citizenship, :on => :update
  74. # validates_presence_of :birth_date, :on => :update # change this back once it works with date_select
  75. validates_presence_of :BIRTHDATE, :on => :update # remove this once above works with date_select
  76. validates_presence_of :birth_city, :on => :update
  77. validates_presence_of :birth_state, :on => :update
  78. validates_length_of :birth_state, :on => :update, :maximum => 60
  79. validates_presence_of :birth_country, :on => :update
  80. validates_presence_of :language, :on => :update
  81. validates_presence_of :home_language, :on => :update
  82. validates_presence_of :gender, :on => :update
  83. validates_presence_of :parents_marital_status, :on => :update
  84.  
  85. validates_presence_of :expected_start_term, :on => :update
  86. validates_presence_of :expected_start_year, :on => :update
  87. validates_presence_of :expected_enrollment_status, :on => :update
  88. validates_presence_of :expected_housing_preference, :on => :update
  89. validates_presence_of :expected_major, :on => :update
  90. validates_presence_of :expected_graduation_year, :on => :update
  91. validates_presence_of :reported_gpa, :on => :update
  92. validates_presence_of :reported_gpa_scale, :on => :update
  93. validates_presence_of :class_rank, :on => :update
  94.  
  95. # generated with a before_filter
  96. # validates_presence_of :recalculated_gpa, :on => :update
  97. # End validations for updating the user
  98. # in the personal info section of the application
  99.  
  100. remappings = [
  101. ['first_name', 'FIRSTNAME'],
  102. ['middle_name', 'TARGETXDEV__MIDDLE_NAME'],
  103. ['last_name', 'LASTNAME'],
  104. ['nick_name', 'TARGETXDEV__NICKNAME'],
  105. ['title', 'SALUTATION'],
  106. ['suffix', 'TARGETXDEV__SUFFIX'],
  107. ['ssn', 'TARGETXDEV__SSN'],
  108. ['former_last_name', 'TARGETXDEV__FORMER_LAST_NAME'],
  109. ['email', 'EMAIL'],
  110.  
  111. # current is mailing in db
  112. ['current_street', 'MAILINGSTREET'],
  113. ['current_city', 'MAILINGCITY'],
  114. ['current_state', 'MAILINGSTATE'],
  115. ['current_zip', 'MAILINGPOSTALCODE'],
  116. ['current_country', 'MAILINGCOUNTRY'],
  117. ['current_home_phone', 'HOMEPHONE'],
  118. ['current_mobile_phone', 'MOBILEPHONE'],
  119.  
  120. # permanent is alternate in db
  121. ['permanent_street', 'TARGETXDEV__ALTERNATE_ADDRESS'],
  122. ['permanent_city', 'TARGETXDEV__ALTERNATE_CITY'],
  123. ['permanent_state', 'TARGETXDEV__ALTERNATE_STATE'],
  124. ['permanent_zip', 'TARGETXDEV__ALTERNATE_POSTAL_C'],
  125. ['permanent_country', 'TARGETXDEV__ALTERNATE_COUNTRY'],
  126. ['permanent_home_phone', 'TARGETXDEV__ALTERNATE_HOME_PHO'],
  127. ['permanent_mobile_phone', 'TARGETXDEV__ALTERNATE_MOBILE_P'],
  128.  
  129. ['citizenship', 'TARGETXDEV__CITIZENSHIP'],
  130. ['primary_other_citizenship', 'TARGETXDEV__PRIMARY_OTHER_CITI'],
  131. ['secondary_other_citizenship', 'TARGETXDEV__SECONDARY_OTHER_CI'],
  132. ['alien_registration', 'TARGETXDEV__ALIEN_REGISTRATION'],
  133. ['visa_type', 'TARGETXDEV__VISA_TYPE'],
  134. ['dual_citizenship', 'TARGETXDEV__DUAL_CITIZENSHIP'],
  135. ['permanent_country_of_residence', 'TARGETXDEV__COUNTRY_OF_PERMANE'],
  136. # ['birth_date', 'BIRTHDATE'], fix this, doesn't work with date_select
  137. ['birth_city', 'TARGETXDEV__BIRTH_CITY'],
  138. ['birth_state', 'TARGETXDEV__BIRTH_STATE'],
  139. ['birth_country', 'TARGETXDEV__BIRTH_COUNTRY'],
  140. ['language', 'TARGETXDEV__LANGUAGE'],
  141. ['home_language', 'TARGETXDEV__HOME_LANGUAGE'],
  142. ['marital_status', 'TARGETXDEV__MARITAL_STATUS'],
  143. # ['divorce_date', 'TARGETXDEV__DIVORCE_DATE'], fix this, doesn't work with date_select
  144. ['ethnicity', 'TARGETXDEV__ETHNICITY'],
  145. ['ethnicity_other', 'TARGETXDEV__ETHNICITY_OTHER'],
  146. ['gender', 'TARGETXDEV__GENDER'],
  147. ['religion', 'TARGETXDEV__RELIGION'],
  148. ['parents_marital_status', 'TARGETXDEV__PARENTS_MARITAL_ST'],
  149. # ['parents_divorce_date', 'TARGETXDEV__PARENTS_DIVORCE_DA'], # fix this, doesn't work with date_select
  150. ['permanent_home', 'TARGETXDEV__PERMANENT_HOME'],
  151. ['permanent_home_other', 'TARGETXDEV__PERMANENT_HOME_OTH'],
  152. ['expected_start_term', 'TARGETXDEV__ANTICIPATED_START'],
  153. ['expected_start_year', 'TARGETXDEV__ANTICIPATED_STAR0'],
  154. ['expected_enrollment_status', 'TARGETXDEV__ANTICIPATED_ENROLL'],
  155. ['expected_housing_preference', 'TARGETXDEV__ANTICIPATED_HOUSIN'],
  156. ['expected_major', 'TARGETXDEV__ANTICIPATED_MAJOR'],
  157. ['expected_graduation_year', 'TARGETXDEV__GRADUATION_YEAR'],
  158. ['reported_gpa', 'TARGETXDEV__REPORTED_GPA'],
  159. ['reported_gpa_scale', 'TARGETXDEV__GPA_SCALE'],
  160. ['recalculated_gpa', 'TARGETXDEV__RECALCULATED_GPA'], # reported_gpa * 4 / gpa_scale
  161. ['class_rank', 'TARGETXDEV__PERCENTILE_RANK'],
  162.  
  163.  
  164. ['created_at', 'CREATEDDATE'],
  165. ['modified_at', 'LASTMODIFIEDDATE']
  166. ]
  167.  
  168. rename(remappings)
  169.  
  170. private
  171. def set_ID_in_development_mode
  172. if ENV['RAILS_ENV'] == 'development'
  173. self.ID =
  174. end
  175. end
  176. def set_recalculated_gpa
  177. if recalculated_gpa.blank? && !reported_gpa.blank? && !reported_gpa_scale.blank?
  178. self.recalculated_gpa = reported_gpa * 4 / reported_gpa_scale.to_f
  179. end
  180. end
  181. def set_created_at
  182. self.created_at = Time.now
  183. end
  184. def set_modified_at
  185. self.modified_at = Time.now
  186. end
  187. end
Add Comment
Please, Sign In to add comment