diff --git a/app/models/communication/website/with_abouts.rb b/app/models/communication/website/with_abouts.rb index c8a45e40f238293d36da5636d060b389ee9e29a6..b1a0e40411b9de8f4e5019d77ae1dbf54b50f9bc 100644 --- a/app/models/communication/website/with_abouts.rb +++ b/app/models/communication/website/with_abouts.rb @@ -35,19 +35,27 @@ module Communication::Website::WithAbouts about_type == 'Education::School' end + def about_journal? + about_type == 'Research::Journal' + end + def programs about_school? ? about.programs : Education::Program.none end def people - @people ||= ( - posts.collect(&:author) + - posts.collect(&:author).map(&:author) + - programs.collect(&:university_people_through_teachers).flatten + - programs.collect(&:university_people_through_teachers).flatten.map(&:teacher) - # TODO administrative via roles - # TODO researchers via articles - ).uniq.compact + @people ||= begin + people = posts.collect(&:author) + posts.collect(&:author).compact.map(&:author) + if about_school? + people += programs.collect(&:university_people_through_teachers).flatten + people += programs.collect(&:university_people_through_teachers).flatten.map(&:teacher) + people += about.university_people_through_administrators + people += about.university_people_through_administrators.map(&:administrator) + elsif about_journal? + # TODO researchers via articles + end + end + people.uniq.compact end def set_programs_categories! diff --git a/app/models/education/school.rb b/app/models/education/school.rb index d8c002cd51519a7944be24c425f162646d0b624d..1bcdadf4ae0349d868949a1bd7208bda3153472d 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -27,8 +27,11 @@ class Education::School < ApplicationRecord include WithGit belongs_to :university - has_many :websites, class_name: 'Communication::Website', as: :about, dependent: :nullify - has_many :administrators, dependent: :destroy + has_many :websites, class_name: 'Communication::Website', as: :about, dependent: :nullify + has_many :administrators, dependent: :destroy + has_many :university_people_through_administrators, + through: :administrators, + source: :person has_and_belongs_to_many :programs, class_name: 'Education::Program', join_table: 'education_programs_schools', diff --git a/app/models/university/person.rb b/app/models/university/person.rb index ade0a167040ee9749f90e86bd39f33c2d90e7744..f9c448947ef9ad0e28dd7a302e4c8deffb37b16d 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -53,6 +53,10 @@ class University::Person < ApplicationRecord through: :education_program_teachers, source: :program + has_many :education_school_administrators, + class_name: 'Education::School::Administrator', + dependent: :destroy + has_many :communication_website_posts, class_name: 'Communication::Website::Post', foreign_key: :author_id, diff --git a/app/models/university/person/administrator.rb b/app/models/university/person/administrator.rb index 3ec4939783f9f5571ee8fa5e9dedb275eca20b93..6b54869f5a42562f71dbeee9ebbce79452da1711 100644 --- a/app/models/university/person/administrator.rb +++ b/app/models/university/person/administrator.rb @@ -37,7 +37,6 @@ class University::Person::Administrator < University::Person end def for_website?(website) - # TODO - is_administration + is_administration && website.about_school? && Education::School::Administrator.where(school_id: website.about_id, person_id: id).any? end end