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