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

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

Overview

Presenter for questionnaire response

Instance Method Summary collapse

Instance Method Details

#answered_atObject



20
21
22
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 20

def answered_at
  participant.created_at
end

#answersObject



34
35
36
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 34

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

#completionObject



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

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



38
39
40
41
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 38

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

#ip_hashObject



16
17
18
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 16

def ip_hash
  participant.ip_hash || "-"
end

#registered?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 26

def registered?
  participant.decidim_user_id.present?
end

#session_tokenObject



12
13
14
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 12

def session_token
  participant.session_token || "-"
end

#statusObject



30
31
32
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 30

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