Class: CourseEnrollment
Overview
== Schema Information
Table name: course_enrollments
Database name: primary
id :bigint not null, primary key
completion_date :datetime
enrollment_date :datetime
passed_email_reminder_sent :boolean default(FALSE)
passed_email_reminder_sent_at :datetime
passed_email_sent :boolean default(FALSE)
passed_email_sent_at :datetime
reminder_1 :datetime
reminder_2 :datetime
reminder_3 :datetime
reminder_4 :datetime
state :string not null
created_at :datetime not null
updated_at :datetime not null
course_id :integer not null
party_id :integer not null
Indexes
index_course_enrollments_on_course_id (course_id)
Foreign Keys
fk_rails_... (course_id => courses.id)
Constant Summary
Models::Auditable::ALWAYS_IGNORED
#creator, #updater
Class Method Summary
collapse
Instance Method Summary
collapse
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
#publish_event
Class Method Details
.active ⇒ ActiveRecord::Relation<CourseEnrollment>
A relation of CourseEnrollments that are active. Active Record Scope
44
|
# File 'app/models/course_enrollment.rb', line 44
scope :active, -> { where(state: 'active') }
|
.for_course ⇒ ActiveRecord::Relation<CourseEnrollment>
A relation of CourseEnrollments that are for course. Active Record Scope
45
|
# File 'app/models/course_enrollment.rb', line 45
scope :for_course, -> (c){ where(course_id: c.id) }
|
.ready_to_certificate ⇒ ActiveRecord::Relation<CourseEnrollment>
A relation of CourseEnrollments that are ready to certificate. Active Record Scope
46
|
# File 'app/models/course_enrollment.rb', line 46
scope :ready_to_certificate, -> { left_outer_joins(:certification).where(state: :completed) }
|
Instance Method Details
120
121
122
|
# File 'app/models/course_enrollment.rb', line 120
def certificate_form_link
url = "#{WEB_URL}/my_account/course_enrollments/#{self.id}/certifications/new"
end
|
#certificate_not_requested? ⇒ Boolean
124
125
126
|
# File 'app/models/course_enrollment.rb', line 124
def certificate_not_requested?
return true unless certification.present?
end
|
40
|
# File 'app/models/course_enrollment.rb', line 40
has_one :certification
|
#completed? ⇒ Boolean
77
78
79
|
# File 'app/models/course_enrollment.rb', line 77
def completed?
state == 'completed'
end
|
#content_completed? ⇒ Boolean
90
91
92
|
# File 'app/models/course_enrollment.rb', line 90
def content_completed?
progress == 100
end
|
35
|
# File 'app/models/course_enrollment.rb', line 35
belongs_to :course, optional: true
|
#course_categories ⇒ ActiveRecord::Relation<CourseCategory>
38
|
# File 'app/models/course_enrollment.rb', line 38
has_many :course_categories, dependent: :delete_all
|
#course_exams ⇒ ActiveRecord::Relation<CourseExam>
37
|
# File 'app/models/course_enrollment.rb', line 37
has_many :course_exams, dependent: :delete_all
|
#course_title ⇒ Object
98
99
100
|
# File 'app/models/course_enrollment.rb', line 98
def course_title
course.name
end
|
#customer_topics ⇒ ActiveRecord::Relation<CustomerTopic>
39
|
# File 'app/models/course_enrollment.rb', line 39
has_many :customer_topics
|
#notify_failed_exam ⇒ Object
#notify_new_enrollment ⇒ Object
#notify_successful_exam ⇒ Object
36
|
# File 'app/models/course_enrollment.rb', line 36
belongs_to :party, optional: true, inverse_of: :course_enrollments
|
#passed? ⇒ Boolean
94
95
96
|
# File 'app/models/course_enrollment.rb', line 94
def passed?
self.state == 'completed' && self.course_exams.where(state: 'passed').present?
end
|
#percentage_progress ⇒ Object
73
74
75
|
# File 'app/models/course_enrollment.rb', line 73
def percentage_progress
"#{progress}%" if customer_topics.present?
end
|
#progress ⇒ Object
69
70
71
|
# File 'app/models/course_enrollment.rb', line 69
def progress
(customer_topics.completed.size * 100) / customer_topics.size if customer_topics.present?
end
|
#send_new_certificate_reminder_email ⇒ Object
111
112
113
114
115
116
117
118
|
# File 'app/models/course_enrollment.rb', line 111
def send_new_certificate_reminder_email
customer = self.party
com = CommunicationBuilder.new(resource: self,
recipient_party: customer,
use_best_email: true,
template_system_code: 'NEW_CERT_REMINDER').create
self.update(passed_email_reminder_sent: true, passed_email_reminder_sent_at: Time.current)
end
|
#send_passed_email ⇒ Object
102
103
104
105
106
107
108
109
|
# File 'app/models/course_enrollment.rb', line 102
def send_passed_email
customer = self.party
com = CommunicationBuilder.new(resource: self,
recipient_party: customer,
use_best_email: true,
template_system_code: 'COURSE_EXAM_PASSED').create
self.update(passed_email_sent: true, passed_email_sent_at: Time.current)
end
|
#send_progress_reminder(days) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'app/models/course_enrollment.rb', line 140
def send_progress_reminder(days)
customer = self.party
com = CommunicationBuilder.new(resource: self,
recipient_party: customer,
use_best_email: true,
template_system_code: 'CERT_PROGRESS').create
case days
when 30
self.update_columns(reminder_1: Time.current, reminder_2: nil, reminder_3: nil, reminder_4: nil)
when 60
self.update_columns(reminder_2: Time.current, reminder_3: nil, reminder_4: nil)
when 90
self.update_columns(reminder_3: Time.current, reminder_4: nil)
when 120
self.update_columns(reminder_4: Time.current)
end
end
|
#status ⇒ Object
81
82
83
84
85
86
87
88
|
# File 'app/models/course_enrollment.rb', line 81
def status
if completed?
"Completed"
else
"Ongoing - #{percentage_progress}"
end
end
|