Class: Decidim::Forms::QuestionnaireParticipant

Inherits:
Query
  • Object
show all
Defined in:
app/queries/decidim/forms/questionnaire_participant.rb

Overview

A class used to collect user answers for a questionnaire

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(questionnaire, session_token) ⇒ QuestionnaireParticipant

Initializes the class.

questionnaire = a Questionnaire object session_token = the session_token used by the questionnaire participant



19
20
21
22
# File 'app/queries/decidim/forms/questionnaire_participant.rb', line 19

def initialize(questionnaire, session_token)
  @questionnaire = questionnaire
  @token = session_token
end

Class Method Details

.for(questionnaire, session_token) ⇒ Object

Syntactic sugar to initialize the class and return the queried objects.

questionnaire - a Questionnaire object session_token = the session_token used by the questionnaire participant



11
12
13
# File 'app/queries/decidim/forms/questionnaire_participant.rb', line 11

def self.for(questionnaire, session_token)
  new(questionnaire, session_token).query
end

Instance Method Details

#answersObject

Finds the participant’s answers.



30
31
32
# File 'app/queries/decidim/forms/questionnaire_participant.rb', line 30

def answers
  Answer.where(questionnaire: @questionnaire, session_token: @token)
end

#queryObject

Returns query with participant info



25
26
27
# File 'app/queries/decidim/forms/questionnaire_participant.rb', line 25

def query
  answers.select(:session_token, :decidim_user_id, :ip_hash).first
end