Class: CustomerTopic

Inherits:
PartyTopic show all
Defined in:
app/models/customer_topic.rb

Overview

== Schema Information

Table name: party_topics
Database name: primary

id :integer not null, primary key
comments :text
due_on :datetime
follow_up :boolean
instruction_type :enum
position :integer
state :string(20)
state_created_at :datetime
type :string(20)
created_at :datetime not null
updated_at :datetime not null
course_category_id :integer
course_enrollment_id :integer
course_exam_id :integer
creator_id :integer
party_id :integer not null
survey_enrollment_id :integer
topic_id :integer not null
trainer_party_id :integer
updater_id :integer

Indexes

index_party_topic_enrollment_and_exam (party_id,topic_id,course_enrollment_id,course_exam_id)
index_party_topics_on_topic_id (topic_id)
index_party_topics_on_type (type)
party_topics_trainer_party_id_idx (trainer_party_id)

Foreign Keys

fk_rails_... (party_id => parties.id) ON DELETE => cascade
fk_rails_... (topic_id => topics.id) ON DELETE => cascade
fk_rails_... (trainer_party_id => parties.id) ON DELETE => nullify

Defined Under Namespace

Classes: MatrixBuilder

Constant Summary

Constants inherited from PartyTopic

PartyTopic::STATES

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Has and belongs to many collapse

Belongs to collapse

Methods inherited from PartyTopic

#party, #topic

Methods included from Models::Auditable

#creator, #updater

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PartyTopic

assigned, #complete, completed, in_progress, ongoing

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#choice_idObject

Returns the value of attribute choice_id.



55
56
57
# File 'app/models/customer_topic.rb', line 55

def choice_id
  @choice_id
end

#quiz_responseObject

Returns the value of attribute quiz_response.



55
56
57
# File 'app/models/customer_topic.rb', line 55

def quiz_response
  @quiz_response
end

Class Method Details

.create_communication(party, current_user) ⇒ Communication

This methods finds all the party which have a party topic marked for follow up and generate a communication
including all relevant snippets and uploads

Parameters:

Returns:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/models/customer_topic.rb', line 76

def self.create_communication(party, current_user)
  # Find all party topics requiring follow up
  follow_up_topics = party.party_topics.joins(:topic).where(follow_up: true)
  snippets = follow_up_topics.where.not(topics: { email_snippet: nil }).pluck(:email_snippet).join
  upload_ids = party.party_topics.where(follow_up: true).map { |pt| pt.topic.upload_ids }.flatten.uniq
  comm = CommunicationBuilder.new(sender_party: current_user,
                  recipient_party: party,
                  use_best_email: true,
                  template_system_code: 'TOPICFOLLOWUP',
                  upload_ids: upload_ids,
                  merge_options: { summary: snippets }).create(keep_as_draft: true)
  # Mark all topics as followed up
  follow_up_topics.update_all("follow_up = false, updater_id = #{current_user.id}, updated_at = '#{Time.current.to_fs(:db)}'")
  comm
end

.sortedActiveRecord::Relation<CustomerTopic>

A relation of CustomerTopics that are sorted. Active Record Scope

Returns:

See Also:



59
# File 'app/models/customer_topic.rb', line 59

scope :sorted, -> { order(:position) }

Instance Method Details

#course_categoryCourseCategory?

Returns:



45
# File 'app/models/customer_topic.rb', line 45

belongs_to :course_category, optional: true

#course_enrollmentCourseEnrollment?

Returns:



49
# File 'app/models/customer_topic.rb', line 49

belongs_to :course_enrollment, optional: true

#course_examCourseExam?

Returns:



47
# File 'app/models/customer_topic.rb', line 47

belongs_to :course_exam, optional: true

#email_snippetString

Returns:

  • (String)


67
68
69
# File 'app/models/customer_topic.rb', line 67

def email_snippet
  topic.email_snippet || topic.title
end

#follow_up_possible?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'app/models/customer_topic.rb', line 62

def follow_up_possible?
  true
end

#survey_enrollmentSurveyEnrollment?

Returns:



51
# File 'app/models/customer_topic.rb', line 51

belongs_to :survey_enrollment, optional: true

#topic_responsesActiveRecord::Relation<TopicResponse>

Returns:



43
# File 'app/models/customer_topic.rb', line 43

has_and_belongs_to_many :topic_responses, inverse_of: :customer_topics