Class: Decidim::Forms::Admin::QuestionnaireParticipantPresenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
decidim-forms/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb

Overview

Presenter for questionnaire response

Instance Method Summary collapse

Instance Method Details

#answered_atObject


22
23
24
# File 'decidim-forms/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 22

def answered_at
  participant.created_at
end

#answersObject


36
37
38
# File 'decidim-forms/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 36

def answers
  sibilings.map { |answer| QuestionnaireAnswerPresenter.new(answer: answer) }
end

#completionObject


45
46
47
48
49
50
51
52
# File 'decidim-forms/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 45

def completion
  with_body = sibilings.where(decidim_forms_questions: { question_type: %w(short_answer long_answer) })
                       .where.not(body: "").count
  with_choices = sibilings.where.not("decidim_forms_questions.question_type in (?)", %w(short_answer long_answer))
                          .where("decidim_forms_answers.id IN (SELECT decidim_answer_id FROM decidim_forms_answer_choices)").count

  (with_body + with_choices).to_f / questionnaire.questions.not_separator.not_title_and_description.count * 100
end

#first_short_answerObject


40
41
42
43
# File 'decidim-forms/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 40

def first_short_answer
  short = sibilings.where(decidim_forms_questions: { question_type: %w(short_answer) })
  short.first
end

#ip_hashObject


18
19
20
# File 'decidim-forms/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 18

def ip_hash
  participant.ip_hash || "-"
end

#participantObject


10
11
12
# File 'decidim-forms/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 10

def participant
  __getobj__.fetch(:participant)
end

#registered?Boolean

Returns:

  • (Boolean)

28
29
30
# File 'decidim-forms/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 28

def registered?
  participant.decidim_user_id.present?
end

#session_tokenObject


14
15
16
# File 'decidim-forms/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 14

def session_token
  participant.session_token || "-"
end

#statusObject


32
33
34
# File 'decidim-forms/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 32

def status
  I18n.t(registered? ? "registered" : "unregistered", scope: "decidim.forms.user_answers_serializer")
end