diff --git a/app/models/education/program/with_websites.rb b/app/models/education/program/with_websites.rb index a9b81dbe992889487e4afd02768f994c5a8ccb6f..6fe2a46406b1c3f1fbc793ee7d1dd4d220f0d9de 100644 --- a/app/models/education/program/with_websites.rb +++ b/app/models/education/program/with_websites.rb @@ -4,18 +4,29 @@ module Education::Program::WithWebsites included do attr_accessor :skip_websites_categories_callback - after_save_commit :set_websites_categories, unless: :skip_websites_categories_callback - - # FIXME incorrect, forgets websites about programs - has_many :websites, -> { distinct }, - through: :schools + after_save_commit :set_websites_categories, + unless: :skip_websites_categories_callback has_many :website_categories, class_name: 'Communication::Website::Category', dependent: :destroy end + def websites + @websites ||= university.websites.reject do |website| + website_concerned = false + # Site de formation + website_concerned = true if website.about == self + # Site d'école + if website.about&.is_a? Education::School + # Formation dispensée dans l'école + website_concerned = true if self.in? website.about.programs + end + !website_concerned + end + end + def set_websites_categories - websites.find_each(&:set_programs_categories!) + websites.each { |website| website.set_programs_categories! } end end diff --git a/db/schema.rb b/db/schema.rb index cfc5d60d161a43297dfe3a6aff25452b85d55d63..4b426c3cc8f5e1b21d319c0b7333f27962e6d60d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -504,6 +504,23 @@ ActiveRecord::Schema.define(version: 2022_06_09_085535) do t.index ["university_id"], name: "index_education_schools_on_university_id" end + create_table "external_organizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "title" + t.text "description" + t.string "address" + t.string "zipcode" + t.string "city" + t.string "country" + t.string "website" + t.string "phone" + t.string "mail" + t.boolean "active" + t.string "sirene" + t.integer "kind" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "imports", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.integer "number_of_lines" t.jsonb "processing_errors" @@ -698,8 +715,8 @@ ActiveRecord::Schema.define(version: 2022_06_09_085535) do t.string "linkedin" t.boolean "is_alumnus", default: false t.text "description_short" - t.boolean "is_author" t.string "name" + t.boolean "is_author" t.integer "gender" t.date "birthdate" t.string "phone_professional"