Class: Decidim::Forms::Questionnaire

Inherits:
ApplicationRecord show all
Includes:
Publicable, Templates::Templatable, Traceable, TranslatableResource
Defined in:
app/models/decidim/forms/questionnaire.rb

Overview

The data store for a Questionnaire in the Decidim::Forms component.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#questionnaire_template_idObject

Returns the value of attribute questionnaire_template_id.



20
21
22
# File 'app/models/decidim/forms/questionnaire.rb', line 20

def questionnaire_template_id
  @questionnaire_template_id
end

Class Method Details

.log_presenter_class_for(_log) ⇒ Object



38
39
40
# File 'app/models/decidim/forms/questionnaire.rb', line 38

def self.log_presenter_class_for(_log)
  Decidim::Forms::AdminLog::QuestionnairePresenter
end

Instance Method Details

#answered_by?(user) ⇒ Boolean

Public: returns whether the questionnaire is answered by the user or not.

Returns:

  • (Boolean)


29
30
31
32
# File 'app/models/decidim/forms/questionnaire.rb', line 29

def answered_by?(user)
  query = user.is_a?(String) ? { session_token: user } : { user: }
  answers.where(query).any? if questions.present?
end

#pristine?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/decidim/forms/questionnaire.rb', line 34

def pristine?
  created_at.to_i == updated_at.to_i && questions.empty?
end

#questions_editable?Boolean

Public: returns whether the questionnaire questions can be modified or not.

Returns:

  • (Boolean)


23
24
25
26
# File 'app/models/decidim/forms/questionnaire.rb', line 23

def questions_editable?
  has_component = questionnaire_for.respond_to? :component
  (has_component && !questionnaire_for.component.published?) || answers.empty?
end