Sha256: 577ebdf7bca7e8fac3544299abb866f1612d39c1134ed182b6e130f2baaa8d84

Contents?: true

Size: 886 Bytes

Versions: 13

Compression:

Stored size: 886 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Forms
    # A class used to collect user answers for a questionnaire
    class QuestionnaireUserAnswers < Rectify::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.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

13 entries across 13 versions & 1 rubygems

Version Path
decidim-forms-0.25.2 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.25.1 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.25.0 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.25.0.rc4 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.25.0.rc3 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.25.0.rc2 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.25.0.rc1 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.24.3 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.24.2 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.24.1 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.24.0 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.24.0.rc2 app/queries/decidim/forms/questionnaire_user_answers.rb
decidim-forms-0.24.0.rc1 app/queries/decidim/forms/questionnaire_user_answers.rb