Sha256: 74e88049963c591ec8390d19b4d09ddb2a8a473cd6176a6452f5e2328e72365b
Contents?: true
Size: 828 Bytes
Versions: 9
Compression:
Stored size: 828 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.where(questionnaire: @questionnaire) answers.sort_by { |answer| answer.question.position }.group_by(&:user).values end end end end
Version data entries
9 entries across 9 versions & 1 rubygems