Class: Decidim::Forms::AnswerQuestionnaire

Inherits:
Command
  • Object
show all
Includes:
MultipleAttachmentsMethods
Defined in:
app/commands/decidim/forms/answer_questionnaire.rb

Overview

This command is executed when the user answers a Questionnaire.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form, current_user, questionnaire) ⇒ AnswerQuestionnaire

Initializes a AnswerQuestionnaire Command.

form - The form from which to get the data. questionnaire - The current instance of the questionnaire to be answered.



13
14
15
16
17
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 13

def initialize(form, current_user, questionnaire)
  @form = form
  @current_user = current_user
  @questionnaire = questionnaire
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



35
36
37
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 35

def current_user
  @current_user
end

#formObject (readonly)

Returns the value of attribute form.



35
36
37
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 35

def form
  @form
end

#questionnaireObject (readonly)

Returns the value of attribute questionnaire.



35
36
37
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 35

def questionnaire
  @questionnaire
end

Instance Method Details

#callObject

Answers a questionnaire if it is valid

Broadcasts :ok if successful, :invalid otherwise.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/commands/decidim/forms/answer_questionnaire.rb', line 22

def call
  return broadcast(:invalid) if @form.invalid? || user_already_answered?

  answer_questionnaire

  if @errors
    reset_form_attachments
    broadcast(:invalid)
  else
    broadcast(:ok)
  end
end