effective_learndash 0.1.5 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43df5441a08d0a4f6974c1833c3967e007f0b84d29bb0211a574b9b5803ecf6e
4
- data.tar.gz: '019f88430901977c58b6ae5a2266aa9b27a548689d1d14aa78926ec32639f582'
3
+ metadata.gz: bb60befd537b5ed6b7111baf26c546997223c4350c60d0b66cf6803281616c64
4
+ data.tar.gz: '0087f4c16776214a5bb6b098078ade3f3a215742f75820b1c9046180faa0cf0b'
5
5
  SHA512:
6
- metadata.gz: ebb0420d408114b919048393146dc0fbfb25c66f635672e8da07beef5847f78388e11cc08b243299db4ef132cd220025ba945715b83e87440e957b37f9ed71f2
7
- data.tar.gz: dc6af37f79445a95ebed1e4501be634ec795d5e1f7ca09e997087e25a0aa95cb8d392a892cd51207998d2ea0d2c30ba885fc8865364860fee0d9260d70cdcb32
6
+ metadata.gz: 0a9def7fbe45dec58d8768454a9adccffb989b44a1f387ee1b04de0c56f9db48ba5f104012ee4060fbf4adb9e35ec3ebc0281ff4274f10c486efc3ba7416e526
7
+ data.tar.gz: 5b8bd37c4ea919fc77aa4f61d6f8aa8b4c638dbb8b9deb72bcf632fa4c56cd01da62024f0e8ff98656060e9e2d25315a5882bebb4760a6b21d7c860cc49165f6
@@ -2,8 +2,8 @@
2
2
 
3
3
  class EffectiveCourseRegistrantsDatatable < Effective::Datatable
4
4
  datatable do
5
- col :learndash_course
6
- col :owner, label: 'User', action: false
5
+ col :learndash_course, label: 'Title'
6
+ col :owner, label: 'Registrant', action: false
7
7
  col :price, as: :price
8
8
  end
9
9
 
@@ -87,9 +87,9 @@ module EffectiveLearndashCourseRegistration
87
87
  course_registrants
88
88
  end
89
89
 
90
+ # Enroll them in all courses.
90
91
  def after_submit_purchased!
91
- # Enroll them in the course!
92
- learndash_owner.create_learndash_enrollment(course: learndash_course)
92
+ course_registrants.each { |registrant| registrant.owner.create_learndash_enrollment(course: registrant.learndash_course) }
93
93
  end
94
94
 
95
95
  end
@@ -116,7 +116,7 @@ module EffectiveLearndashCourseRegistration
116
116
  end
117
117
 
118
118
  def build_course_registrant
119
- course_registrants.build(owner: owner)
119
+ course_registrants.build(owner: owner, learndash_course: learndash_course)
120
120
  end
121
121
 
122
122
  def learndash_owner
@@ -151,7 +151,7 @@ module EffectiveLearndashCourseRegistration
151
151
 
152
152
  # Assign prices
153
153
  assign_pricing()
154
- raise('expected course_registrant to have a price') if course_registrant.price.blank?
154
+ raise('expected course_registrants to have a price') if course_registrants.any? { |registrant| registrant.price.blank? }
155
155
 
156
156
  # Save record
157
157
  save!
@@ -30,7 +30,7 @@ module Effective
30
30
  def find_user(value)
31
31
  # Find by email
32
32
  if value.kind_of?(String) && value.include?('@')
33
- return find_by("/wp/v2/users", :email, value)
33
+ return find_by("/wp/v2/users", :email, email_for(value))
34
34
  end
35
35
 
36
36
  # Fetch by saved param value
@@ -39,7 +39,7 @@ module Effective
39
39
  return user if user.present?
40
40
 
41
41
  # Find by email
42
- email = value.try(:email)
42
+ email = email_for(value)
43
43
  user = find_by("/wp/v2/users", :email, email) if email
44
44
  return user if user.present?
45
45
 
@@ -122,7 +122,6 @@ module Effective
122
122
 
123
123
  # private under this point
124
124
 
125
-
126
125
  def user_id(resource)
127
126
  if resource.class.respond_to?(:effective_learndash_owner?) # This is a user
128
127
  resource.learndash_user&.user_id
@@ -147,18 +146,9 @@ module Effective
147
146
 
148
147
  def username_for(resource)
149
148
  raise('expected a LearnDash owner') unless resource.class.respond_to?(:effective_learndash_owner?) # This is a user
150
-
151
149
  name = EffectiveLearndash.wp_username_for(resource)
152
- name = "test#{name}" unless Rails.env.production?
153
- name
154
- end
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
150
 
159
- email = resource.email
160
- email = "test#{email}" unless Rails.env.production?
161
- email
151
+ Rails.env.production? ? name : "test#{name}"
162
152
  end
163
153
 
164
154
  def password_for(resource)
@@ -166,6 +156,13 @@ module Effective
166
156
  EffectiveLearndash.wp_password_for(resource)
167
157
  end
168
158
 
159
+ def email_for(value)
160
+ email = value.try(:email) || value.to_s
161
+ return nil unless email.present? && email.include?('@')
162
+
163
+ Rails.env.production? ? email : "test#{email}"
164
+ end
165
+
169
166
  def find(endpoint, params = nil)
170
167
  response = get(endpoint, params)
171
168
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveLearndash
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.1.8'.freeze
3
3
  end
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.1.5
4
+ version: 0.1.8
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: 2022-03-31 00:00:00.000000000 Z
11
+ date: 2022-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails