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
Constants included
from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
#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
config
#after_commit
#publish_event
Class Method Details
.active ⇒ ActiveRecord::Relation<CourseEnrollment>
A relation of CourseEnrollments that are active. Active Record Scope
45
|
# File 'app/models/course_enrollment.rb', line 45
scope :active, -> { where(state: 'active') }
|
.for_course ⇒ ActiveRecord::Relation<CourseEnrollment>
A relation of CourseEnrollments that are for course. Active Record Scope
46
|
# File 'app/models/course_enrollment.rb', line 46
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
47
|
# File 'app/models/course_enrollment.rb', line 47
scope :ready_to_certificate, -> { left_outer_joins(:certification).where(state: :completed) }
|
Instance Method Details
121
122
123
|
# File 'app/models/course_enrollment.rb', line 121
def certificate_form_link
"#{WEB_URL}/my_account/course_enrollments/#{id}/certifications/new"
end
|
#certificate_not_requested? ⇒ Boolean
125
126
127
|
# File 'app/models/course_enrollment.rb', line 125
def certificate_not_requested?
true if certification.blank?
end
|
41
|
# File 'app/models/course_enrollment.rb', line 41
has_one :certification
|
#completed? ⇒ Boolean
78
79
80
|
# File 'app/models/course_enrollment.rb', line 78
def completed?
state == 'completed'
end
|
#content_completed? ⇒ Boolean
91
92
93
|
# File 'app/models/course_enrollment.rb', line 91
def content_completed?
progress == 100
end
|
36
|
# File 'app/models/course_enrollment.rb', line 36
belongs_to :course, optional: true
|
#course_categories ⇒ ActiveRecord::Relation<CourseCategory>
39
|
# File 'app/models/course_enrollment.rb', line 39
has_many :course_categories, dependent: :delete_all
|
#course_exams ⇒ ActiveRecord::Relation<CourseExam>
38
|
# File 'app/models/course_enrollment.rb', line 38
has_many :course_exams, dependent: :delete_all
|
#course_title ⇒ Object
99
100
101
|
# File 'app/models/course_enrollment.rb', line 99
def course_title
course.name
end
|
#customer_topics ⇒ ActiveRecord::Relation<CustomerTopic>
40
|
# File 'app/models/course_enrollment.rb', line 40
has_many :customer_topics
|
#notify_failed_exam ⇒ Object
#notify_new_enrollment ⇒ Object
#notify_successful_exam ⇒ Object
37
|
# File 'app/models/course_enrollment.rb', line 37
belongs_to :party, optional: true, inverse_of: :course_enrollments
|
#passed? ⇒ Boolean
95
96
97
|
# File 'app/models/course_enrollment.rb', line 95
def passed?
state == 'completed' && course_exams.where(state: 'passed').present?
end
|
#percentage_progress ⇒ Object
74
75
76
|
# File 'app/models/course_enrollment.rb', line 74
def percentage_progress
"#{progress}%" if customer_topics.present?
end
|
#progress ⇒ Object
70
71
72
|
# File 'app/models/course_enrollment.rb', line 70
def progress
(customer_topics.completed.size * 100) / customer_topics.size if customer_topics.present?
end
|
#send_new_certificate_reminder_email ⇒ Object
112
113
114
115
116
117
118
119
|
# File 'app/models/course_enrollment.rb', line 112
def send_new_certificate_reminder_email
customer = party
CommunicationBuilder.new(resource: self,
recipient_party: customer,
use_best_email: true,
template_system_code: 'NEW_CERT_REMINDER').create
update(passed_email_reminder_sent: true, passed_email_reminder_sent_at: Time.current)
end
|
#send_passed_email ⇒ Object
103
104
105
106
107
108
109
110
|
# File 'app/models/course_enrollment.rb', line 103
def send_passed_email
customer = party
CommunicationBuilder.new(resource: self,
recipient_party: customer,
use_best_email: true,
template_system_code: 'COURSE_EXAM_PASSED').create
update(passed_email_sent: true, passed_email_sent_at: Time.current)
end
|
#send_progress_reminder(days) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'app/models/course_enrollment.rb', line 141
def send_progress_reminder(days)
customer = party
CommunicationBuilder.new(resource: self,
recipient_party: customer,
use_best_email: true,
template_system_code: 'CERT_PROGRESS').create
case days
when 30
update_columns(reminder_1: Time.current, reminder_2: nil, reminder_3: nil, reminder_4: nil)
when 60
update_columns(reminder_2: Time.current, reminder_3: nil, reminder_4: nil)
when 90
update_columns(reminder_3: Time.current, reminder_4: nil)
when 120
update_columns(reminder_4: Time.current)
end
end
|
#status ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'app/models/course_enrollment.rb', line 82
def status
if completed?
"Completed"
else
"Ongoing - #{percentage_progress}"
end
end
|