Newer
Older
# == Schema Information
#
# Table name: communication_website_pages
#
# id :uuid not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# language_id :uuid not null, indexed
# original_id :uuid indexed
# parent_id :uuid indexed
# university_id :uuid not null, indexed
#
# Indexes
#
# index_communication_website_pages_on_communication_website_id (communication_website_id)
# index_communication_website_pages_on_language_id (language_id)
# index_communication_website_pages_on_original_id (original_id)
# index_communication_website_pages_on_parent_id (parent_id)
# index_communication_website_pages_on_university_id (university_id)
#
# Foreign Keys
#
# fk_rails_1a42003f06 (parent_id => communication_website_pages.id)
# fk_rails_280107c62b (communication_website_id => communication_websites.id)
# fk_rails_304f57360f (original_id => communication_website_pages.id)
# fk_rails_d208d15a73 (university_id => universities.id)
# WithPath overwrite the git_path method defined in WithWebsites
include WithPath
has_summernote :text # TODO: Remove text attribute
belongs_to :parent,
class_name: 'Communication::Website::Page',
optional: true
belongs_to :original,
class_name: 'Communication::Website::Page',
optional: true
belongs_to :language
has_many :children,
class_name: 'Communication::Website::Page',
has_many :translations,
class_name: 'Communication::Website::Page',
foreign_key: :original_id
scope :for_search_term, -> (term) {
where("
unaccent(communication_website_pages.meta_description) ILIKE unaccent(:term) OR
unaccent(communication_website_pages.summary) ILIKE unaccent(:term) OR
unaccent(communication_website_pages.title) ILIKE unaccent(:term)
", term: "%#{sanitize_sql_like(term)}%")
}
scope :for_published, -> (published) { where(published: published == 'true') }
scope :for_full_width, -> (full_width) { where(full_width: full_width == 'true') }
def template_static
"admin/communication/websites/pages/static"
end
calculated_dependencies = active_storage_blobs + blocks
# children are used only if there is no block to display
def best_title
breadcrumb_title.blank? ? title : breadcrumb_title
end
def best_featured_image_source(fallback: true)
return self if featured_image.attached? || is_home? || parent&.is_home?
parent&.best_featured_image_source
end
def best_bodyclass
return bodyclass if bodyclass.present?
self.class.unscoped
.where(parent: parent, university: university, website: website)
.where.not(id: id)
website.pages.where(parent_id: parent_id, language_id: language_id).ordered.last
end
def inherited_blob_ids
[best_featured_image&.blob_id]
end
def abouts_with_page_block
website.blocks.pages.collect(&:about)
end