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 :integer
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

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, exams, for_topic_category, in_progress, no_exams, 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::EventPublishable

#publish_event

Instance Attribute Details

#choice_idObject

Returns the value of attribute choice_id.



52
53
54
# File 'app/models/customer_topic.rb', line 52

def choice_id
  @choice_id
end

#quiz_responseObject

Returns the value of attribute quiz_response.



52
53
54
# File 'app/models/customer_topic.rb', line 52

def quiz_response
  @quiz_response
end

Class Method Details

.create_communication(party, current_user) ⇒ Object

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



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/customer_topic.rb', line 68

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('topics.email_snippet IS NOT NULL').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:



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

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

Instance Method Details

#course_categoryCourseCategory



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

belongs_to :course_category, optional: true

#course_enrollmentCourseEnrollment



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

belongs_to :course_enrollment, optional: true

#course_examCourseExam

Returns:

See Also:



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

belongs_to :course_exam, optional: true

#email_snippetObject



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

def email_snippet
  topic.email_snippet || topic.title
end

#follow_up_possible?Boolean

Returns:

  • (Boolean)


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

def follow_up_possible?
  true
end

#survey_enrollmentSurveyEnrollment



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

belongs_to :survey_enrollment, optional: true

#topic_categoryTopicCategory



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

belongs_to :topic_category, optional: true

#topic_examTopicExam

Returns:

See Also:



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

belongs_to :topic_exam, optional: true

#topic_responsesActiveRecord::Relation<TopicResponse>

Returns:

See Also:



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

has_and_belongs_to_many :topic_responses, inverse_of: :customer_topics