Newer
Older
# == Schema Information
#
# Table name: communication_blocks
#
# id :uuid not null, primary key
# about_type :string indexed => [about_id]
# data :jsonb
# position :integer default(0), not null
# published :boolean default(TRUE)
# template_kind :integer default(NULL), not null
# title :string
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid indexed => [about_type]
# communication_website_id :uuid indexed
# heading_id :uuid indexed
# university_id :uuid not null, indexed
# index_communication_blocks_on_communication_website_id (communication_website_id)
# index_communication_blocks_on_heading_id (heading_id)
# index_communication_blocks_on_university_id (university_id)
# index_communication_website_blocks_on_about (about_type,about_id)
#
# Foreign Keys
#
# fk_rails_18291ef65f (university_id => universities.id)
# fk_rails_80e5625874 (communication_website_id => communication_websites.id)
# fk_rails_90ac986fab (heading_id => communication_block_headings.id)
belongs_to :communication_website,
class_name: "Communication::Website",
optional: true
alias :website :communication_website
# We do not use the :touch option of the belongs_to association
# because we do not want to touch the about when destroying the block.
# Les numéros sont un peu en vrac
# Dans l'idée, pour le futur
# 1000 basic
# 2000 storytelling
# 3000 references
# 4000 utilities
embed: 53,
features: 2010,
files: 55,
gallery: 300,
image: 51,
key_figures: 56,
license: 4040,
locations: 3200,
storytelling: [:key_figures, :features, :gallery, :call_to_action, :testimonials, :timeline],
references: [:pages, :posts, :persons, :organizations, :agenda, :programs, :locations, :projects, :papers, :volumes],
utilities: [:files, :definitions, :contact, :links, :license, :embed]
scope :published, -> { where(published: true) }
scope :without_heading, -> { where(heading: nil) }
before_validation :set_university_and_website_from_about, on: :create
# When we set data from json, we pass it to the template.
# The json we save is first sanitized and prepared by the template.
# Template data is clean and sanitized, and initialized with json
def language
return @language if defined?(@language)
@language ||= about.language
def duplicate
block = self.dup
block.save
block
end
def paste(about)
block = self.dup
block.about = about
block.heading = nil
block.save
block
end
def localize_for!(new_localization, localized_heading_id = nil)
localized_block = self.dup
localized_block.about = new_localization
localized_block.heading_id = localized_heading_id
localized_block.save
title.blank? ? "#{Communication::Block.model_name.human} #{position}"
protected
about.blocks.where(heading_id: heading_id).ordered.last
def set_university_and_website_from_about
# about always have an university_id but can have no communication_website_id
self.communication_website_id = about.try(:communication_website_id)
def check_accessibility
accessibility_merge template
end
# if a block changed we need to touch the old targets (for example persons previously connected), and the new connected ones
if persons? || organizations?
dependencies.each(&:touch)
# TODO: @arnaud help!
# I need to touch the old dependencies
# Ideally we should only touch the diff between old and new dependencies
end
end