diff --git a/app/admin/questions.rb b/app/admin/questions.rb index ec9415f41..cc4ba10b2 100644 --- a/app/admin/questions.rb +++ b/app/admin/questions.rb @@ -42,12 +42,12 @@ def erreur_import(error) def redirection_apres_import redirection_paths = { - 'QuestionClicDansImage' => admin_questions_clic_dans_image_path, - 'QuestionGlisserDeposer' => admin_questions_glisser_deposer_path, - 'QuestionQcm' => admin_question_qcms_path, - 'QuestionSaisie' => admin_questions_saisies_path, - 'QuestionSousConsigne' => admin_question_sous_consignes_path, - 'QuestionClicDansTexte' => admin_questions_clic_dans_texte_path + QuestionClicDansImage.TYPE => admin_questions_clic_dans_image_path, + QuestionGlisserDeposer.TYPE => admin_questions_glisser_deposer_path, + QuestionQcm.TYPE => admin_question_qcms_path, + QuestionSaisie.TYPE => admin_questions_saisies_path, + QuestionSousConsigne.TYPE => admin_question_sous_consignes_path, + QuestionClicDansTexte.TYPE => admin_questions_clic_dans_texte_path } redirection_paths[params[:type]] || admin_questions_path diff --git a/app/admin/questions_clic_dans_image.rb b/app/admin/questions_clic_dans_image.rb index 805a78f11..403f34eae 100644 --- a/app/admin/questions_clic_dans_image.rb +++ b/app/admin/questions_clic_dans_image.rb @@ -35,7 +35,7 @@ action_item :importer_question, only: :index do link_to 'Importer questions clic dans image', - admin_import_xls_path(type: 'QuestionClicDansImage') + admin_import_xls_path(type: QuestionClicDansImage.TYPE) end action_item :exporter_question, only: :show do diff --git a/app/admin/questions_clic_dans_texte.rb b/app/admin/questions_clic_dans_texte.rb index f5f399265..f22ccd531 100644 --- a/app/admin/questions_clic_dans_texte.rb +++ b/app/admin/questions_clic_dans_texte.rb @@ -16,7 +16,7 @@ action_item :importer_question, only: :index do link_to 'Importer questions Clic dans texte', - admin_import_xls_path(type: 'QuestionClicDansTexte') + admin_import_xls_path(type: QuestionClicDansTexte.TYPE) end action_item :exporter_question, only: :show do diff --git a/app/admin/questions_glisser_deposer.rb b/app/admin/questions_glisser_deposer.rb index 426cd9872..41d7b97ba 100644 --- a/app/admin/questions_glisser_deposer.rb +++ b/app/admin/questions_glisser_deposer.rb @@ -19,7 +19,7 @@ action_item :importer_question, only: :index do link_to 'Importer questions glisser déposer', - admin_import_xls_path(type: 'QuestionGlisserDeposer') + admin_import_xls_path(type: QuestionGlisserDeposer.TYPE) end action_item :exporter_question, only: :show do diff --git a/app/admin/questions_qcm.rb b/app/admin/questions_qcm.rb index 3b00c107a..730d93b9e 100644 --- a/app/admin/questions_qcm.rb +++ b/app/admin/questions_qcm.rb @@ -18,7 +18,7 @@ form partial: 'form' action_item :importer_question, only: :index do - link_to 'Importer questions QCM', admin_import_xls_path(type: 'QuestionQcm') + link_to 'Importer questions QCM', admin_import_xls_path(type: QuestionQcm.TYPE) end action_item :exporter_question, only: :show do diff --git a/app/admin/questions_saisie.rb b/app/admin/questions_saisie.rb index efdf9cd8b..7bf9552f0 100644 --- a/app/admin/questions_saisie.rb +++ b/app/admin/questions_saisie.rb @@ -16,7 +16,7 @@ filter :nom_technique action_item :importer_question, only: :index do - link_to 'Importer questions saisies', admin_import_xls_path(type: 'QuestionSaisie') + link_to 'Importer questions saisies', admin_import_xls_path(type: QuestionSaisie.TYPE) end action_item :exporter_question, only: :show do diff --git a/app/admin/questions_sous_consigne.rb b/app/admin/questions_sous_consigne.rb index c7415855a..5eecb80a1 100644 --- a/app/admin/questions_sous_consigne.rb +++ b/app/admin/questions_sous_consigne.rb @@ -11,7 +11,8 @@ filter :nom_technique action_item :importer_question, only: :index do - link_to 'Importer questions sous consigne', admin_import_xls_path(type: 'QuestionSousConsigne') + link_to 'Importer questions sous consigne', + admin_import_xls_path(type: QuestionSousConsigne.TYPE) end action_item :exporter_question, only: :show do diff --git a/app/models/import_export/questions/export.rb b/app/models/import_export/questions/export.rb index 11e601460..6361bb628 100644 --- a/app/models/import_export/questions/export.rb +++ b/app/models/import_export/questions/export.rb @@ -50,11 +50,11 @@ def remplis_champs_additionnels def remplis_champs_specifiques case @question.type - when 'QuestionClicDansImage' then remplis_champs_clic_dans_image - when 'QuestionGlisserDeposer' then remplis_champs_glisser_deposer + when QuestionClicDansImage.TYPE then remplis_champs_clic_dans_image + when QuestionGlisserDeposer.TYPE then remplis_champs_glisser_deposer when 'QuestionQcm' then remplis_champs_qcm - when 'QuestionSaisie' then remplis_champs_saisie - when 'QuestionClicDansTexte' then remplis_champs_clic_dans_texte + when QuestionSaisie.TYPE then remplis_champs_saisie + when QuestionClicDansTexte.TYPE then remplis_champs_clic_dans_texte end end diff --git a/app/models/import_export/questions/import.rb b/app/models/import_export/questions/import.rb index b090a82fa..829877656 100644 --- a/app/models/import_export/questions/import.rb +++ b/app/models/import_export/questions/import.rb @@ -55,11 +55,11 @@ def cree_transcription(categorie, audio_url, ecrit) def update_champs_specifiques updates = { - 'QuestionClicDansImage' => :update_clic_dans_image, - 'QuestionGlisserDeposer' => :update_glisser_deposer, - 'QuestionQcm' => :update_qcm, - 'QuestionSaisie' => :update_saisie, - 'QuestionClicDansTexte' => :update_clic_dans_texte + QuestionClicDansImage.TYPE => :update_clic_dans_image, + QuestionGlisserDeposer.TYPE => :update_glisser_deposer, + QuestionQcm.TYPE => :update_qcm, + QuestionSaisie.TYPE => :update_saisie, + QuestionClicDansTexte.TYPE => :update_clic_dans_texte } send(updates[@type]) if updates.key?(@type) end diff --git a/app/models/import_export/questions/import_export_donnees.rb b/app/models/import_export/questions/import_export_donnees.rb index 44f1a1fca..aab43d482 100644 --- a/app/models/import_export/questions/import_export_donnees.rb +++ b/app/models/import_export/questions/import_export_donnees.rb @@ -13,12 +13,12 @@ class ImportExportDonnees intitule_audio].freeze HEADERS_COMMUN = %i[libelle nom_technique illustration intitule_ecrit intitule_audio consigne_ecrit consigne_audio description].freeze - HEADERS_ATTENDUS = { 'QuestionClicDansImage' => HEADERS_COMMUN + HEADERS_CLIC_DANS_IMAGE, - 'QuestionClicDansTexte' => HEADERS_COMMUN + HEADERS_CLIC_DANS_TEXTE, - 'QuestionGlisserDeposer' => HEADERS_COMMUN + HEADERS_GLISSER_DEPOSER, - 'QuestionQcm' => HEADERS_COMMUN + HEADERS_QCM, - 'QuestionSaisie' => HEADERS_COMMUN + HEADERS_SAISIE, - 'QuestionSousConsigne' => HEADERS_SOUS_CONSIGNE }.freeze + HEADERS_ATTENDUS = { QuestionClicDansImage.TYPE => HEADERS_COMMUN + HEADERS_CLIC_DANS_IMAGE, + QuestionClicDansTexte.TYPE => HEADERS_COMMUN + HEADERS_CLIC_DANS_TEXTE, + QuestionGlisserDeposer.TYPE => HEADERS_COMMUN + HEADERS_GLISSER_DEPOSER, + QuestionQcm.TYPE => HEADERS_COMMUN + HEADERS_QCM, + QuestionSaisie.TYPE => HEADERS_COMMUN + HEADERS_SAISIE, + QuestionSousConsigne.TYPE => HEADERS_SOUS_CONSIGNE }.freeze def initialize(questions: nil, type: nil) @questions = questions diff --git a/app/models/question.rb b/app/models/question.rb index 63b75113e..373126188 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -28,12 +28,12 @@ class Question < ApplicationRecord CATEGORIE = %i[situation scolarite sante appareils].freeze AUDIO_TYPES = %i[intitule modalite_reponse consigne].freeze INTERACTION_TYPES = { - 'QuestionQcm' => 'qcm', - 'QuestionClicDansImage' => 'clic dans image', - 'QuestionGlisserDeposer' => 'glisser deposer', - 'QuestionSousConsigne' => 'sous consigne', - 'QuestionSaisie' => 'saisie', - 'QuestionClicDansTexte' => 'clic dans texte' + QuestionQcm.TYPE => 'qcm', + QuestionClicDansImage.TYPE => 'clic dans image', + QuestionGlisserDeposer.TYPE => 'glisser deposer', + QuestionSousConsigne.TYPE => 'sous consigne', + QuestionSaisie.TYPE => 'saisie', + QuestionClicDansTexte.TYPE => 'clic dans texte' }.freeze enum :categorie, CATEGORIE.zip(CATEGORIE.map(&:to_s)).to_h, prefix: true @@ -84,15 +84,15 @@ def interaction end def saisie? - type == 'QuestionSaisie' + type == QuestionSaisie.TYPE end def qcm? - type == 'QuestionQcm' + type == QuestionQcm.TYPE end def sous_consigne? - type == 'QuestionSousConsigne' + type == QuestionSousConsigne.TYPE end private diff --git a/app/models/question_clic_dans_image.rb b/app/models/question_clic_dans_image.rb index 5822bacff..a8f71f40c 100644 --- a/app/models/question_clic_dans_image.rb +++ b/app/models/question_clic_dans_image.rb @@ -2,6 +2,7 @@ class QuestionClicDansImage < Question CLASS_BONNE_REPONSE = 'bonne-reponse' + TYPE = 'QuestionClicDansImage' has_one_attached :zone_cliquable has_one_attached :image_au_clic diff --git a/app/models/question_clic_dans_texte.rb b/app/models/question_clic_dans_texte.rb index ee1af5e73..f930977b3 100644 --- a/app/models/question_clic_dans_texte.rb +++ b/app/models/question_clic_dans_texte.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class QuestionClicDansTexte < Question - # validates :texte_sur_illustration, presence: true + TYPE = 'QuestionClicDansTexte' def as_json(_options = nil) base_json diff --git a/app/models/question_glisser_deposer.rb b/app/models/question_glisser_deposer.rb index 3c73487b6..a9fe93aea 100644 --- a/app/models/question_glisser_deposer.rb +++ b/app/models/question_glisser_deposer.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class QuestionGlisserDeposer < Question + TYPE = 'QuestionGlisserDeposer' has_many :reponses, -> { order(position: :asc) }, foreign_key: :question_id, class_name: 'Choix', diff --git a/app/models/question_qcm.rb b/app/models/question_qcm.rb index fd21f6bcb..bc4915ee5 100644 --- a/app/models/question_qcm.rb +++ b/app/models/question_qcm.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class QuestionQcm < Question + TYPE = 'QuestionQcm' enum :metacompetence, { numeratie: 0, ccf: 1, 'syntaxe-orthographe': 2 } enum :type_qcm, { standard: 0, jauge: 1 } has_many :choix, lambda { diff --git a/app/models/question_saisie.rb b/app/models/question_saisie.rb index 058963794..ccb02f20a 100644 --- a/app/models/question_saisie.rb +++ b/app/models/question_saisie.rb @@ -2,6 +2,8 @@ class QuestionSaisie < Question QUESTION_REDACTION = 'redaction_note' + TYPE = 'QuestionSaisie' + enum :type_saisie, { redaction: 0, numerique: 1 } has_one :bonne_reponse, class_name: 'Choix', foreign_key: :question_id, dependent: :destroy diff --git a/app/models/question_sous_consigne.rb b/app/models/question_sous_consigne.rb index 43587a75e..9fb2489b5 100644 --- a/app/models/question_sous_consigne.rb +++ b/app/models/question_sous_consigne.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class QuestionSousConsigne < Question + TYPE = 'QuestionSousConsigne' + def as_json(_options = nil) json = slice(:id, :nom_technique) json['type'] = 'sous-consigne' diff --git a/app/models/restitution/questions_reponses.rb b/app/models/restitution/questions_reponses.rb index 00f51618e..03479a847 100644 --- a/app/models/restitution/questions_reponses.rb +++ b/app/models/restitution/questions_reponses.rb @@ -32,8 +32,8 @@ def choix_repondu(question, evenement_reponse) def questions_repondues questions_ids = reponses.collect { |r| r.donnees['question'] } - Question.where(id: questions_ids, type: 'QuestionQcm').includes(:choix) + - Question.where(id: questions_ids).where.not(type: 'QuestionQcm') + Question.where(id: questions_ids, type: QuestionQcm.TYPE).includes(:choix) + + Question.where(id: questions_ids).where.not(type: QuestionQcm.TYPE) end end end