Class: Decidim::Forms::Admin::QuestionnaireParticipantPresenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Decidim::Forms::Admin::QuestionnaireParticipantPresenter
- Defined in:
- app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb
Overview
Presenter for questionnaire response
Instance Method Summary collapse
- #answered_at ⇒ Object
- #answers ⇒ Object
- #completion ⇒ Object
- #first_short_answer ⇒ Object
- #ip_hash ⇒ Object
- #participant ⇒ Object
- #registered? ⇒ Boolean
- #session_token ⇒ Object
- #status ⇒ Object
Instance Method Details
#answered_at ⇒ Object
22 23 24 |
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 22 def answered_at participant.created_at end |
#answers ⇒ Object
36 37 38 |
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 36 def answers siblings.map { |answer| QuestionnaireAnswerPresenter.new(answer:) } end |
#completion ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 45 def completion with_body = siblings.where(decidim_forms_questions: { question_type: %w(short_answer long_answer) }) .where.not(body: "").count with_choices = siblings.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_answer ⇒ Object
40 41 42 43 |
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 40 def first_short_answer short = siblings.where(decidim_forms_questions: { question_type: %w(short_answer) }) short.first end |
#ip_hash ⇒ Object
18 19 20 |
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 18 def ip_hash participant.ip_hash || "-" end |
#participant ⇒ Object
10 11 12 |
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 10 def participant __getobj__.fetch(:participant) end |
#registered? ⇒ Boolean
28 29 30 |
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 28 def registered? participant.decidim_user_id.present? end |
#session_token ⇒ Object
14 15 16 |
# File 'app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb', line 14 def session_token participant.session_token || "-" end |
#status ⇒ Object
32 33 34 |
# File '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 |