Sha256: f78c5676fd9a784b50c048bff2a6f948756d987fd0517748362eba5078facfa6

Contents?: true

Size: 987 Bytes

Versions: 25

Compression:

Stored size: 987 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Forms
    # A class used to collect user answers for a questionnaire
    class QuestionnaireUserAnswers < Decidim::Query
      # Syntactic sugar to initialize the class and return the queried objects.
      #
      # questionnaire - a Questionnaire object
      def self.for(questionnaire)
        new(questionnaire).query
      end

      # Initializes the class.
      #
      # questionnaire = a Questionnaire object
      def initialize(questionnaire)
        @questionnaire = questionnaire
      end

      # Finds and group answers by user for each questionnaire's question.
      def query
        answers = Answer.not_separator
                        .not_title_and_description
                        .joins(:question)
                        .where(questionnaire: @questionnaire)

        answers.sort_by { |answer| answer.question.position }.group_by { |a| a.user || a.session_token }.values
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-forms-0.29.1 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.28.4 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.27.9 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.29.0 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.28.3 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.27.8 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.29.0.rc4 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.29.0.rc3 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.29.0.rc2 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.29.0.rc1 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.28.2 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.27.7 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.28.1 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.27.6 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.28.0 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.27.5 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.28.0.rc5 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.28.0.rc4 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.27.4 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.27.3 app/queries/decidim/forms/questionnaire_user_answers.rb