class Person

Person

Constants

ALL_AFFILIATIONS

TODO: should become the value of self&.pluck(:affiliations)&.flatten!&.compact!&.uniq!&.sort!

FACULTY_STATUSES
GENDERS
STUDENT_ROLES

Public Instance Methods

accepted_student_only?() click to toggle source
# File lib/buweb/person.rb, line 236
def accepted_student_only?
  accepted_student? && (affiliations_to_sym - [:accepted_student]).empty?
end
affiliations_to_sym() click to toggle source
# File lib/buweb/person.rb, line 252
def affiliations_to_sym
  @aff_sym ||= affiliations.to_a.map do |a|
    a.to_s.parameterize.underscore.to_sym
  end
end
alumnus_only?() click to toggle source
# File lib/buweb/person.rb, line 248
def alumnus_only?
  alumnus? && (affiliations_to_sym - [:alumnus]).empty?
end
as_indexed_json(*) click to toggle source
# File lib/buweb/person.rb, line 265
def as_indexed_json(*)
  {
    slug: slug,
    affiliations: visible_affiliations,
    department: department_title,
    departments: departments.to_a.map(&:title),
    department_aliases: departments.to_a.map(&:aliases).flatten,
    email: preferred_biola_email,
    biola_id: biola_id,
    titles: titles,
    biola_title: biola_title,
    faculty_status: faculty_status,
    first_initial: first_initial,
    first_name: first_name,
    full_legal_name: full_legal_name,
    last_initial: last_initial,
    last_name: last_name,
    last_name_raw: last_name,
    legal_name: legal_name,
    middle_name: middle_name,
    normalized_data: {
      title: name,
      subtitles: (titles + [department_title]).compact.presence || [major, minor].compact,
      short_description: nil,
      location: office_location,
      image_url: profile_photo_url(:thumb),
      phone: full_biola_phone_number,
      alternate_phone: full_biola_phone_number(:alternate_employee_phone),
      published: published,
      email: preferred_biola_email
    },
    preferred_name: preferred_name,
    display_name: display_name,
    previous_last_name: previous_last_name,
    major: major,
    minor: minor,
    mailbox: mailbox,
    privacy: privacy,
    is_public: public?,
    show_work_email: show_work_email,
    show_employee_phone: show_employee_phone
  }
end
bio_edition() click to toggle source
# File lib/buweb/person.rb, line 147
def bio_edition
  @bio_edition ||= bio_editions.published.first
end
birthday() click to toggle source
# File lib/buweb/person.rb, line 191
def birthday
  # Should return month and day as string. Example: "February 03"
  birth_date.strftime('%B %d') if birth_date
end
custom_profile() click to toggle source
# File lib/buweb/person.rb, line 151
def custom_profile
  @custom_profile ||= custom_profiles.published.first
end
department_memberships() click to toggle source
# File lib/buweb/person.rb, line 141
def department_memberships
  departments.map do |d|
    d.memberships.to_a.find { |m| m.person_id == id }
  end.compact
end
departments(published_only: true) click to toggle source
# File lib/buweb/person.rb, line 127
def departments(published_only: true)
  if published_only
    Department.elem_match(memberships: {person_id: id, published: true}).where(published: true)
  else
    Department.where({'memberships.person_id' => id})
  end
end
dont_index?() click to toggle source
# File lib/buweb/person.rb, line 323
def dont_index?
  private? || accepted_student_only? || !published || empty_alumnus?
end
empty_alumnus?() click to toggle source
# File lib/buweb/person.rb, line 309
def empty_alumnus?
  visible_affiliations == [:alumnus] &&
    preferred_biola_email.blank? &&
    full_biola_phone_number.blank? &&
    alternate_employee_phone.blank?
end
first_initial() click to toggle source
# File lib/buweb/person.rb, line 196
def first_initial
  preferred_name.to_s[0] || ''
end
group_memberships() click to toggle source
# File lib/buweb/person.rb, line 135
def group_memberships
  groups.map do |g|
    g.memberships.to_a.find { |m| m.person_id == id }
  end.compact
end
groups(published_only: true) click to toggle source
# File lib/buweb/person.rb, line 121
def groups(published_only: true)
  conditions = published_only ? { published: true } : {}

  Group.where({ 'memberships.person_id' => id }.merge conditions)
end
id_card_image(size = :medium) click to toggle source
# File lib/buweb/person.rb, line 159
def id_card_image(size = :medium)
  # I want to use a size up since id_card_images come really small.
  size = :large if size == :medium
  size = :medium if %i[small thumb].include? size
  if biola_id.present?
    digest = Digest::MD5.hexdigest(biola_id.to_s)
    "https://apps.biola.edu/idphotos/#{digest}_#{size}.jpg"
  end
end
is_public?()
Alias for: public?
last_initial() click to toggle source
# File lib/buweb/person.rb, line 204
def last_initial
  last_name.to_s[0] || ''
end
middle_initial() click to toggle source
# File lib/buweb/person.rb, line 224
def middle_initial
  middle_name[0, 1] if middle_name
end
name() click to toggle source
# File lib/buweb/person.rb, line 208
def name
  if display_name.present?
    display_name
  else
    [preferred_name, last_name].join(' ').squeeze(' ')
  end
end
private?() click to toggle source
# File lib/buweb/person.rb, line 334
def private?
  return false if faculty? || employee?
  privacy
end
profile_photo() click to toggle source
# File lib/buweb/person.rb, line 155
def profile_photo
  @profile_photo ||= ProfilePhoto.where(id: profile_photo_id).first if profile_photo_id
end
profile_photo_url(size=:small) click to toggle source
# File lib/buweb/person.rb, line 169
def profile_photo_url(size=:small)
  # use primary profile_photo if there is one, otherwise use the id_card_image
  profile_photo = self.profile_photo
  profile_photo ? profile_photo.photo.url(size) : self.id_card_image(size)
end
public?() click to toggle source
# File lib/buweb/person.rb, line 327
def public?
  return true if faculty?
  return false if student? || private?
  publicly_viewable
end
Also aliased as: is_public?
student?() click to toggle source
# File lib/buweb/person.rb, line 240
def student?
  (affiliations_to_sym & STUDENT_ROLES).any?
end
student_only?() click to toggle source
# File lib/buweb/person.rb, line 244
def student_only?
  student? && (affiliations_to_sym - STUDENT_ROLES).empty?
end
to_s() click to toggle source
# File lib/buweb/person.rb, line 187
def to_s
  name || ''
end
visible_affiliations() click to toggle source
# File lib/buweb/person.rb, line 258
def visible_affiliations
  # list all affiliations minus student or alumnus if they are private
  affiliations_to_remove = privacy? ? %i[student alumnus] : []
  affiliations_to_remove += %i[accepted_student] # any affiliation that should never show up to anyone
  affiliations.to_a.map { |aff| aff.to_s.gsub(' ', '_').to_sym } - affiliations_to_remove
end

Private Instance Methods

clean_arrays() click to toggle source
# File lib/buweb/person.rb, line 345
def clean_arrays
  %i[affiliations groupings].each do |att|
    next if send(att).nil?
    send("#{att}=", send(att).reject(&:blank?))
  end
end
parameterize_groupings() click to toggle source
# File lib/buweb/person.rb, line 352
def parameterize_groupings
  return unless groupings.present?
  groupings.map!(&:parameterize)
end
set_preferred_name() click to toggle source
# File lib/buweb/person.rb, line 341
def set_preferred_name
  self.preferred_name = preferred_name.presence || first_name
end
update_bio_slug() click to toggle source
# File lib/buweb/person.rb, line 357
def update_bio_slug
  return if bio_editions.empty? || slug == bio_editions.first&.slug
  bio_editions.first.update_attribute(:slug, slug)
end