Class: SurveyEnrollment
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- SurveyEnrollment
- Defined in:
- app/models/survey_enrollment.rb
Overview
== Schema Information
Table name: survey_enrollments
Database name: primary
id :bigint not null, primary key
enrollment_date :datetime
state :string not null
employee_id :integer
party_id :integer not null
review_id :integer
survey_id :integer not null
Indexes
index_survey_enrollments_on_survey_id (survey_id)
Foreign Keys
fk_rails_... (survey_id => surveys.id)
Constant Summary
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Belongs to collapse
Has many collapse
- #customer_topics ⇒ ActiveRecord::Relation<CustomerTopic>
- #employee_survey_enrollments ⇒ ActiveRecord::Relation<EmployeeSurveyEnrollment>
- #employees ⇒ ActiveRecord::Relation<Employee>
Instance Method Summary collapse
- #completed? ⇒ Boolean
- #content_completed? ⇒ Boolean
- #has_answers? ⇒ Boolean
- #percentage_progress ⇒ void
- #progress ⇒ void
- #status ⇒ void
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Method Details
#completed? ⇒ Boolean
48 49 50 |
# File 'app/models/survey_enrollment.rb', line 48 def completed? state == 'completed' end |
#content_completed? ⇒ Boolean
68 69 70 |
# File 'app/models/survey_enrollment.rb', line 68 def content_completed? progress == 100 end |
#customer_topics ⇒ ActiveRecord::Relation<CustomerTopic>
29 |
# File 'app/models/survey_enrollment.rb', line 29 has_many :customer_topics |
#employee_survey_enrollments ⇒ ActiveRecord::Relation<EmployeeSurveyEnrollment>
31 |
# File 'app/models/survey_enrollment.rb', line 31 has_many :employee_survey_enrollments, dependent: :destroy |
#employees ⇒ ActiveRecord::Relation<Employee>
33 |
# File 'app/models/survey_enrollment.rb', line 33 has_many :employees, through: :employee_survey_enrollments |
#has_answers? ⇒ Boolean
63 64 65 |
# File 'app/models/survey_enrollment.rb', line 63 def has_answers? customer_topics.joins(:topic_responses).present? || customer_topics.where.not(comments: nil).present? end |
#party ⇒ Party?
26 |
# File 'app/models/survey_enrollment.rb', line 26 belongs_to :party, optional: true, inverse_of: :survey_enrollments |
#percentage_progress ⇒ void
This method returns an undefined value.
43 44 45 |
# File 'app/models/survey_enrollment.rb', line 43 def percentage_progress "#{progress}%" if customer_topics.present? end |
#progress ⇒ void
This method returns an undefined value.
38 39 40 |
# File 'app/models/survey_enrollment.rb', line 38 def progress (customer_topics.completed.size * 100) / customer_topics.size if customer_topics.present? end |
#status ⇒ void
This method returns an undefined value.
53 54 55 56 57 58 59 60 |
# File 'app/models/survey_enrollment.rb', line 53 def status if completed? "Completed" else "Ongoing - #{percentage_progress}" end # There could also be state "renewed" or "expired" end |
#survey ⇒ Survey?
24 |
# File 'app/models/survey_enrollment.rb', line 24 belongs_to :survey, optional: true |