effective_learndash 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/datatables/admin/effective_learndash_enrollments_datatable.rb +2 -2
- data/app/datatables/{effective_learndash_courses_datatable.rb → effective_learndash_available_courses_datatable.rb} +6 -9
- data/app/models/concerns/effective_learndash_owner.rb +57 -4
- data/app/models/effective/learndash_enrollment.rb +38 -4
- data/app/models/effective/learndash_user.rb +2 -0
- data/app/views/admin/learndash_courses/_form.html.haml +1 -0
- data/app/views/admin/learndash_users/_learndash_user.html.haml +5 -2
- data/app/views/effective/learndash/_dashboard.html.haml +11 -3
- data/config/routes.rb +2 -0
- data/lib/effective_learndash/version.rb +1 -1
- data/lib/effective_learndash.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87e52e6957936bdcd5edc9debdad8e631d22e37d3077506eca3ca26c8d5eba1a
|
4
|
+
data.tar.gz: cf4eb36b9850f5e6e9534dbe09aae83872029d0ff08d8ee1d94ff14eab486b1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34d1b92f818ef50b710af71865c50ef0e5fbd0ded41a6f65f0eaaf8cc3eb344b580bae3b477b8b9d131a781b81a4e0b03577869fc55f49b2818e064770a456f8
|
7
|
+
data.tar.gz: ef13112da1f237ff71fb734cdc10e42061464706d85bf4a01a7dc4fa24a4fc7ccb340d05d08a5e9bd8722fb0bc4fd773d6a74fbdf39dbc873e58b912142bfac6
|
@@ -14,9 +14,9 @@ module Admin
|
|
14
14
|
time_ago_in_words(enrollment.last_synced_at) + ' ago'
|
15
15
|
end
|
16
16
|
|
17
|
-
col :owner
|
18
|
-
col :learndash_course
|
17
|
+
col :owner, visible: attributes[:learndash_user_id].blank?
|
19
18
|
col :learndash_user
|
19
|
+
col :learndash_course
|
20
20
|
|
21
21
|
col :progress_status
|
22
22
|
|
@@ -1,11 +1,5 @@
|
|
1
|
-
# Dashboard Courses
|
2
|
-
class
|
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
|
-
|
1
|
+
# Dashboard Available Courses
|
2
|
+
class EffectiveLearndashAvailableCoursesDatatable < Effective::Datatable
|
9
3
|
datatable do
|
10
4
|
order :title
|
11
5
|
col :id, visible: false
|
@@ -24,7 +18,10 @@ class EffectiveLearndashCoursesDatatable < Effective::Datatable
|
|
24
18
|
end
|
25
19
|
|
26
20
|
collection do
|
27
|
-
Effective::
|
21
|
+
enrolled = Effective::LearndashEnrollment.where(learndash_user: current_user.learndash_user).select(:learndash_course_id)
|
22
|
+
courses = Effective::LearndashCourse.deep.registerable.learndash_courses(user: current_user)
|
23
|
+
|
24
|
+
courses.where.not(id: enrolled)
|
28
25
|
end
|
29
26
|
|
30
27
|
end
|
@@ -43,6 +43,22 @@ module EffectiveLearndashOwner
|
|
43
43
|
learndash_users.first
|
44
44
|
end
|
45
45
|
|
46
|
+
def in_progress_learndash_enrollments
|
47
|
+
learndash_enrollments.reject(&:completed?).sort_by(&:created_at)
|
48
|
+
end
|
49
|
+
|
50
|
+
def completed_learndash_enrollments
|
51
|
+
learndash_enrollments.select(&:completed?).sort_by(&:date_completed)
|
52
|
+
end
|
53
|
+
|
54
|
+
def completed_learndash_courses
|
55
|
+
learndash_enrollments.select(&:completed?).map(&:course).sort_by(&:id)
|
56
|
+
end
|
57
|
+
|
58
|
+
def learndash_enrolled_courses
|
59
|
+
learndash_enrollments.map { |enrollment| enrollment.learndash_course }
|
60
|
+
end
|
61
|
+
|
46
62
|
# Find or create
|
47
63
|
def create_learndash_user
|
48
64
|
learndash_user || learndash_users.create!(owner: self)
|
@@ -67,11 +83,48 @@ module EffectiveLearndashOwner
|
|
67
83
|
return false if enrollment.blank?
|
68
84
|
|
69
85
|
# Return completed right away if previously marked completed
|
70
|
-
return true if enrollment.completed?
|
71
|
-
|
72
|
-
# Check the API
|
73
|
-
enrollment.refresh!
|
74
86
|
enrollment.completed?
|
87
|
+
|
88
|
+
# DO NOT check API
|
89
|
+
end
|
90
|
+
|
91
|
+
def learndash_enroll!(courses:)
|
92
|
+
courses = Array(courses)
|
93
|
+
|
94
|
+
# Find or create the user
|
95
|
+
create_learndash_user
|
96
|
+
raise('expected a persisted learndash user') unless learndash_user&.persisted?
|
97
|
+
|
98
|
+
courses.each do |course|
|
99
|
+
# Find or Enroll in the course
|
100
|
+
create_learndash_enrollment(course: course)
|
101
|
+
raise('expected a persisted learndash enrollment') unless learndash_enrollment(course: course)&.persisted?
|
102
|
+
end
|
103
|
+
|
104
|
+
# This syncs the learndash enrollment locally
|
105
|
+
learndash_enrollments.select { |enrollment| courses.include?(enrollment.learndash_course) }.each do |enrollment|
|
106
|
+
enrollment.refresh! unless enrollment.completed?
|
107
|
+
end
|
108
|
+
|
109
|
+
save!
|
110
|
+
|
111
|
+
after_learndash_enroll() if respond_to?(:after_learndash_enroll)
|
112
|
+
|
113
|
+
true
|
114
|
+
end
|
115
|
+
|
116
|
+
def learndash_refresh!(force: false)
|
117
|
+
raise('expected a previously persisted learndash user') if learndash_user.blank?
|
118
|
+
|
119
|
+
learndash_enrollments.each do |enrollment|
|
120
|
+
enrollment.refresh!(force: force) unless (force || enrollment.completed?)
|
121
|
+
end
|
122
|
+
|
123
|
+
save!
|
124
|
+
|
125
|
+
after_learndash_refresh() if respond_to?(:after_learndash_refresh)
|
126
|
+
|
127
|
+
true
|
75
128
|
end
|
76
129
|
|
77
130
|
end
|
@@ -8,7 +8,9 @@ module Effective
|
|
8
8
|
|
9
9
|
log_changes(to: :learndash_course, except: [:last_synced_at]) if respond_to?(:log_changes)
|
10
10
|
|
11
|
-
|
11
|
+
# Only admin can mark finished
|
12
|
+
# Finished is treated as an admin override for completed?
|
13
|
+
PROGRESS_STATUSES = ['not-started', 'in-progress', 'completed', 'finished']
|
12
14
|
|
13
15
|
effective_resource do
|
14
16
|
last_synced_at :string
|
@@ -26,7 +28,7 @@ module Effective
|
|
26
28
|
timestamps
|
27
29
|
end
|
28
30
|
|
29
|
-
scope :completed, -> { where(progress_status: 'completed') }
|
31
|
+
scope :completed, -> { where(progress_status: ['completed', 'finished']) }
|
30
32
|
scope :in_progress, -> { where(progress_status: 'in-progress') }
|
31
33
|
scope :not_started, -> { where(progress_status: 'not-started') }
|
32
34
|
|
@@ -61,8 +63,35 @@ module Effective
|
|
61
63
|
progress_status == 'in-progress'
|
62
64
|
end
|
63
65
|
|
66
|
+
# Admin override to completed
|
67
|
+
def finished?
|
68
|
+
progress_status == 'finished'
|
69
|
+
end
|
70
|
+
|
71
|
+
# Checked to see if the course is done throughout
|
64
72
|
def completed?
|
65
|
-
progress_status == 'completed'
|
73
|
+
progress_status == 'completed' || finished?
|
74
|
+
end
|
75
|
+
|
76
|
+
def completed_on
|
77
|
+
date_completed || (created_at if finished?)
|
78
|
+
end
|
79
|
+
|
80
|
+
def mark_as_finished!
|
81
|
+
update!(progress_status: 'finished')
|
82
|
+
end
|
83
|
+
|
84
|
+
# Guess old status
|
85
|
+
def unfinish!
|
86
|
+
if date_completed.present?
|
87
|
+
assign_attributes(progress_status: 'completed')
|
88
|
+
elsif date_started.present?
|
89
|
+
assign_attributes(progress_status: 'in-progress')
|
90
|
+
else
|
91
|
+
assign_attributes(progress_status: 'not-started')
|
92
|
+
end
|
93
|
+
|
94
|
+
save!
|
66
95
|
end
|
67
96
|
|
68
97
|
def refresh!(force: false)
|
@@ -75,17 +104,22 @@ module Effective
|
|
75
104
|
end
|
76
105
|
|
77
106
|
def assign_api_attributes(data = nil)
|
107
|
+
return if EffectiveLearndash.disabled?
|
108
|
+
|
78
109
|
data ||= EffectiveLearndash.api.find_enrollment(self) || EffectiveLearndash.api.create_enrollment(self)
|
79
110
|
|
80
111
|
assign_attributes(
|
81
112
|
last_synced_at: Time.zone.now,
|
82
|
-
progress_status: data[:progress_status],
|
83
113
|
last_step: data[:last_step],
|
84
114
|
steps_completed: data[:steps_completed],
|
85
115
|
steps_total: data[:steps_total],
|
86
116
|
date_started: Time.use_zone('UTC') { Time.zone.parse(data[:date_started]) },
|
87
117
|
date_completed: (Time.use_zone('UTC') { Time.zone.parse(data[:date_completed]) } if data[:date_completed].present?)
|
88
118
|
)
|
119
|
+
|
120
|
+
assign_attributes(progress_status: data[:progress_status]) unless finished?
|
121
|
+
|
122
|
+
true
|
89
123
|
end
|
90
124
|
|
91
125
|
end
|
@@ -83,6 +83,8 @@ module Effective
|
|
83
83
|
|
84
84
|
# This synchronizes all the course enrollments from the API down locally.
|
85
85
|
def assign_api_course_enrollments
|
86
|
+
return if EffectiveLearndash.disabled?
|
87
|
+
|
86
88
|
raise('must be persisted') unless persisted?
|
87
89
|
|
88
90
|
courses = LearndashCourse.all()
|
@@ -8,6 +8,7 @@
|
|
8
8
|
%p Click the New button from the below table to enroll a user into this course.
|
9
9
|
%p Enrolling a user here will enroll them on the LearnDash site.
|
10
10
|
%p Alternately, if this course is available for registration, the enrollment will be created upon registration purchase.
|
11
|
+
%p Marking the course finished will allow them to proceed without completing the course on the Learndash LMS.
|
11
12
|
|
12
13
|
- datatable = Admin::EffectiveLearndashEnrollmentsDatatable.new(learndash_course: learndash_course)
|
13
14
|
= render_datatable(datatable, inline: true)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
= link_to(learndash_user.owner, "/admin/users/#{learndash_user.owner.to_param}/edit")
|
4
4
|
has an existing account on LearnDash.
|
5
5
|
|
6
|
-
%p= link_to "LearnDash LMS User Admin", EffectiveLearndash.learndash_url.chomp('/') + "/wp-admin/user-edit.php?user_id=#{learndash_user.user_id}", target: '_blank'
|
6
|
+
%p= link_to "LearnDash LMS User Admin", EffectiveLearndash.learndash_url.to_s.chomp('/') + "/wp-admin/user-edit.php?user_id=#{learndash_user.user_id}", target: '_blank'
|
7
7
|
|
8
8
|
%ul
|
9
9
|
%li Email: #{learndash_user.email}
|
@@ -21,7 +21,10 @@
|
|
21
21
|
|
22
22
|
%h3 LearnDash Course Enrollments
|
23
23
|
|
24
|
-
%p
|
24
|
+
%p
|
25
|
+
Click the New button from the below table to manually enroll this user into a new course.
|
26
|
+
%br
|
27
|
+
%small.text-muted Marking the course finished will allow them to proceed without completing the course on the Learndash LMS.
|
25
28
|
|
26
29
|
- datatable = Admin::EffectiveLearndashEnrollmentsDatatable.new(learndash_user: learndash_user)
|
27
30
|
= render_datatable(datatable, inline: true)
|
@@ -1,13 +1,14 @@
|
|
1
1
|
- learndash_user = current_user.try(:learndash_user)
|
2
|
-
-
|
2
|
+
- authorized_user = learndash_user && EffectiveResources.authorized?(self, :show, learndash_user)
|
3
|
+
- authorized_registration = EffectiveResources.authorized?(self, :new, EffectiveLearndash.CourseRegistration)
|
3
4
|
|
4
5
|
%h2 Courses
|
5
6
|
|
6
7
|
- if learndash_user.blank?
|
7
8
|
%p You do not have an account to access courses. When you are enrolled in a course, your account credentials will be displayed here.
|
8
9
|
|
9
|
-
- if learndash_user.present? &&
|
10
|
-
- learndash_user.refresh!
|
10
|
+
- if learndash_user.present? && authorized_user
|
11
|
+
- learndash_user.refresh! unless EffectiveLearndash.disabled?
|
11
12
|
|
12
13
|
%p Your course account credentials are:
|
13
14
|
|
@@ -22,8 +23,15 @@
|
|
22
23
|
%p= link_to('Sign in to your course account', EffectiveLearndash.learndash_url, target: '_blank', class: 'btn btn-primary')
|
23
24
|
|
24
25
|
- if learndash_user.learndash_enrollments.present?
|
26
|
+
%p You are enrolled in the following courses:
|
25
27
|
- datatable = EffectiveResources.best('EffectiveLearndashEnrollmentsDatatable').new(self)
|
26
28
|
= render_datatable(datatable, simple: true)
|
27
29
|
|
28
30
|
- else
|
29
31
|
%p You are not enrolled in any courses.
|
32
|
+
|
33
|
+
- available = EffectiveResources.best('EffectiveLearndashAvailableCoursesDatatable').new(self)
|
34
|
+
|
35
|
+
- if available.present? && authorized_registration
|
36
|
+
%p The following courses are available for registration:
|
37
|
+
= render_datatable(available, simple: true)
|
data/config/routes.rb
CHANGED
@@ -23,6 +23,8 @@ EffectiveLearndash::Engine.routes.draw do
|
|
23
23
|
|
24
24
|
resources :learndash_enrollments, only: [:index, :new, :create, :update] do
|
25
25
|
post :refresh, on: :member
|
26
|
+
post :mark_as_finished, on: :member
|
27
|
+
post :unfinish, on: :member
|
26
28
|
end
|
27
29
|
|
28
30
|
resources :learndash_courses, only: [:index, :edit, :update] do
|
data/lib/effective_learndash.rb
CHANGED
@@ -18,7 +18,13 @@ module EffectiveLearndash
|
|
18
18
|
|
19
19
|
include EffectiveGem
|
20
20
|
|
21
|
+
def self.disabled?
|
22
|
+
learndash_url.blank?
|
23
|
+
end
|
24
|
+
|
21
25
|
def self.api
|
26
|
+
return if disabled?
|
27
|
+
|
22
28
|
raise('please set learndash_url in config/initializers/effective_learndash.rb') unless learndash_url.present?
|
23
29
|
raise('please set learndash_username in config/initializers/effective_learndash.rb') unless learndash_username.present?
|
24
30
|
raise('please set learndash_password in config/initializers/effective_learndash.rb') unless learndash_password.present?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_learndash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -191,7 +191,7 @@ files:
|
|
191
191
|
- app/datatables/admin/effective_learndash_users_datatable.rb
|
192
192
|
- app/datatables/effective_course_registrants_datatable.rb
|
193
193
|
- app/datatables/effective_course_registrations_datatable.rb
|
194
|
-
- app/datatables/
|
194
|
+
- app/datatables/effective_learndash_available_courses_datatable.rb
|
195
195
|
- app/datatables/effective_learndash_enrollments_datatable.rb
|
196
196
|
- app/helpers/effective_learndash_helper.rb
|
197
197
|
- app/models/concerns/effective_learndash_course_registration.rb
|