Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Contact < ActiveRecord::Base
- set_table_name 'TCONTACT'
- set_primary_key 'ETL_ID'
- # sets up the relationship where data sync'd with Salesforce
- # is stored in this table and the authentication information
- # is stored in the student table
- has_one :user
- before_create :set_created_at
- before_update :set_modified_at
- before_update :set_recalculated_gpa
- # Begin validations for creating the user
- validates_presence_of :email
- validates_length_of :email, :within => 3..240
- 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
- # not sure why this one doesn't work with remapped attributes...any ideas?
- validates_uniqueness_of :EMAIL, :case_sensitive => false, :allow_nil => true
- validates_presence_of :first_name
- validates_length_of :first_name, :maximum => 120 # based on mysql schema
- validates_presence_of :last_name
- validates_length_of :last_name, :maximum => 240 # based on mysql schema
- validates_presence_of :current_street
- validates_presence_of :current_city
- validates_length_of :current_city, :maximum => 120 # based on mysql schema
- validates_presence_of :current_state
- validates_length_of :current_state, :maximum => 60 # based on mysql schema
- validates_presence_of :current_zip
- validates_length_of :current_zip, :within => 5..60 # based on mysql schema
- # End validations for creating the user
- # Begin validations for updating the user
- # in the personal info section of the application
- # THESE ARE ON UPDATE BECAUSE IT WILL BREAK THE REG PROCESS IF THEY ARE NOT
- validates_presence_of :current_country, :on => :update
- validates_length_of :current_country, :on => :update, :maximum => 120 # based on mysql schema
- validates_presence_of :current_home_phone, :on => :update
- validates_length_of :current_home_phone, :on => :update, :maximum => 120 # based on mysql schema
- validates_presence_of :current_mobile_phone, :on => :update
- validates_length_of :current_mobile_phone, :on => :update, :maximum => 120 # based on mysql schema
- validates_presence_of :permanent_street, :on => :update
- validates_presence_of :permanent_city, :on => :update
- validates_length_of :permanent_city, :on => :update, :maximum => 120 # based on mysql schema
- validates_presence_of :permanent_state, :on => :update
- validates_length_of :permanent_state, :on => :update, :maximum => 60 # based on mysql schema
- validates_presence_of :permanent_zip, :on => :update
- validates_length_of :permanent_zip, :on => :update, :within => 5..30 # based on mysql schema
- validates_presence_of :permanent_country, :on => :update
- validates_length_of :permanent_country, :on => :update, :maximum => 120 # based on mysql schema
- validates_presence_of :permanent_home_phone, :on => :update
- validates_length_of :permanent_home_phone, :on => :update, :maximum => 120 # based on mysql schema
- validates_presence_of :permanent_mobile_phone, :on => :update
- validates_length_of :permanent_mobile_phone, :on => :update, :maximum => 120 # based on mysql schema
- validates_presence_of :citizenship, :on => :update
- # validates_presence_of :birth_date, :on => :update # change this back once it works with date_select
- validates_presence_of :BIRTHDATE, :on => :update # remove this once above works with date_select
- validates_presence_of :birth_city, :on => :update
- validates_presence_of :birth_state, :on => :update
- validates_length_of :birth_state, :on => :update, :maximum => 60
- validates_presence_of :birth_country, :on => :update
- validates_presence_of :language, :on => :update
- validates_presence_of :home_language, :on => :update
- validates_presence_of :gender, :on => :update
- validates_presence_of :parents_marital_status, :on => :update
- validates_presence_of :expected_start_term, :on => :update
- validates_presence_of :expected_start_year, :on => :update
- validates_presence_of :expected_enrollment_status, :on => :update
- validates_presence_of :expected_housing_preference, :on => :update
- validates_presence_of :expected_major, :on => :update
- validates_presence_of :expected_graduation_year, :on => :update
- validates_presence_of :reported_gpa, :on => :update
- validates_presence_of :reported_gpa_scale, :on => :update
- validates_presence_of :class_rank, :on => :update
- # generated with a before_filter
- # validates_presence_of :recalculated_gpa, :on => :update
- # End validations for updating the user
- # in the personal info section of the application
- remappings = [
- ['first_name', 'FIRSTNAME'],
- ['middle_name', 'TARGETXDEV__MIDDLE_NAME'],
- ['last_name', 'LASTNAME'],
- ['nick_name', 'TARGETXDEV__NICKNAME'],
- ['title', 'SALUTATION'],
- ['suffix', 'TARGETXDEV__SUFFIX'],
- ['ssn', 'TARGETXDEV__SSN'],
- ['former_last_name', 'TARGETXDEV__FORMER_LAST_NAME'],
- ['email', 'EMAIL'],
- # current is mailing in db
- ['current_street', 'MAILINGSTREET'],
- ['current_city', 'MAILINGCITY'],
- ['current_state', 'MAILINGSTATE'],
- ['current_zip', 'MAILINGPOSTALCODE'],
- ['current_country', 'MAILINGCOUNTRY'],
- ['current_home_phone', 'HOMEPHONE'],
- ['current_mobile_phone', 'MOBILEPHONE'],
- # permanent is alternate in db
- ['permanent_street', 'TARGETXDEV__ALTERNATE_ADDRESS'],
- ['permanent_city', 'TARGETXDEV__ALTERNATE_CITY'],
- ['permanent_state', 'TARGETXDEV__ALTERNATE_STATE'],
- ['permanent_zip', 'TARGETXDEV__ALTERNATE_POSTAL_C'],
- ['permanent_country', 'TARGETXDEV__ALTERNATE_COUNTRY'],
- ['permanent_home_phone', 'TARGETXDEV__ALTERNATE_HOME_PHO'],
- ['permanent_mobile_phone', 'TARGETXDEV__ALTERNATE_MOBILE_P'],
- ['citizenship', 'TARGETXDEV__CITIZENSHIP'],
- ['primary_other_citizenship', 'TARGETXDEV__PRIMARY_OTHER_CITI'],
- ['secondary_other_citizenship', 'TARGETXDEV__SECONDARY_OTHER_CI'],
- ['alien_registration', 'TARGETXDEV__ALIEN_REGISTRATION'],
- ['visa_type', 'TARGETXDEV__VISA_TYPE'],
- ['dual_citizenship', 'TARGETXDEV__DUAL_CITIZENSHIP'],
- ['permanent_country_of_residence', 'TARGETXDEV__COUNTRY_OF_PERMANE'],
- # ['birth_date', 'BIRTHDATE'], fix this, doesn't work with date_select
- ['birth_city', 'TARGETXDEV__BIRTH_CITY'],
- ['birth_state', 'TARGETXDEV__BIRTH_STATE'],
- ['birth_country', 'TARGETXDEV__BIRTH_COUNTRY'],
- ['language', 'TARGETXDEV__LANGUAGE'],
- ['home_language', 'TARGETXDEV__HOME_LANGUAGE'],
- ['marital_status', 'TARGETXDEV__MARITAL_STATUS'],
- # ['divorce_date', 'TARGETXDEV__DIVORCE_DATE'], fix this, doesn't work with date_select
- ['ethnicity', 'TARGETXDEV__ETHNICITY'],
- ['ethnicity_other', 'TARGETXDEV__ETHNICITY_OTHER'],
- ['gender', 'TARGETXDEV__GENDER'],
- ['religion', 'TARGETXDEV__RELIGION'],
- ['parents_marital_status', 'TARGETXDEV__PARENTS_MARITAL_ST'],
- # ['parents_divorce_date', 'TARGETXDEV__PARENTS_DIVORCE_DA'], # fix this, doesn't work with date_select
- ['permanent_home', 'TARGETXDEV__PERMANENT_HOME'],
- ['permanent_home_other', 'TARGETXDEV__PERMANENT_HOME_OTH'],
- ['expected_start_term', 'TARGETXDEV__ANTICIPATED_START'],
- ['expected_start_year', 'TARGETXDEV__ANTICIPATED_STAR0'],
- ['expected_enrollment_status', 'TARGETXDEV__ANTICIPATED_ENROLL'],
- ['expected_housing_preference', 'TARGETXDEV__ANTICIPATED_HOUSIN'],
- ['expected_major', 'TARGETXDEV__ANTICIPATED_MAJOR'],
- ['expected_graduation_year', 'TARGETXDEV__GRADUATION_YEAR'],
- ['reported_gpa', 'TARGETXDEV__REPORTED_GPA'],
- ['reported_gpa_scale', 'TARGETXDEV__GPA_SCALE'],
- ['recalculated_gpa', 'TARGETXDEV__RECALCULATED_GPA'], # reported_gpa * 4 / gpa_scale
- ['class_rank', 'TARGETXDEV__PERCENTILE_RANK'],
- ['created_at', 'CREATEDDATE'],
- ['modified_at', 'LASTMODIFIEDDATE']
- ]
- rename(remappings)
- private
- def set_ID_in_development_mode
- if ENV['RAILS_ENV'] == 'development'
- self.ID =
- end
- end
- def set_recalculated_gpa
- if recalculated_gpa.blank? && !reported_gpa.blank? && !reported_gpa_scale.blank?
- self.recalculated_gpa = reported_gpa * 4 / reported_gpa_scale.to_f
- end
- end
- def set_created_at
- self.created_at = Time.now
- end
- def set_modified_at
- self.modified_at = Time.now
- end
- end
Add Comment
Please, Sign In to add comment