Newer
Older
# featured_image_alt :string
# level :integer
# name :string
# objectives :text
# opportunities :text
# other :text
# slug :string
# created_at :datetime not null
# updated_at :datetime not null
# parent_id :uuid indexed
# university_id :uuid not null, indexed
# fk_rails_ec1f16f607 (parent_id => education_programs.id)
include WithFeaturedImage
include WithBlobs
rich_text_areas_with_inheritance :accessibility,
:contacts,
:duration,
:evaluation,
:objectives,
:opportunities,
:other,
:pedagogy,
:prerequisites,
:pricing,
belongs_to :parent,
class_name: 'Education::Program',
optional: true
has_many :children,
class_name: 'Education::Program',
foreign_key: :parent_id,
has_many :university_roles,
class_name: 'University::Role',
as: :target,
dependent: :destroy
has_many :involvements_through_roles,
through: :university_roles,
source: :involvements
has_many :university_people_through_role_involvements,
through: :involvements_through_roles,
source: :person
has_many :university_person_involvements,
class_name: 'University::Person::Involvement',
as: :target,
has_many :university_people_through_involvements,
through: :university_person_involvements,
source: :person
has_many :website_categories,
class_name: 'Communication::Website::Category',
dependent: :destroy
has_and_belongs_to_many :schools,
class_name: 'Education::School',
join_table: 'education_programs_schools',
foreign_key: 'education_program_id',
association_foreign_key: 'education_school_id'
accepts_nested_attributes_for :university_person_involvements, reject_if: :all_blank, allow_destroy: true
bachelor: 300,
master: 500,
doctor: 800
}
validates_presence_of :name
after_save :update_children_paths, if: :saved_change_to_path?
after_save_commit :set_websites_categories, unless: :skip_websites_categories_callback
scope :published, -> { where(published: true) }
def best_featured_image(fallback: true)
return featured_image if featured_image.attached?
best_image = parent&.best_featured_image(fallback: false)
best_image ||= featured_image if fallback
best_image
end
def git_dependencies(website)
[self] +
active_storage_blobs +
university_people_through_involvements.map(&:active_storage_blobs).flatten +
university_people_through_involvements.map(&:teacher) +
university_people_through_role_involvements +
university_people_through_role_involvements.map(&:active_storage_blobs).flatten +
university_people_through_role_involvements.map(&:administrator) +
website.menus
def git_destroy_dependencies(website)
[self] +
children.each do |child|
child.update_column :path, child.generated_path
child.update_children_paths
end
university.education_programs.where(parent_id: parent_id).ordered.last
end
def inherited_blob_ids
[best_featured_image&.blob_id]
end