Newer
Older
# id :uuid not null, primary key
# address :string
# biography :text
# birthdate :date
# city :string
# country :string
# description :text
# description_short :text
# email :string
# first_name :string
# gender :integer
# habilitation :boolean default(FALSE)
# is_administration :boolean
# is_alumnus :boolean default(FALSE)
# is_author :boolean
# is_researcher :boolean
# is_teacher :boolean
# last_name :string
# linkedin :string
# name :string
# phone_mobile :string
# phone_personal :string
# phone_professional :string
# slug :string
# tenure :boolean default(FALSE)
# twitter :string
# url :string
# zipcode :string
# created_at :datetime not null
# updated_at :datetime not null
# university_id :uuid not null, indexed
# user_id :uuid indexed
# index_university_people_on_university_id (university_id)
# index_university_people_on_user_id (user_id)
# fk_rails_b47a769440 (user_id => users.id)
# fk_rails_da35e70d61 (university_id => universities.id)
include WithEducation
include WithExperiences
LIST_OF_ROLES = [
:administration,
:teacher,
:researcher,
:alumnus,
:author
].freeze
has_and_belongs_to_many :research_journal_papers,
class_name: 'Research::Journal::Paper',
join_table: :research_journal_papers_researchers,
has_many :communication_website_posts,
class_name: 'Communication::Website::Post',
foreign_key: :author_id,
dependent: :nullify
has_many :involvements,
class_name: 'University::Person::Involvement',
dependent: :destroy
-> { distinct },
through: :communication_website_posts,
source: :website
-> { distinct },
through: :education_programs,
source: :websites
validates_presence_of :first_name, :last_name
validates_uniqueness_of :email,
scope: :university_id,
allow_blank: true,
if: :will_save_change_to_email?
validates_format_of :email,
with: Devise::email_regexp,
allow_blank: true,
if: :will_save_change_to_email?
scope :teachers, -> { where(is_teacher: true) }
scope :researchers, -> { where(is_researcher: true) }
scope :for_role, -> (role) { where("is_#{role}": true) }
scope :for_program, -> (program_id) {
left_joins(:education_programs_as_administrator, :education_programs_as_teacher)
.where(education_programs: { id: program_id })
.or(
left_joins(:education_programs_as_administrator, :education_programs_as_teacher)
.where(education_programs_as_teachers_university_people: { id: program_id })
)
.select("university_people.*")
.distinct
}
scope :for_search_term, -> (term) {
where("
unaccent(concat(university_people.first_name, ' ', university_people.last_name)) ILIKE unaccent(:term) OR
unaccent(concat(university_people.last_name, ' ', university_people.first_name)) ILIKE unaccent(:term) OR
unaccent(university_people.first_name) ILIKE unaccent(:term) OR
unaccent(university_people.last_name) ILIKE unaccent(:term) OR
unaccent(university_people.email) ILIKE unaccent(:term) OR
unaccent(university_people.phone_mobile) ILIKE unaccent(:term) OR
unaccent(university_people.phone_personal) ILIKE unaccent(:term) OR
unaccent(university_people.phone_professional) ILIKE unaccent(:term) OR
unaccent(university_people.biography) ILIKE unaccent(:term) OR
unaccent(university_people.description) ILIKE unaccent(:term) OR
unaccent(university_people.description_short) ILIKE unaccent(:term) OR
unaccent(university_people.twitter) ILIKE unaccent(:term) OR
unaccent(university_people.linkedin) ILIKE unaccent(:term) OR
unaccent(university_people.address) ILIKE unaccent(:term) OR
unaccent(university_people.zipcode) ILIKE unaccent(:term) OR
unaccent(university_people.city) ILIKE unaccent(:term) OR
unaccent(university_people.url) ILIKE unaccent(:term)
", term: "%#{sanitize_sql_like(term)}%")
}
LIST_OF_ROLES.reject do |role|
def git_path(website)
"content/persons/#{slug}.html" if for_website?(website)
dependencies = [self]
dependencies += active_storage_blobs
dependencies += git_block_dependencies
dependencies += [administrator, author, researcher, teacher]
dependencies += dependencies_through_blocks(website)
def administrator
@administrator ||= University::Person::Administrator.find(id)
def author
@author ||= University::Person::Author.find(id)
def researcher
@researcher ||= University::Person::Researcher.find(id)
def teacher
@teacher ||= University::Person::Teacher.find(id)
administrator.for_website?(website) ||
author.for_website?(website) ||
researcher.for_website?(website) ||
teacher.for_website?(website)
def full_street_address
return nil if [address, zipcode, city].all?(&:blank?)
[address, "#{zipcode} #{city} #{country}".strip].join(', ')
end
def explicit_blob_ids
[picture&.blob_id]
end
def inherited_blob_ids
[best_picture&.blob_id]
end
self.email = self.email.to_s.downcase.strip
def permalink_config_key
:persons
end