@memberjunction/actions-bizapps-lms 2.55.0
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.
- package/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +12 -0
- package/dist/base/base-lms.action.d.ts +77 -0
- package/dist/base/base-lms.action.d.ts.map +1 -0
- package/dist/base/base-lms.action.js +176 -0
- package/dist/base/base-lms.action.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts +125 -0
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-courses.action.js +436 -0
- package/dist/providers/learnworlds/actions/get-courses.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts +95 -0
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-details.action.js +280 -0
- package/dist/providers/learnworlds/actions/get-user-details.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts +151 -0
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-progress.action.js +417 -0
- package/dist/providers/learnworlds/actions/get-user-progress.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-users.action.d.ts +53 -0
- package/dist/providers/learnworlds/actions/get-users.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-users.action.js +272 -0
- package/dist/providers/learnworlds/actions/get-users.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/index.d.ts +5 -0
- package/dist/providers/learnworlds/actions/index.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/index.js +22 -0
- package/dist/providers/learnworlds/actions/index.js.map +1 -0
- package/dist/providers/learnworlds/index.d.ts +3 -0
- package/dist/providers/learnworlds/index.d.ts.map +1 -0
- package/dist/providers/learnworlds/index.js +21 -0
- package/dist/providers/learnworlds/index.js.map +1 -0
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts +52 -0
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/learnworlds-base.action.js +186 -0
- package/dist/providers/learnworlds/learnworlds-base.action.js.map +1 -0
- package/package.json +40 -0
- package/src/base/base-lms.action.ts +197 -0
- package/src/index.ts +5 -0
- package/src/providers/learnworlds/actions/get-courses.action.ts +592 -0
- package/src/providers/learnworlds/actions/get-user-details.action.ts +381 -0
- package/src/providers/learnworlds/actions/get-user-progress.action.ts +625 -0
- package/src/providers/learnworlds/actions/get-users.action.ts +319 -0
- package/src/providers/learnworlds/actions/index.ts +5 -0
- package/src/providers/learnworlds/index.ts +5 -0
- package/src/providers/learnworlds/learnworlds-base.action.ts +221 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
2
|
+
import { LearnWorldsBaseAction } from '../learnworlds-base.action';
|
|
3
|
+
import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Interface for a LearnWorlds course
|
|
7
|
+
*/
|
|
8
|
+
export interface LearnWorldsCourse {
|
|
9
|
+
id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
subtitle?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
shortDescription?: string;
|
|
14
|
+
|
|
15
|
+
// Status and visibility
|
|
16
|
+
status: 'published' | 'draft' | 'coming_soon';
|
|
17
|
+
visibility: 'public' | 'private' | 'hidden';
|
|
18
|
+
isActive: boolean;
|
|
19
|
+
isFree: boolean;
|
|
20
|
+
|
|
21
|
+
// Pricing
|
|
22
|
+
price?: number;
|
|
23
|
+
currency?: string;
|
|
24
|
+
originalPrice?: number;
|
|
25
|
+
discountPercentage?: number;
|
|
26
|
+
|
|
27
|
+
// Course metadata
|
|
28
|
+
categoryId?: string;
|
|
29
|
+
categoryName?: string;
|
|
30
|
+
tags?: string[];
|
|
31
|
+
level?: 'beginner' | 'intermediate' | 'advanced' | 'all';
|
|
32
|
+
language?: string;
|
|
33
|
+
duration?: number; // in minutes
|
|
34
|
+
|
|
35
|
+
// Media
|
|
36
|
+
thumbnailUrl?: string;
|
|
37
|
+
coverImageUrl?: string;
|
|
38
|
+
promoVideoUrl?: string;
|
|
39
|
+
|
|
40
|
+
// Instructor info
|
|
41
|
+
instructorId?: string;
|
|
42
|
+
instructorName?: string;
|
|
43
|
+
instructorBio?: string;
|
|
44
|
+
instructorAvatarUrl?: string;
|
|
45
|
+
|
|
46
|
+
// Course structure
|
|
47
|
+
totalUnits: number;
|
|
48
|
+
totalLessons: number;
|
|
49
|
+
totalQuizzes: number;
|
|
50
|
+
totalAssignments: number;
|
|
51
|
+
estimatedDuration?: number;
|
|
52
|
+
|
|
53
|
+
// Enrollment data
|
|
54
|
+
totalEnrollments: number;
|
|
55
|
+
activeEnrollments: number;
|
|
56
|
+
completionRate: number;
|
|
57
|
+
averageRating?: number;
|
|
58
|
+
totalReviews?: number;
|
|
59
|
+
|
|
60
|
+
// Dates
|
|
61
|
+
createdAt: Date;
|
|
62
|
+
updatedAt: Date;
|
|
63
|
+
publishedAt?: Date;
|
|
64
|
+
enrollmentStartDate?: Date;
|
|
65
|
+
enrollmentEndDate?: Date;
|
|
66
|
+
|
|
67
|
+
// Access settings
|
|
68
|
+
requiresApproval: boolean;
|
|
69
|
+
hasPrerequisites: boolean;
|
|
70
|
+
prerequisites?: string[];
|
|
71
|
+
certificateAvailable: boolean;
|
|
72
|
+
|
|
73
|
+
// Learning outcomes
|
|
74
|
+
objectives?: string[];
|
|
75
|
+
targetAudience?: string[];
|
|
76
|
+
requirements?: string[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Interface for course catalog summary
|
|
81
|
+
*/
|
|
82
|
+
export interface CourseCatalogSummary {
|
|
83
|
+
totalCourses: number;
|
|
84
|
+
publishedCourses: number;
|
|
85
|
+
draftCourses: number;
|
|
86
|
+
freeCourses: number;
|
|
87
|
+
paidCourses: number;
|
|
88
|
+
|
|
89
|
+
categoryCounts: Record<string, number>;
|
|
90
|
+
levelCounts: Record<string, number>;
|
|
91
|
+
languageCounts: Record<string, number>;
|
|
92
|
+
|
|
93
|
+
enrollmentStats: {
|
|
94
|
+
totalEnrollments: number;
|
|
95
|
+
averageEnrollmentsPerCourse: number;
|
|
96
|
+
mostPopularCourses: Array<{
|
|
97
|
+
id: string;
|
|
98
|
+
title: string;
|
|
99
|
+
enrollments: number;
|
|
100
|
+
}>;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
priceStats: {
|
|
104
|
+
averagePrice: number;
|
|
105
|
+
minPrice: number;
|
|
106
|
+
maxPrice: number;
|
|
107
|
+
currency: string;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Action to retrieve courses from LearnWorlds LMS
|
|
113
|
+
*/
|
|
114
|
+
@RegisterClass(LearnWorldsBaseAction, 'GetLearnWorldsCoursesAction')
|
|
115
|
+
export class GetLearnWorldsCoursesAction extends LearnWorldsBaseAction {
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Description of the action
|
|
119
|
+
*/
|
|
120
|
+
public get Description(): string {
|
|
121
|
+
return 'Retrieves the course catalog from LearnWorlds with filtering, search, and sorting options';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Main execution method
|
|
126
|
+
*/
|
|
127
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
128
|
+
try {
|
|
129
|
+
const contextUser = params.ContextUser;
|
|
130
|
+
if (!contextUser) {
|
|
131
|
+
return {
|
|
132
|
+
Success: false,
|
|
133
|
+
ResultCode: 'ERROR',
|
|
134
|
+
Message: 'Context user is required for LearnWorlds API calls'
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Store params for base class methods
|
|
139
|
+
this.params = params.Params;
|
|
140
|
+
|
|
141
|
+
// Build query parameters
|
|
142
|
+
const queryParams: Record<string, any> = {};
|
|
143
|
+
|
|
144
|
+
// Search filter
|
|
145
|
+
const searchText = this.getParamValue(params.Params, 'SearchText');
|
|
146
|
+
if (searchText) {
|
|
147
|
+
queryParams.search = searchText;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Status filter
|
|
151
|
+
const status = this.getParamValue(params.Params, 'Status');
|
|
152
|
+
if (status) {
|
|
153
|
+
queryParams.status = status;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Category filter
|
|
157
|
+
const categoryId = this.getParamValue(params.Params, 'CategoryID');
|
|
158
|
+
if (categoryId) {
|
|
159
|
+
queryParams.category_id = categoryId;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Level filter
|
|
163
|
+
const level = this.getParamValue(params.Params, 'Level');
|
|
164
|
+
if (level) {
|
|
165
|
+
queryParams.level = level;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Language filter
|
|
169
|
+
const language = this.getParamValue(params.Params, 'Language');
|
|
170
|
+
if (language) {
|
|
171
|
+
queryParams.language = language;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Price filters
|
|
175
|
+
const onlyFree = this.getParamValue(params.Params, 'OnlyFree');
|
|
176
|
+
if (onlyFree) {
|
|
177
|
+
queryParams.is_free = true;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const minPrice = this.getParamValue(params.Params, 'MinPrice');
|
|
181
|
+
if (minPrice !== null && minPrice !== undefined) {
|
|
182
|
+
queryParams.min_price = minPrice;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const maxPrice = this.getParamValue(params.Params, 'MaxPrice');
|
|
186
|
+
if (maxPrice !== null && maxPrice !== undefined) {
|
|
187
|
+
queryParams.max_price = maxPrice;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Tags filter
|
|
191
|
+
const tags = this.getParamValue(params.Params, 'Tags');
|
|
192
|
+
if (tags) {
|
|
193
|
+
queryParams.tags = tags;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Instructor filter
|
|
197
|
+
const instructorId = this.getParamValue(params.Params, 'InstructorID');
|
|
198
|
+
if (instructorId) {
|
|
199
|
+
queryParams.instructor_id = instructorId;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Date filters
|
|
203
|
+
const createdAfter = this.getParamValue(params.Params, 'CreatedAfter');
|
|
204
|
+
if (createdAfter) {
|
|
205
|
+
queryParams.created_after = this.formatLearnWorldsDate(new Date(createdAfter));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const createdBefore = this.getParamValue(params.Params, 'CreatedBefore');
|
|
209
|
+
if (createdBefore) {
|
|
210
|
+
queryParams.created_before = this.formatLearnWorldsDate(new Date(createdBefore));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Sorting
|
|
214
|
+
const sortBy = this.getParamValue(params.Params, 'SortBy') || 'created';
|
|
215
|
+
const sortOrder = this.getParamValue(params.Params, 'SortOrder') || 'desc';
|
|
216
|
+
queryParams.sort = `${sortOrder === 'asc' ? '' : '-'}${sortBy}`;
|
|
217
|
+
|
|
218
|
+
// Include extra data
|
|
219
|
+
const includeEnrollmentStats = this.getParamValue(params.Params, 'IncludeEnrollmentStats') ?? true;
|
|
220
|
+
if (includeEnrollmentStats) {
|
|
221
|
+
queryParams.include = 'enrollment_stats';
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Limit for pagination
|
|
225
|
+
const maxResults = this.getParamValue(params.Params, 'MaxResults') || 100;
|
|
226
|
+
queryParams.limit = Math.min(maxResults, 100);
|
|
227
|
+
|
|
228
|
+
// Make the API request
|
|
229
|
+
const courses = await this.makeLearnWorldsPaginatedRequest<any>(
|
|
230
|
+
'courses',
|
|
231
|
+
queryParams,
|
|
232
|
+
contextUser
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
// Map to our interface
|
|
236
|
+
const mappedCourses: LearnWorldsCourse[] = courses.map(course => this.mapLearnWorldsCourse(course));
|
|
237
|
+
|
|
238
|
+
// Calculate summary
|
|
239
|
+
const summary = this.calculateCourseCatalogSummary(mappedCourses);
|
|
240
|
+
|
|
241
|
+
// Create output parameters
|
|
242
|
+
if (!params.Params.find(p => p.Name === 'Courses')) {
|
|
243
|
+
params.Params.push({
|
|
244
|
+
Name: 'Courses',
|
|
245
|
+
Type: 'Output',
|
|
246
|
+
Value: mappedCourses
|
|
247
|
+
});
|
|
248
|
+
} else {
|
|
249
|
+
params.Params.find(p => p.Name === 'Courses')!.Value = mappedCourses;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (!params.Params.find(p => p.Name === 'TotalCount')) {
|
|
253
|
+
params.Params.push({
|
|
254
|
+
Name: 'TotalCount',
|
|
255
|
+
Type: 'Output',
|
|
256
|
+
Value: mappedCourses.length
|
|
257
|
+
});
|
|
258
|
+
} else {
|
|
259
|
+
params.Params.find(p => p.Name === 'TotalCount')!.Value = mappedCourses.length;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (!params.Params.find(p => p.Name === 'Summary')) {
|
|
263
|
+
params.Params.push({
|
|
264
|
+
Name: 'Summary',
|
|
265
|
+
Type: 'Output',
|
|
266
|
+
Value: summary
|
|
267
|
+
});
|
|
268
|
+
} else {
|
|
269
|
+
params.Params.find(p => p.Name === 'Summary')!.Value = summary;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
Success: true,
|
|
274
|
+
ResultCode: 'SUCCESS',
|
|
275
|
+
Message: `Successfully retrieved ${mappedCourses.length} courses from LearnWorlds`
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
} catch (error) {
|
|
279
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
280
|
+
return {
|
|
281
|
+
Success: false,
|
|
282
|
+
ResultCode: 'ERROR',
|
|
283
|
+
Message: errorMessage
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Map LearnWorlds course data to our interface
|
|
290
|
+
*/
|
|
291
|
+
private mapLearnWorldsCourse(lwCourse: any): LearnWorldsCourse {
|
|
292
|
+
return {
|
|
293
|
+
id: lwCourse.id || lwCourse._id,
|
|
294
|
+
title: lwCourse.title,
|
|
295
|
+
subtitle: lwCourse.subtitle,
|
|
296
|
+
description: lwCourse.description,
|
|
297
|
+
shortDescription: lwCourse.short_description || lwCourse.excerpt,
|
|
298
|
+
|
|
299
|
+
status: this.mapCourseStatus(lwCourse.status),
|
|
300
|
+
visibility: this.mapCourseVisibility(lwCourse.visibility || lwCourse.access_type),
|
|
301
|
+
isActive: lwCourse.is_active !== false,
|
|
302
|
+
isFree: lwCourse.is_free || lwCourse.price === 0,
|
|
303
|
+
|
|
304
|
+
price: lwCourse.price,
|
|
305
|
+
currency: lwCourse.currency || 'USD',
|
|
306
|
+
originalPrice: lwCourse.original_price,
|
|
307
|
+
discountPercentage: this.calculateDiscountPercentage(lwCourse.original_price, lwCourse.price),
|
|
308
|
+
|
|
309
|
+
categoryId: lwCourse.category_id || lwCourse.category?.id,
|
|
310
|
+
categoryName: lwCourse.category_name || lwCourse.category?.name,
|
|
311
|
+
tags: lwCourse.tags || [],
|
|
312
|
+
level: this.mapCourseLevel(lwCourse.level || lwCourse.difficulty),
|
|
313
|
+
language: lwCourse.language || 'en',
|
|
314
|
+
duration: lwCourse.duration || lwCourse.estimated_duration,
|
|
315
|
+
|
|
316
|
+
thumbnailUrl: lwCourse.thumbnail_url || lwCourse.image,
|
|
317
|
+
coverImageUrl: lwCourse.cover_image_url || lwCourse.cover_image,
|
|
318
|
+
promoVideoUrl: lwCourse.promo_video_url || lwCourse.video_url,
|
|
319
|
+
|
|
320
|
+
instructorId: lwCourse.instructor_id || lwCourse.instructor?.id || lwCourse.author_id,
|
|
321
|
+
instructorName: lwCourse.instructor_name || lwCourse.instructor?.name || lwCourse.author_name,
|
|
322
|
+
instructorBio: lwCourse.instructor_bio || lwCourse.instructor?.bio,
|
|
323
|
+
instructorAvatarUrl: lwCourse.instructor_avatar || lwCourse.instructor?.avatar_url,
|
|
324
|
+
|
|
325
|
+
totalUnits: lwCourse.total_units || lwCourse.sections_count || 0,
|
|
326
|
+
totalLessons: lwCourse.total_lessons || lwCourse.lessons_count || 0,
|
|
327
|
+
totalQuizzes: lwCourse.total_quizzes || lwCourse.quizzes_count || 0,
|
|
328
|
+
totalAssignments: lwCourse.total_assignments || lwCourse.assignments_count || 0,
|
|
329
|
+
estimatedDuration: lwCourse.estimated_duration || lwCourse.total_duration,
|
|
330
|
+
|
|
331
|
+
totalEnrollments: lwCourse.total_enrollments || lwCourse.students_count || 0,
|
|
332
|
+
activeEnrollments: lwCourse.active_enrollments || lwCourse.active_students || 0,
|
|
333
|
+
completionRate: lwCourse.completion_rate || 0,
|
|
334
|
+
averageRating: lwCourse.average_rating || lwCourse.rating,
|
|
335
|
+
totalReviews: lwCourse.total_reviews || lwCourse.reviews_count,
|
|
336
|
+
|
|
337
|
+
createdAt: this.parseLearnWorldsDate(lwCourse.created || lwCourse.created_at),
|
|
338
|
+
updatedAt: this.parseLearnWorldsDate(lwCourse.updated || lwCourse.updated_at),
|
|
339
|
+
publishedAt: lwCourse.published_at ? this.parseLearnWorldsDate(lwCourse.published_at) : undefined,
|
|
340
|
+
enrollmentStartDate: lwCourse.enrollment_start ? this.parseLearnWorldsDate(lwCourse.enrollment_start) : undefined,
|
|
341
|
+
enrollmentEndDate: lwCourse.enrollment_end ? this.parseLearnWorldsDate(lwCourse.enrollment_end) : undefined,
|
|
342
|
+
|
|
343
|
+
requiresApproval: lwCourse.requires_approval || false,
|
|
344
|
+
hasPrerequisites: lwCourse.has_prerequisites || false,
|
|
345
|
+
prerequisites: lwCourse.prerequisites || [],
|
|
346
|
+
certificateAvailable: lwCourse.certificate_available || lwCourse.has_certificate || false,
|
|
347
|
+
|
|
348
|
+
objectives: lwCourse.objectives || lwCourse.learning_objectives || [],
|
|
349
|
+
targetAudience: lwCourse.target_audience || [],
|
|
350
|
+
requirements: lwCourse.requirements || lwCourse.prerequisites_text || []
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Map course status
|
|
356
|
+
*/
|
|
357
|
+
private mapCourseStatus(status: string): 'published' | 'draft' | 'coming_soon' {
|
|
358
|
+
const statusMap: Record<string, 'published' | 'draft' | 'coming_soon'> = {
|
|
359
|
+
'published': 'published',
|
|
360
|
+
'active': 'published',
|
|
361
|
+
'draft': 'draft',
|
|
362
|
+
'unpublished': 'draft',
|
|
363
|
+
'coming_soon': 'coming_soon',
|
|
364
|
+
'upcoming': 'coming_soon'
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
return statusMap[status?.toLowerCase()] || 'draft';
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Map course visibility
|
|
372
|
+
*/
|
|
373
|
+
private mapCourseVisibility(visibility: string): 'public' | 'private' | 'hidden' {
|
|
374
|
+
const visibilityMap: Record<string, 'public' | 'private' | 'hidden'> = {
|
|
375
|
+
'public': 'public',
|
|
376
|
+
'open': 'public',
|
|
377
|
+
'private': 'private',
|
|
378
|
+
'closed': 'private',
|
|
379
|
+
'hidden': 'hidden',
|
|
380
|
+
'unlisted': 'hidden'
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
return visibilityMap[visibility?.toLowerCase()] || 'public';
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Map course level
|
|
388
|
+
*/
|
|
389
|
+
private mapCourseLevel(level: string): 'beginner' | 'intermediate' | 'advanced' | 'all' {
|
|
390
|
+
const levelMap: Record<string, 'beginner' | 'intermediate' | 'advanced' | 'all'> = {
|
|
391
|
+
'beginner': 'beginner',
|
|
392
|
+
'basic': 'beginner',
|
|
393
|
+
'introductory': 'beginner',
|
|
394
|
+
'intermediate': 'intermediate',
|
|
395
|
+
'medium': 'intermediate',
|
|
396
|
+
'advanced': 'advanced',
|
|
397
|
+
'expert': 'advanced',
|
|
398
|
+
'all': 'all',
|
|
399
|
+
'any': 'all',
|
|
400
|
+
'mixed': 'all'
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
return levelMap[level?.toLowerCase()] || 'all';
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Calculate discount percentage
|
|
408
|
+
*/
|
|
409
|
+
private calculateDiscountPercentage(originalPrice?: number, currentPrice?: number): number | undefined {
|
|
410
|
+
if (!originalPrice || !currentPrice || originalPrice <= currentPrice) {
|
|
411
|
+
return undefined;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return Math.round(((originalPrice - currentPrice) / originalPrice) * 100);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Calculate course catalog summary
|
|
419
|
+
*/
|
|
420
|
+
private calculateCourseCatalogSummary(courses: LearnWorldsCourse[]): CourseCatalogSummary {
|
|
421
|
+
const summary: CourseCatalogSummary = {
|
|
422
|
+
totalCourses: courses.length,
|
|
423
|
+
publishedCourses: courses.filter(c => c.status === 'published').length,
|
|
424
|
+
draftCourses: courses.filter(c => c.status === 'draft').length,
|
|
425
|
+
freeCourses: courses.filter(c => c.isFree).length,
|
|
426
|
+
paidCourses: courses.filter(c => !c.isFree).length,
|
|
427
|
+
|
|
428
|
+
categoryCounts: {},
|
|
429
|
+
levelCounts: {},
|
|
430
|
+
languageCounts: {},
|
|
431
|
+
|
|
432
|
+
enrollmentStats: {
|
|
433
|
+
totalEnrollments: 0,
|
|
434
|
+
averageEnrollmentsPerCourse: 0,
|
|
435
|
+
mostPopularCourses: []
|
|
436
|
+
},
|
|
437
|
+
|
|
438
|
+
priceStats: {
|
|
439
|
+
averagePrice: 0,
|
|
440
|
+
minPrice: 0,
|
|
441
|
+
maxPrice: 0,
|
|
442
|
+
currency: 'USD'
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
// Count by category
|
|
447
|
+
courses.forEach(course => {
|
|
448
|
+
if (course.categoryName) {
|
|
449
|
+
summary.categoryCounts[course.categoryName] =
|
|
450
|
+
(summary.categoryCounts[course.categoryName] || 0) + 1;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// Count by level
|
|
454
|
+
if (course.level) {
|
|
455
|
+
summary.levelCounts[course.level] =
|
|
456
|
+
(summary.levelCounts[course.level] || 0) + 1;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// Count by language
|
|
460
|
+
if (course.language) {
|
|
461
|
+
summary.languageCounts[course.language] =
|
|
462
|
+
(summary.languageCounts[course.language] || 0) + 1;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Accumulate enrollment stats
|
|
466
|
+
summary.enrollmentStats.totalEnrollments += course.totalEnrollments;
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
// Calculate averages
|
|
470
|
+
if (courses.length > 0) {
|
|
471
|
+
summary.enrollmentStats.averageEnrollmentsPerCourse =
|
|
472
|
+
Math.round(summary.enrollmentStats.totalEnrollments / courses.length);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// Find most popular courses
|
|
476
|
+
summary.enrollmentStats.mostPopularCourses = courses
|
|
477
|
+
.filter(c => c.totalEnrollments > 0)
|
|
478
|
+
.sort((a, b) => b.totalEnrollments - a.totalEnrollments)
|
|
479
|
+
.slice(0, 5)
|
|
480
|
+
.map(c => ({
|
|
481
|
+
id: c.id,
|
|
482
|
+
title: c.title,
|
|
483
|
+
enrollments: c.totalEnrollments
|
|
484
|
+
}));
|
|
485
|
+
|
|
486
|
+
// Calculate price statistics for paid courses
|
|
487
|
+
const paidCourses = courses.filter(c => !c.isFree && c.price !== undefined);
|
|
488
|
+
if (paidCourses.length > 0) {
|
|
489
|
+
const prices = paidCourses.map(c => c.price!);
|
|
490
|
+
summary.priceStats = {
|
|
491
|
+
averagePrice: Math.round(prices.reduce((sum, p) => sum + p, 0) / prices.length),
|
|
492
|
+
minPrice: Math.min(...prices),
|
|
493
|
+
maxPrice: Math.max(...prices),
|
|
494
|
+
currency: paidCourses[0].currency || 'USD'
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return summary;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Define the parameters for this action
|
|
503
|
+
*/
|
|
504
|
+
public get Params(): ActionParam[] {
|
|
505
|
+
const baseParams = this.getCommonLMSParams();
|
|
506
|
+
|
|
507
|
+
const specificParams: ActionParam[] = [
|
|
508
|
+
{
|
|
509
|
+
Name: 'SearchText',
|
|
510
|
+
Type: 'Input',
|
|
511
|
+
Value: null
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
Name: 'Status',
|
|
515
|
+
Type: 'Input',
|
|
516
|
+
Value: null
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
Name: 'CategoryID',
|
|
520
|
+
Type: 'Input',
|
|
521
|
+
Value: null
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
Name: 'Level',
|
|
525
|
+
Type: 'Input',
|
|
526
|
+
Value: null
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
Name: 'Language',
|
|
530
|
+
Type: 'Input',
|
|
531
|
+
Value: null
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
Name: 'OnlyFree',
|
|
535
|
+
Type: 'Input',
|
|
536
|
+
Value: false
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
Name: 'MinPrice',
|
|
540
|
+
Type: 'Input',
|
|
541
|
+
Value: null
|
|
542
|
+
},
|
|
543
|
+
{
|
|
544
|
+
Name: 'MaxPrice',
|
|
545
|
+
Type: 'Input',
|
|
546
|
+
Value: null
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
Name: 'Tags',
|
|
550
|
+
Type: 'Input',
|
|
551
|
+
Value: null
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
Name: 'InstructorID',
|
|
555
|
+
Type: 'Input',
|
|
556
|
+
Value: null
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
Name: 'CreatedAfter',
|
|
560
|
+
Type: 'Input',
|
|
561
|
+
Value: null
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
Name: 'CreatedBefore',
|
|
565
|
+
Type: 'Input',
|
|
566
|
+
Value: null
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
Name: 'SortBy',
|
|
570
|
+
Type: 'Input',
|
|
571
|
+
Value: 'created'
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
Name: 'SortOrder',
|
|
575
|
+
Type: 'Input',
|
|
576
|
+
Value: 'desc'
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
Name: 'IncludeEnrollmentStats',
|
|
580
|
+
Type: 'Input',
|
|
581
|
+
Value: true
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
Name: 'MaxResults',
|
|
585
|
+
Type: 'Input',
|
|
586
|
+
Value: 100
|
|
587
|
+
}
|
|
588
|
+
];
|
|
589
|
+
|
|
590
|
+
return [...baseParams, ...specificParams];
|
|
591
|
+
}
|
|
592
|
+
}
|