effective_learndash 0.1.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/app/assets/config/effective_learndash_manifest.js +0 -1
- data/app/controllers/admin/course_registrations_controller.rb +8 -0
- data/app/controllers/effective/course_registrations_controller.rb +13 -0
- data/app/controllers/effective/learndash_courses_controller.rb +32 -0
- data/app/datatables/admin/effective_course_registrations_datatable.rb +28 -0
- data/app/datatables/admin/effective_learndash_courses_datatable.rb +4 -0
- data/app/datatables/admin/effective_learndash_enrollments_datatable.rb +1 -2
- data/app/datatables/effective_course_registrants_datatable.rb +24 -0
- data/app/datatables/effective_course_registrations_datatable.rb +35 -0
- data/app/datatables/effective_learndash_courses_datatable.rb +28 -0
- data/app/datatables/effective_learndash_enrollments_datatable.rb +15 -1
- data/app/models/concerns/effective_learndash_course_registration.rb +167 -0
- data/app/models/concerns/effective_learndash_owner.rb +1 -1
- data/app/models/effective/course_registrant.rb +53 -0
- data/app/models/effective/course_registration.rb +5 -0
- data/app/models/effective/learndash_api.rb +10 -1
- data/app/models/effective/learndash_course.rb +78 -3
- data/app/models/effective/learndash_enrollment.rb +15 -3
- data/app/models/effective/learndash_user.rb +5 -6
- data/app/views/admin/learndash_courses/_form.html.haml +25 -0
- data/app/views/admin/learndash_courses/_form_course_registration_content.html.haml +19 -0
- data/app/views/admin/learndash_courses/_form_learndash_course.html.haml +32 -0
- data/app/views/effective/course_registrations/_content.html.haml +10 -0
- data/app/views/effective/course_registrations/_course.html.haml +9 -0
- data/app/views/effective/course_registrations/_course_registration.html.haml +3 -0
- data/app/views/effective/course_registrations/_dashboard.html.haml +30 -0
- data/app/views/effective/course_registrations/_layout.html.haml +3 -0
- data/app/views/effective/course_registrations/_orders.html.haml +4 -0
- data/app/views/effective/course_registrations/_summary.html.haml +35 -0
- data/app/views/effective/course_registrations/billing.html.haml +15 -0
- data/app/views/effective/course_registrations/checkout.html.haml +6 -0
- data/app/views/effective/course_registrations/course.html.haml +21 -0
- data/app/views/effective/course_registrations/start.html.haml +24 -0
- data/app/views/effective/course_registrations/submitted.html.haml +16 -0
- data/app/views/effective/course_registrations/summary.html.haml +8 -0
- data/app/views/effective/learndash/_dashboard.html.haml +8 -5
- data/app/views/effective/learndash_courses/_learndash_course.html.haml +13 -0
- data/app/views/effective/learndash_courses/index.html.haml +5 -0
- data/app/views/effective/learndash_courses/show.html.haml +6 -0
- data/config/effective_learndash.rb +9 -0
- data/config/routes.rb +13 -3
- data/db/migrate/01_create_effective_learndash.rb.erb +98 -33
- data/lib/effective_learndash/engine.rb +1 -0
- data/lib/effective_learndash/version.rb +1 -1
- data/lib/effective_learndash.rb +6 -1
- data/lib/generators/effective_learndash/install_generator.rb +0 -1
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83cc9e6d5daa0a6e08e491f1ea9edec7f8e394b045801a2d704eaacab5c93f18
|
4
|
+
data.tar.gz: 467de056d4e11255c927a212e0f893b54ddcac8720ec12bf80299873ff5e2910
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cbb48faa89c8d2a6fee3f47b78cdb41f3cf20871b354f7e88852a5103e0a294d4b2dd1d2eca63be1525dd546e365fd8143416e35942d714039ecd6031a12a0c
|
7
|
+
data.tar.gz: ee47891e98f74e0c8ecdbacbd76f37071a16d95a347bca7014f421a4aeb007b7ffc92d0f96c080dea39c8d57b15b92aa83f06f5558a0ee2182049dfa442952c0
|
data/README.md
CHANGED
@@ -71,6 +71,15 @@ All authorization checks are handled via the effective_resources gem found in th
|
|
71
71
|
The permissions you actually want to define are as follows (using CanCan):
|
72
72
|
|
73
73
|
```ruby
|
74
|
+
can(:show, Effective::LearndashUser) { |lduser| lduser.owner_id == user.id }
|
75
|
+
can(:index, Effective::LearndashEnrollment)
|
76
|
+
|
77
|
+
can([:index, :show], Effective::LearndashCourse) { |course| !course.draft? }
|
78
|
+
can([:show, :index], Effective::CourseRegistrant) { |registrant| registrant.owner == user || registrant.owner.blank? }
|
79
|
+
can([:new, :create], EffectiveLearndash.CourseRegistration)
|
80
|
+
can([:show, :index], EffectiveLearndash.CourseRegistration) { |registration| registration.owner == user }
|
81
|
+
can([:update, :destroy], EffectiveLearndash.CourseRegistration) { |registration| registration.owner == user && !registration.was_submitted? }
|
82
|
+
|
74
83
|
if user.admin?
|
75
84
|
can :admin, :effective_learndash
|
76
85
|
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module Admin
|
2
|
+
class CourseRegistrationsController < ApplicationController
|
3
|
+
before_action(:authenticate_user!) if defined?(Devise)
|
4
|
+
before_action { EffectiveResources.authorize!(self, :admin, :effective_learndash) }
|
5
|
+
|
6
|
+
include Effective::CrudController
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Effective
|
2
|
+
class CourseRegistrationsController < ApplicationController
|
3
|
+
before_action(:authenticate_user!) if defined?(Devise)
|
4
|
+
|
5
|
+
include Effective::WizardController
|
6
|
+
|
7
|
+
resource_scope -> {
|
8
|
+
learndash_course = Effective::LearndashCourse.find(params[:learndash_course_id])
|
9
|
+
EffectiveLearndash.CourseRegistration.deep.where(owner: current_user, learndash_course: learndash_course)
|
10
|
+
}
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Effective
|
2
|
+
class LearndashCoursesController < ApplicationController
|
3
|
+
include Effective::CrudController
|
4
|
+
|
5
|
+
resource_scope -> {
|
6
|
+
unpublished = EffectiveResources.authorized?(self, :admin, :effective_learndash)
|
7
|
+
Effective::LearndashCourse.learndash_courses(user: current_user, unpublished: unpublished)
|
8
|
+
}
|
9
|
+
|
10
|
+
def show
|
11
|
+
@learndash_course = resource_scope.find(params[:id])
|
12
|
+
|
13
|
+
if @learndash_course.respond_to?(:roles_permit?)
|
14
|
+
raise Effective::AccessDenied.new('Access Denied', :show, @learndash_course) unless @learndash_course.roles_permit?(current_user)
|
15
|
+
end
|
16
|
+
|
17
|
+
EffectiveResources.authorize!(self, :show, @learndash_course)
|
18
|
+
|
19
|
+
if EffectiveResources.authorized?(self, :admin, :effective_learndash)
|
20
|
+
flash.now[:warning] = [
|
21
|
+
'Hi Admin!',
|
22
|
+
('You are viewing a hidden course.' if @learndash_course.draft?),
|
23
|
+
'Click here to',
|
24
|
+
("<a href='#{effective_learndash.edit_admin_learndash_course_path(@learndash_course)}' class='alert-link'>edit learndash course settings</a>.")
|
25
|
+
].compact.join(' ')
|
26
|
+
end
|
27
|
+
|
28
|
+
@page_title ||= @learndash_course.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Admin
|
2
|
+
class EffectiveCourseRegistrationsDatatable < Effective::Datatable
|
3
|
+
datatable do
|
4
|
+
col :updated_at, visible: false
|
5
|
+
col :created_at, visible: false
|
6
|
+
col :id, visible: false
|
7
|
+
|
8
|
+
col :token, visible: false
|
9
|
+
|
10
|
+
col :created_at, label: 'Created', visible: false
|
11
|
+
col :updated_at, label: 'Updated', visible: false
|
12
|
+
col :submitted_at, label: 'Submitted', visible: false, as: :date
|
13
|
+
|
14
|
+
col :learndash_course
|
15
|
+
col :owner
|
16
|
+
|
17
|
+
col :course_registrants, search: :string, visible: false
|
18
|
+
col :orders, label: 'Order'
|
19
|
+
|
20
|
+
actions_col
|
21
|
+
end
|
22
|
+
|
23
|
+
collection do
|
24
|
+
scope = EffectiveLearndash.CourseRegistration.all.deep.done
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Used on the Course Registrations courses step
|
2
|
+
|
3
|
+
class EffectiveCourseRegistrantsDatatable < Effective::Datatable
|
4
|
+
datatable do
|
5
|
+
col :learndash_course
|
6
|
+
col :owner, label: 'User', action: false
|
7
|
+
col :price, as: :price
|
8
|
+
end
|
9
|
+
|
10
|
+
collection do
|
11
|
+
scope = Effective::CourseRegistrant.deep.all
|
12
|
+
|
13
|
+
if attributes[:learndash_course_id].present?
|
14
|
+
scope = scope.where(learndash_course_id: attributes[:learndash_course_id])
|
15
|
+
end
|
16
|
+
|
17
|
+
if attributes[:course_registration_id].present?
|
18
|
+
scope = scope.where(course_registration_id: attributes[:course_registration_id])
|
19
|
+
end
|
20
|
+
|
21
|
+
scope
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Dashboard Course Registrations
|
2
|
+
class EffectiveCourseRegistrationsDatatable < Effective::Datatable
|
3
|
+
datatable do
|
4
|
+
order :created_at
|
5
|
+
|
6
|
+
col :token, visible: false
|
7
|
+
col :created_at, visible: false
|
8
|
+
|
9
|
+
col(:submitted_at, label: 'Registered on') do |registration|
|
10
|
+
registration.submitted_at&.strftime('%F') || 'Incomplete'
|
11
|
+
end
|
12
|
+
|
13
|
+
col :learndash_course, search: :string do |registration|
|
14
|
+
registration.learndash_course.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
col :owner, visible: false, search: :string
|
18
|
+
col :status, visible: false
|
19
|
+
col :orders, action: :show, visible: false, search: :string
|
20
|
+
|
21
|
+
actions_col(actions: []) do |registration|
|
22
|
+
if registration.draft?
|
23
|
+
dropdown_link_to('Continue', effective_learndash.learndash_course_course_registration_build_path(registration.learndash_course, registration, registration.next_step), 'data-turbolinks' => false)
|
24
|
+
dropdown_link_to('Delete', effective_learndash.learndash_course_course_registration_path(registration.learndash_course, registration), 'data-confirm': "Really delete #{registration}?", 'data-method': :delete)
|
25
|
+
else
|
26
|
+
dropdown_link_to('Show', effective_learndash.learndash_course_course_registration_path(registration.learndash_course, registration))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
collection do
|
32
|
+
EffectiveLearndash.CourseRegistration.deep.where(owner: current_user)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Dashboard Courses
|
2
|
+
class EffectiveLearndashCoursesDatatable < Effective::Datatable
|
3
|
+
filters do
|
4
|
+
# Registerable should be first here, so when displayed as a simple datatable on the dashboard they only see registerable courses
|
5
|
+
scope :registerable
|
6
|
+
scope :all
|
7
|
+
end
|
8
|
+
|
9
|
+
datatable do
|
10
|
+
order :title
|
11
|
+
col :id, visible: false
|
12
|
+
|
13
|
+
col :title, label: 'Title' do |learndash_course|
|
14
|
+
link_to(learndash_course.to_s, effective_learndash.learndash_course_path(learndash_course))
|
15
|
+
end
|
16
|
+
|
17
|
+
actions_col show: false do |learndash_course|
|
18
|
+
if learndash_course.can_register?
|
19
|
+
dropdown_link_to('Register', effective_learndash.new_learndash_course_course_registration_path(learndash_course))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
collection do
|
25
|
+
Effective::LearndashCourse.deep.learndash_courses(user: current_user)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
# Dashboard LearndashUsers
|
2
2
|
class EffectiveLearndashEnrollmentsDatatable < Effective::Datatable
|
3
3
|
datatable do
|
4
|
-
col :learndash_course
|
4
|
+
col :learndash_course do |enrollment|
|
5
|
+
link_to(enrollment.learndash_course, EffectiveLearndash.learndash_url, target: '_blank')
|
6
|
+
end
|
7
|
+
|
5
8
|
col :progress_status
|
6
9
|
|
7
10
|
col :last_step, visible: false
|
@@ -10,6 +13,17 @@ class EffectiveLearndashEnrollmentsDatatable < Effective::Datatable
|
|
10
13
|
|
11
14
|
col :date_started, as: :date
|
12
15
|
col :date_completed, as: :date
|
16
|
+
|
17
|
+
actions_col(show: false) do |enrollment|
|
18
|
+
if enrollment.not_started?
|
19
|
+
dropdown_link_to('Start', EffectiveLearndash.learndash_url, target: '_blank')
|
20
|
+
elsif enrollment.in_progress?
|
21
|
+
dropdown_link_to('Continue', EffectiveLearndash.learndash_url, target: '_blank')
|
22
|
+
else
|
23
|
+
dropdown_link_to('Show', EffectiveLearndash.learndash_url, target: '_blank')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
13
27
|
end
|
14
28
|
|
15
29
|
collection do
|
@@ -0,0 +1,167 @@
|
|
1
|
+
# frozen_stcourse_registrant_literal: true
|
2
|
+
|
3
|
+
# EffectiveLearndashCourseRegistration
|
4
|
+
#
|
5
|
+
# Mark your owner model with effective_learndash_course_registration to get all the includes
|
6
|
+
|
7
|
+
module EffectiveLearndashCourseRegistration
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
module Base
|
11
|
+
def effective_learndash_course_registration
|
12
|
+
include ::EffectiveLearndashCourseRegistration
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def effective_learndash_course_registration?; true; end
|
18
|
+
end
|
19
|
+
|
20
|
+
included do
|
21
|
+
acts_as_purchasable_parent
|
22
|
+
acts_as_tokened
|
23
|
+
|
24
|
+
acts_as_statused(
|
25
|
+
:draft, # Just Started
|
26
|
+
:submitted # All done
|
27
|
+
)
|
28
|
+
|
29
|
+
acts_as_wizard(
|
30
|
+
start: 'Start',
|
31
|
+
course: 'Course',
|
32
|
+
summary: 'Review',
|
33
|
+
billing: 'Billing Address',
|
34
|
+
checkout: 'Checkout',
|
35
|
+
submitted: 'Submitted'
|
36
|
+
)
|
37
|
+
|
38
|
+
acts_as_purchasable_wizard
|
39
|
+
|
40
|
+
log_changes(except: :wizard_steps) if respond_to?(:log_changes)
|
41
|
+
|
42
|
+
# Application Namespace
|
43
|
+
belongs_to :owner, polymorphic: true
|
44
|
+
accepts_nested_attributes_for :owner
|
45
|
+
|
46
|
+
# Effective Namespace
|
47
|
+
belongs_to :learndash_course, class_name: 'Effective::LearndashCourse'
|
48
|
+
|
49
|
+
has_many :course_registrants, -> { order(:id) }, class_name: 'Effective::CourseRegistrant', inverse_of: :course_registration, dependent: :destroy
|
50
|
+
accepts_nested_attributes_for :course_registrants, reject_if: :all_blank, allow_destroy: true
|
51
|
+
|
52
|
+
has_many :orders, -> { order(:id) }, as: :parent, class_name: 'Effective::Order', dependent: :nullify
|
53
|
+
accepts_nested_attributes_for :orders
|
54
|
+
|
55
|
+
effective_resource do
|
56
|
+
# Acts as Statused
|
57
|
+
status :string, permitted: false
|
58
|
+
status_steps :text, permitted: false
|
59
|
+
|
60
|
+
# Dates
|
61
|
+
submitted_at :datetime
|
62
|
+
|
63
|
+
# Acts as Wizard
|
64
|
+
wizard_steps :text, permitted: false
|
65
|
+
|
66
|
+
timestamps
|
67
|
+
end
|
68
|
+
|
69
|
+
scope :deep, -> { includes(:owner, :orders, :course_registrants) }
|
70
|
+
scope :sorted, -> { order(:id) }
|
71
|
+
|
72
|
+
scope :in_progress, -> { where.not(status: [:submitted]) }
|
73
|
+
scope :done, -> { where(status: [:submitted]) }
|
74
|
+
|
75
|
+
scope :for, -> (user) { where(owner: user) }
|
76
|
+
|
77
|
+
# All Steps validations
|
78
|
+
validates :owner, presence: true
|
79
|
+
|
80
|
+
# Course Step
|
81
|
+
validate(if: -> { current_step == :course }) do
|
82
|
+
self.errors.add(:course_registrants, "can't be blank") unless present_course_registrants.present?
|
83
|
+
end
|
84
|
+
|
85
|
+
# All Fees and Orders
|
86
|
+
def submit_fees
|
87
|
+
course_registrants
|
88
|
+
end
|
89
|
+
|
90
|
+
def after_submit_purchased!
|
91
|
+
# Enroll them in the course!
|
92
|
+
learndash_owner.create_learndash_enrollment(course: learndash_course)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
# Instance Methods
|
98
|
+
def to_s
|
99
|
+
persisted? ? "#{learndash_course} - #{owner}" : 'course registration'
|
100
|
+
end
|
101
|
+
|
102
|
+
def course
|
103
|
+
learndash_course
|
104
|
+
end
|
105
|
+
|
106
|
+
def in_progress?
|
107
|
+
draft?
|
108
|
+
end
|
109
|
+
|
110
|
+
def done?
|
111
|
+
submitted?
|
112
|
+
end
|
113
|
+
|
114
|
+
def course_registrant
|
115
|
+
course_registrants.first
|
116
|
+
end
|
117
|
+
|
118
|
+
def build_course_registrant
|
119
|
+
course_registrants.build(owner: owner)
|
120
|
+
end
|
121
|
+
|
122
|
+
def learndash_owner
|
123
|
+
(course_registrant&.owner || owner)
|
124
|
+
end
|
125
|
+
|
126
|
+
def member_pricing?
|
127
|
+
learndash_owner.membership_present?
|
128
|
+
end
|
129
|
+
|
130
|
+
def assign_pricing
|
131
|
+
price = (member_pricing? ? learndash_course.member_price : learndash_course.regular_price)
|
132
|
+
|
133
|
+
course_registrant.assign_attributes(
|
134
|
+
price: price,
|
135
|
+
qb_item_name: learndash_course.qb_item_name,
|
136
|
+
tax_exempt: learndash_course.tax_exempt
|
137
|
+
)
|
138
|
+
end
|
139
|
+
|
140
|
+
# After the course step.
|
141
|
+
def course!
|
142
|
+
raise('expected a learndash course') unless learndash_course.present?
|
143
|
+
raise('expected a course_registrant to be present') unless course_registrant.present?
|
144
|
+
raise('expected a course_registrant to have an owner') unless course_registrant.owner.present?
|
145
|
+
raise('expected a learndash owner') unless learndash_owner.class.try(:effective_learndash_owner?)
|
146
|
+
|
147
|
+
# Assign prices
|
148
|
+
assign_pricing()
|
149
|
+
raise('expected course_registrant to have a price') if course_registrant.price.blank?
|
150
|
+
|
151
|
+
# Save record
|
152
|
+
save!
|
153
|
+
|
154
|
+
# Create a learndash user now before payment to catch any errors in server stuff before payment.
|
155
|
+
learndash_owner.create_learndash_user
|
156
|
+
raise('expected a persisted learndash user') unless learndash_owner.learndash_user&.persisted?
|
157
|
+
|
158
|
+
true
|
159
|
+
end
|
160
|
+
|
161
|
+
private
|
162
|
+
|
163
|
+
def present_course_registrants
|
164
|
+
course_registrants.reject(&:marked_for_destruction?)
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This is the registrant as created by the course registration
|
4
|
+
# It tracks who purchased which course for how much
|
5
|
+
|
6
|
+
module Effective
|
7
|
+
class CourseRegistrant < ActiveRecord::Base
|
8
|
+
acts_as_purchasable
|
9
|
+
|
10
|
+
log_changes(to: :learndash_course) if respond_to?(:log_changes)
|
11
|
+
|
12
|
+
# The learndash course containing all the pricing and unique info about this course purchase
|
13
|
+
belongs_to :learndash_course
|
14
|
+
|
15
|
+
# Every course is charged to a owner
|
16
|
+
belongs_to :owner, polymorphic: true
|
17
|
+
|
18
|
+
# As checked out through the learndash course purchase wizard
|
19
|
+
belongs_to :course_registration, polymorphic: true
|
20
|
+
|
21
|
+
effective_resource do
|
22
|
+
# Acts as Purchasable
|
23
|
+
price :integer
|
24
|
+
qb_item_name :string
|
25
|
+
tax_exempt :boolean
|
26
|
+
|
27
|
+
timestamps
|
28
|
+
end
|
29
|
+
|
30
|
+
scope :sorted, -> { order(:id) }
|
31
|
+
scope :deep, -> { includes(:learndash_course, :owner, :course_registration) }
|
32
|
+
|
33
|
+
before_validation(if: -> { course_registration.present? }) do
|
34
|
+
self.learndash_course ||= course_registration.learndash_course
|
35
|
+
self.owner ||= course_registration.owner
|
36
|
+
end
|
37
|
+
|
38
|
+
before_validation(if: -> { learndash_course.present? }) do
|
39
|
+
self.price ||= learndash_course.price
|
40
|
+
self.qb_item_name ||= learndash_course.qb_item_name
|
41
|
+
self.tax_exempt = learndash_course.tax_exempt? if self.tax_exempt.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
persisted? ? title : 'course purchase'
|
46
|
+
end
|
47
|
+
|
48
|
+
def title
|
49
|
+
"#{learndash_course} - #{owner}"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -60,13 +60,14 @@ module Effective
|
|
60
60
|
|
61
61
|
username = username_for(owner)
|
62
62
|
password = password_for(owner)
|
63
|
+
email = email_for(owner)
|
63
64
|
|
64
65
|
payload = {
|
65
66
|
username: username,
|
66
67
|
password: password,
|
68
|
+
email: email,
|
67
69
|
|
68
70
|
name: owner.to_s,
|
69
|
-
email: owner.email,
|
70
71
|
roles: ['subscriber'],
|
71
72
|
|
72
73
|
first_name: owner.try(:first_name),
|
@@ -152,6 +153,14 @@ module Effective
|
|
152
153
|
name
|
153
154
|
end
|
154
155
|
|
156
|
+
def email_for(resource)
|
157
|
+
raise('expected a learndash owner') unless resource.class.respond_to?(:effective_learndash_owner?) # This is a user
|
158
|
+
|
159
|
+
email = resource.email
|
160
|
+
email = "test#{email}" unless Rails.env.production?
|
161
|
+
email
|
162
|
+
end
|
163
|
+
|
155
164
|
def password_for(resource)
|
156
165
|
raise('expected a learndash owner') unless resource.class.respond_to?(:effective_learndash_owner?) # This is a user
|
157
166
|
EffectiveLearndash.wp_password_for(resource)
|
@@ -3,22 +3,88 @@ module Effective
|
|
3
3
|
has_many :learndash_enrollments
|
4
4
|
has_many :learndash_users, through: :learndash_enrollments
|
5
5
|
|
6
|
+
log_changes if respond_to?(:log_changes)
|
7
|
+
|
8
|
+
# rich_text_body - Used by the select step
|
9
|
+
has_many_rich_texts
|
10
|
+
|
11
|
+
# rich_text_body
|
12
|
+
|
13
|
+
# rich_text_all_steps_content
|
14
|
+
# rich_text_start_content
|
15
|
+
# rich_text_select_content
|
16
|
+
# rich_text_select_content
|
17
|
+
|
18
|
+
acts_as_slugged
|
19
|
+
log_changes if respond_to?(:log_changes)
|
20
|
+
acts_as_role_restricted if respond_to?(:acts_as_role_restricted)
|
21
|
+
|
6
22
|
effective_resource do
|
7
23
|
# This user the wordpress credentials
|
8
|
-
course_id
|
9
|
-
|
10
|
-
|
24
|
+
course_id :integer
|
25
|
+
title :string
|
26
|
+
status :string
|
27
|
+
|
28
|
+
# Our attributes
|
29
|
+
slug :string
|
30
|
+
|
31
|
+
# For course purchases
|
32
|
+
can_register :boolean
|
33
|
+
|
34
|
+
# Pricing
|
35
|
+
regular_price :integer
|
36
|
+
member_price :integer
|
37
|
+
|
38
|
+
qb_item_name :string
|
39
|
+
tax_exempt :boolean
|
40
|
+
|
41
|
+
# Access
|
42
|
+
roles_mask :integer
|
43
|
+
authenticate_user :boolean
|
11
44
|
|
12
45
|
timestamps
|
13
46
|
end
|
14
47
|
|
15
48
|
scope :deep, -> { all }
|
16
49
|
scope :sorted, -> { order(:title) }
|
50
|
+
scope :registerable, -> { where(can_register: true) }
|
51
|
+
scope :published, -> { all }
|
52
|
+
|
53
|
+
scope :paginate, -> (page: nil, per_page: nil) {
|
54
|
+
page = (page || 1).to_i
|
55
|
+
offset = [(page - 1), 0].max * (per_page || EffectiveLearndash.per_page)
|
56
|
+
|
57
|
+
limit(per_page).offset(offset)
|
58
|
+
}
|
59
|
+
|
60
|
+
scope :learndash_courses, -> (user: nil, unpublished: false) {
|
61
|
+
scope = all.deep.sorted
|
62
|
+
|
63
|
+
if defined?(EffectiveRoles) && EffectiveLearndash.use_effective_roles
|
64
|
+
scope = scope.for_role(user&.roles)
|
65
|
+
end
|
66
|
+
|
67
|
+
if user.blank?
|
68
|
+
scope = scope.where(authenticate_user: false)
|
69
|
+
end
|
70
|
+
|
71
|
+
# TODO
|
72
|
+
# unless unpublished
|
73
|
+
# scope = scope.published
|
74
|
+
# end
|
75
|
+
|
76
|
+
scope
|
77
|
+
}
|
17
78
|
|
18
79
|
validates :course_id, presence: true
|
19
80
|
validates :status, presence: true
|
20
81
|
validates :title, presence: true
|
21
82
|
|
83
|
+
with_options(if: -> { can_register? }) do
|
84
|
+
validates :regular_price, presence: true
|
85
|
+
validates :member_price, presence: true
|
86
|
+
end
|
87
|
+
|
22
88
|
# Syncs all courses
|
23
89
|
def self.refresh!
|
24
90
|
courses = all()
|
@@ -35,5 +101,14 @@ module Effective
|
|
35
101
|
title.presence || 'learndash course'
|
36
102
|
end
|
37
103
|
|
104
|
+
def body
|
105
|
+
rich_text_body
|
106
|
+
end
|
107
|
+
|
108
|
+
# Todo
|
109
|
+
def draft?
|
110
|
+
false
|
111
|
+
end
|
112
|
+
|
38
113
|
end
|
39
114
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Effective
|
2
2
|
class LearndashEnrollment < ActiveRecord::Base
|
3
3
|
belongs_to :owner, polymorphic: true
|
4
|
-
log_changes(to: :owner) if respond_to?(:log_changes)
|
5
|
-
|
6
4
|
belongs_to :learndash_course
|
7
5
|
belongs_to :learndash_user
|
8
6
|
|
7
|
+
log_changes(to: :learndash_course, except: [:last_synced_at]) if respond_to?(:log_changes)
|
8
|
+
|
9
9
|
PROGRESS_STATUSES = ['not-started', 'in-progress', 'completed']
|
10
10
|
|
11
11
|
effective_resource do
|
@@ -46,11 +46,23 @@ module Effective
|
|
46
46
|
persisted? ? "#{learndash_user} #{learndash_course}" : 'learndash enrollment'
|
47
47
|
end
|
48
48
|
|
49
|
+
def not_started?
|
50
|
+
progress_status == 'not-started'
|
51
|
+
end
|
52
|
+
|
53
|
+
def in_progress?
|
54
|
+
progress_status == 'in-progress'
|
55
|
+
end
|
56
|
+
|
49
57
|
def completed?
|
50
58
|
progress_status == 'completed'
|
51
59
|
end
|
52
60
|
|
53
|
-
def refresh!
|
61
|
+
def refresh!(force: false)
|
62
|
+
unless force
|
63
|
+
return if last_synced_at.present? && (Time.zone.now - last_synced_at) < 5
|
64
|
+
end
|
65
|
+
|
54
66
|
assign_api_attributes
|
55
67
|
save!
|
56
68
|
end
|