@memberjunction/actions-bizapps-lms 2.55.0 → 2.57.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 +1 -1
- package/CHANGELOG.md +26 -0
- package/README.md +321 -0
- package/dist/providers/learnworlds/actions/create-user.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/create-user.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/create-user.action.js +243 -0
- package/dist/providers/learnworlds/actions/create-user.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.js +208 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.js +301 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts +36 -0
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js +333 -0
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts +28 -0
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-course-details.action.js +237 -0
- package/dist/providers/learnworlds/actions/get-course-details.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts +28 -0
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js +368 -0
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js +228 -0
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/index.d.ts +8 -0
- package/dist/providers/learnworlds/actions/index.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/index.js +8 -0
- package/dist/providers/learnworlds/actions/index.js.map +1 -1
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts +20 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.js +254 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.js.map +1 -0
- package/package.json +6 -6
- package/src/providers/learnworlds/actions/create-user.action.ts +249 -0
- package/src/providers/learnworlds/actions/enroll-user.action.ts +233 -0
- package/src/providers/learnworlds/actions/get-certificates.action.ts +332 -0
- package/src/providers/learnworlds/actions/get-course-analytics.action.ts +359 -0
- package/src/providers/learnworlds/actions/get-course-details.action.ts +267 -0
- package/src/providers/learnworlds/actions/get-quiz-results.action.ts +399 -0
- package/src/providers/learnworlds/actions/get-user-enrollments.action.ts +242 -0
- package/src/providers/learnworlds/actions/index.ts +9 -1
- package/src/providers/learnworlds/actions/update-user-progress.action.ts +277 -0
|
@@ -0,0 +1,359 @@
|
|
|
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
|
+
* Action to retrieve comprehensive analytics for a LearnWorlds course
|
|
7
|
+
*/
|
|
8
|
+
@RegisterClass(LearnWorldsBaseAction, 'GetCourseAnalyticsAction')
|
|
9
|
+
export class GetCourseAnalyticsAction extends LearnWorldsBaseAction {
|
|
10
|
+
/**
|
|
11
|
+
* Get course performance analytics
|
|
12
|
+
*/
|
|
13
|
+
public async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
14
|
+
const { Params, ContextUser } = params;
|
|
15
|
+
this.params = Params;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Extract and validate parameters
|
|
19
|
+
const courseId = this.getParamValue(Params, 'CourseID');
|
|
20
|
+
const dateFrom = this.getParamValue(Params, 'DateFrom');
|
|
21
|
+
const dateTo = this.getParamValue(Params, 'DateTo');
|
|
22
|
+
const includeUserBreakdown = this.getParamValue(Params, 'IncludeUserBreakdown') === true;
|
|
23
|
+
const includeModuleStats = this.getParamValue(Params, 'IncludeModuleStats') !== false;
|
|
24
|
+
const includeRevenue = this.getParamValue(Params, 'IncludeRevenue') !== false;
|
|
25
|
+
|
|
26
|
+
if (!courseId) {
|
|
27
|
+
return {
|
|
28
|
+
Success: false,
|
|
29
|
+
ResultCode: 'VALIDATION_ERROR',
|
|
30
|
+
Message: 'CourseID is required',
|
|
31
|
+
Params
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
// Build query parameters
|
|
37
|
+
const queryParams: any = {};
|
|
38
|
+
if (dateFrom) {
|
|
39
|
+
queryParams.date_from = new Date(dateFrom).toISOString().split('T')[0];
|
|
40
|
+
}
|
|
41
|
+
if (dateTo) {
|
|
42
|
+
queryParams.date_to = new Date(dateTo).toISOString().split('T')[0];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Build query string
|
|
46
|
+
const queryString = Object.keys(queryParams).length > 0
|
|
47
|
+
? '?' + new URLSearchParams(queryParams).toString()
|
|
48
|
+
: '';
|
|
49
|
+
|
|
50
|
+
// Get course analytics
|
|
51
|
+
const analyticsResponse = await this.makeLearnWorldsRequest(
|
|
52
|
+
`/courses/${courseId}/analytics${queryString}`,
|
|
53
|
+
'GET',
|
|
54
|
+
null,
|
|
55
|
+
ContextUser
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
if (!analyticsResponse.success) {
|
|
59
|
+
return {
|
|
60
|
+
Success: false,
|
|
61
|
+
ResultCode: 'API_ERROR',
|
|
62
|
+
Message: analyticsResponse.message || 'Failed to retrieve analytics',
|
|
63
|
+
Params
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const analyticsData = analyticsResponse.data || {};
|
|
68
|
+
|
|
69
|
+
// Format analytics data
|
|
70
|
+
const analytics: any = {
|
|
71
|
+
courseId: courseId,
|
|
72
|
+
period: {
|
|
73
|
+
from: dateFrom || 'all-time',
|
|
74
|
+
to: dateTo || 'current'
|
|
75
|
+
},
|
|
76
|
+
enrollment: {
|
|
77
|
+
totalEnrollments: analyticsData.total_enrollments || 0,
|
|
78
|
+
newEnrollments: analyticsData.new_enrollments || 0,
|
|
79
|
+
activeStudents: analyticsData.active_students || 0,
|
|
80
|
+
enrollmentTrend: analyticsData.enrollment_trend || []
|
|
81
|
+
},
|
|
82
|
+
progress: {
|
|
83
|
+
averageProgressPercentage: analyticsData.average_progress || 0,
|
|
84
|
+
completionRate: analyticsData.completion_rate || 0,
|
|
85
|
+
totalCompletions: analyticsData.total_completions || 0,
|
|
86
|
+
inProgressCount: analyticsData.in_progress_count || 0,
|
|
87
|
+
notStartedCount: analyticsData.not_started_count || 0,
|
|
88
|
+
dropoutRate: analyticsData.dropout_rate || 0
|
|
89
|
+
},
|
|
90
|
+
engagement: {
|
|
91
|
+
averageTimeSpent: analyticsData.average_time_spent || 0,
|
|
92
|
+
averageTimeSpentText: this.formatDuration(analyticsData.average_time_spent || 0),
|
|
93
|
+
totalTimeSpent: analyticsData.total_time_spent || 0,
|
|
94
|
+
totalTimeSpentText: this.formatDuration(analyticsData.total_time_spent || 0),
|
|
95
|
+
averageSessionDuration: analyticsData.average_session_duration || 0,
|
|
96
|
+
lastActivityDate: analyticsData.last_activity_date,
|
|
97
|
+
dailyActiveUsers: analyticsData.daily_active_users || []
|
|
98
|
+
},
|
|
99
|
+
performance: {
|
|
100
|
+
averageQuizScore: analyticsData.average_quiz_score || 0,
|
|
101
|
+
passRate: analyticsData.pass_rate || 0,
|
|
102
|
+
certificatesIssued: analyticsData.certificates_issued || 0,
|
|
103
|
+
averageTimeToComplete: analyticsData.average_time_to_complete || 0,
|
|
104
|
+
averageTimeToCompleteText: this.formatDuration(analyticsData.average_time_to_complete || 0)
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Get revenue analytics if requested
|
|
109
|
+
if (includeRevenue) {
|
|
110
|
+
const revenueResponse = await this.makeLearnWorldsRequest(
|
|
111
|
+
`/courses/${courseId}/revenue${queryString}`,
|
|
112
|
+
'GET',
|
|
113
|
+
null,
|
|
114
|
+
ContextUser
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
if (revenueResponse.success && revenueResponse.data) {
|
|
118
|
+
analytics.revenue = {
|
|
119
|
+
totalRevenue: revenueResponse.data.total_revenue || 0,
|
|
120
|
+
currency: revenueResponse.data.currency || 'USD',
|
|
121
|
+
averageOrderValue: revenueResponse.data.average_order_value || 0,
|
|
122
|
+
totalOrders: revenueResponse.data.total_orders || 0,
|
|
123
|
+
revenueTrend: revenueResponse.data.revenue_trend || [],
|
|
124
|
+
topMarkets: revenueResponse.data.top_markets || []
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Get module/lesson stats if requested
|
|
130
|
+
if (includeModuleStats) {
|
|
131
|
+
const moduleStatsResponse = await this.makeLearnWorldsRequest(
|
|
132
|
+
`/courses/${courseId}/modules/analytics`,
|
|
133
|
+
'GET',
|
|
134
|
+
null,
|
|
135
|
+
ContextUser
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
if (moduleStatsResponse.success && moduleStatsResponse.data) {
|
|
139
|
+
analytics.moduleStats = this.formatModuleStats(moduleStatsResponse.data.data || moduleStatsResponse.data);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Get user breakdown if requested
|
|
144
|
+
if (includeUserBreakdown) {
|
|
145
|
+
const enrollmentQueryString = '?' + new URLSearchParams({ limit: '1000', include: 'progress' }).toString();
|
|
146
|
+
const userBreakdownResponse = await this.makeLearnWorldsRequest(
|
|
147
|
+
`/courses/${courseId}/enrollments${enrollmentQueryString}`,
|
|
148
|
+
'GET',
|
|
149
|
+
null,
|
|
150
|
+
ContextUser
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
if (userBreakdownResponse.success && userBreakdownResponse.data) {
|
|
154
|
+
const enrollments = userBreakdownResponse.data.data || userBreakdownResponse.data;
|
|
155
|
+
analytics.userBreakdown = this.calculateUserBreakdown(enrollments);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Create summary
|
|
160
|
+
const summary = {
|
|
161
|
+
courseId: courseId,
|
|
162
|
+
period: analytics.period,
|
|
163
|
+
keyMetrics: {
|
|
164
|
+
totalEnrollments: analytics.enrollment.totalEnrollments,
|
|
165
|
+
completionRate: analytics.progress.completionRate,
|
|
166
|
+
averageProgress: analytics.progress.averageProgressPercentage,
|
|
167
|
+
activeStudents: analytics.enrollment.activeStudents,
|
|
168
|
+
averageTimeSpent: analytics.engagement.averageTimeSpentText,
|
|
169
|
+
certificatesIssued: analytics.performance.certificatesIssued
|
|
170
|
+
},
|
|
171
|
+
trends: {
|
|
172
|
+
enrollmentGrowth: this.calculateGrowthRate(analytics.enrollment.enrollmentTrend),
|
|
173
|
+
engagementTrend: this.calculateEngagementTrend(analytics.engagement.dailyActiveUsers),
|
|
174
|
+
completionTrend: 'stable' // Would calculate from historical data
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// Update output parameters
|
|
179
|
+
const outputParams = [...Params];
|
|
180
|
+
const courseAnalyticsParam = outputParams.find(p => p.Name === 'CourseAnalytics');
|
|
181
|
+
if (courseAnalyticsParam) {
|
|
182
|
+
courseAnalyticsParam.Value = analytics;
|
|
183
|
+
}
|
|
184
|
+
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
185
|
+
if (summaryParam) {
|
|
186
|
+
summaryParam.Value = summary;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
Success: true,
|
|
191
|
+
ResultCode: 'SUCCESS',
|
|
192
|
+
Message: 'Course analytics retrieved successfully',
|
|
193
|
+
Params: outputParams
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
} catch (error) {
|
|
197
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
198
|
+
return {
|
|
199
|
+
Success: false,
|
|
200
|
+
ResultCode: 'EXECUTION_ERROR',
|
|
201
|
+
Message: `Error retrieving course analytics: ${errorMessage}`,
|
|
202
|
+
Params
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Format module statistics
|
|
209
|
+
*/
|
|
210
|
+
private formatModuleStats(modules: any[]): any[] {
|
|
211
|
+
return modules.map(module => ({
|
|
212
|
+
moduleId: module.id,
|
|
213
|
+
moduleTitle: module.title,
|
|
214
|
+
completionRate: module.completion_rate || 0,
|
|
215
|
+
averageProgress: module.average_progress || 0,
|
|
216
|
+
averageTimeSpent: module.average_time_spent || 0,
|
|
217
|
+
averageTimeSpentText: this.formatDuration(module.average_time_spent || 0),
|
|
218
|
+
studentsStarted: module.students_started || 0,
|
|
219
|
+
studentsCompleted: module.students_completed || 0,
|
|
220
|
+
lessons: module.lessons?.map((lesson: any) => ({
|
|
221
|
+
lessonId: lesson.id,
|
|
222
|
+
lessonTitle: lesson.title,
|
|
223
|
+
completionRate: lesson.completion_rate || 0,
|
|
224
|
+
averageTimeSpent: lesson.average_time_spent || 0,
|
|
225
|
+
viewCount: lesson.view_count || 0
|
|
226
|
+
})) || []
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Calculate user breakdown statistics
|
|
232
|
+
*/
|
|
233
|
+
private calculateUserBreakdown(enrollments: any[]): any {
|
|
234
|
+
const progressBuckets = {
|
|
235
|
+
notStarted: 0,
|
|
236
|
+
under25: 0,
|
|
237
|
+
between25And50: 0,
|
|
238
|
+
between50And75: 0,
|
|
239
|
+
between75And99: 0,
|
|
240
|
+
completed: 0
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
enrollments.forEach(enrollment => {
|
|
244
|
+
const progress = enrollment.progress_percentage || 0;
|
|
245
|
+
if (progress === 0) progressBuckets.notStarted++;
|
|
246
|
+
else if (progress < 25) progressBuckets.under25++;
|
|
247
|
+
else if (progress < 50) progressBuckets.between25And50++;
|
|
248
|
+
else if (progress < 75) progressBuckets.between50And75++;
|
|
249
|
+
else if (progress < 100) progressBuckets.between75And99++;
|
|
250
|
+
else progressBuckets.completed++;
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
total: enrollments.length,
|
|
255
|
+
progressDistribution: progressBuckets,
|
|
256
|
+
percentageDistribution: {
|
|
257
|
+
notStarted: (progressBuckets.notStarted / enrollments.length * 100).toFixed(1),
|
|
258
|
+
under25: (progressBuckets.under25 / enrollments.length * 100).toFixed(1),
|
|
259
|
+
between25And50: (progressBuckets.between25And50 / enrollments.length * 100).toFixed(1),
|
|
260
|
+
between50And75: (progressBuckets.between50And75 / enrollments.length * 100).toFixed(1),
|
|
261
|
+
between75And99: (progressBuckets.between75And99 / enrollments.length * 100).toFixed(1),
|
|
262
|
+
completed: (progressBuckets.completed / enrollments.length * 100).toFixed(1)
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Calculate growth rate from trend data
|
|
269
|
+
*/
|
|
270
|
+
private calculateGrowthRate(trend: any[]): string {
|
|
271
|
+
if (!trend || trend.length < 2) return 'insufficient-data';
|
|
272
|
+
|
|
273
|
+
const recent = trend[trend.length - 1]?.value || 0;
|
|
274
|
+
const previous = trend[trend.length - 2]?.value || 0;
|
|
275
|
+
|
|
276
|
+
if (previous === 0) return 'new';
|
|
277
|
+
|
|
278
|
+
const growthRate = ((recent - previous) / previous) * 100;
|
|
279
|
+
if (growthRate > 10) return 'high-growth';
|
|
280
|
+
if (growthRate > 0) return 'growing';
|
|
281
|
+
if (growthRate === 0) return 'stable';
|
|
282
|
+
return 'declining';
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Calculate engagement trend
|
|
287
|
+
*/
|
|
288
|
+
private calculateEngagementTrend(dailyActiveUsers: any[]): string {
|
|
289
|
+
if (!dailyActiveUsers || dailyActiveUsers.length < 7) return 'insufficient-data';
|
|
290
|
+
|
|
291
|
+
// Simple trend calculation based on last 7 days
|
|
292
|
+
const recentAvg = dailyActiveUsers.slice(-7).reduce((sum, day) => sum + (day.value || 0), 0) / 7;
|
|
293
|
+
const previousAvg = dailyActiveUsers.slice(-14, -7).reduce((sum, day) => sum + (day.value || 0), 0) / 7;
|
|
294
|
+
|
|
295
|
+
if (previousAvg === 0) return 'new';
|
|
296
|
+
|
|
297
|
+
const change = ((recentAvg - previousAvg) / previousAvg) * 100;
|
|
298
|
+
if (change > 5) return 'increasing';
|
|
299
|
+
if (change < -5) return 'decreasing';
|
|
300
|
+
return 'stable';
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Define the parameters this action expects
|
|
305
|
+
*/
|
|
306
|
+
public get Params(): ActionParam[] {
|
|
307
|
+
const baseParams = this.getCommonLMSParams();
|
|
308
|
+
const specificParams: ActionParam[] = [
|
|
309
|
+
{
|
|
310
|
+
Name: 'CourseID',
|
|
311
|
+
Type: 'Input',
|
|
312
|
+
Value: null
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
Name: 'DateFrom',
|
|
316
|
+
Type: 'Input',
|
|
317
|
+
Value: null
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
Name: 'DateTo',
|
|
321
|
+
Type: 'Input',
|
|
322
|
+
Value: null
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
Name: 'IncludeUserBreakdown',
|
|
326
|
+
Type: 'Input',
|
|
327
|
+
Value: false
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
Name: 'IncludeModuleStats',
|
|
331
|
+
Type: 'Input',
|
|
332
|
+
Value: true
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
Name: 'IncludeRevenue',
|
|
336
|
+
Type: 'Input',
|
|
337
|
+
Value: true
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
Name: 'CourseAnalytics',
|
|
341
|
+
Type: 'Output',
|
|
342
|
+
Value: null
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
Name: 'Summary',
|
|
346
|
+
Type: 'Output',
|
|
347
|
+
Value: null
|
|
348
|
+
}
|
|
349
|
+
];
|
|
350
|
+
return [...baseParams, ...specificParams];
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Metadata about this action
|
|
355
|
+
*/
|
|
356
|
+
public get Description(): string {
|
|
357
|
+
return 'Retrieves comprehensive analytics and performance metrics for a LearnWorlds course';
|
|
358
|
+
}
|
|
359
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
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
|
+
* Action to retrieve comprehensive course details including curriculum structure
|
|
7
|
+
*/
|
|
8
|
+
@RegisterClass(LearnWorldsBaseAction, 'GetLearnWorldsCourseDetailsAction')
|
|
9
|
+
export class GetLearnWorldsCourseDetailsAction extends LearnWorldsBaseAction {
|
|
10
|
+
/**
|
|
11
|
+
* Get comprehensive details about a specific course including curriculum
|
|
12
|
+
*/
|
|
13
|
+
public async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
14
|
+
const { Params, ContextUser } = params;
|
|
15
|
+
this.params = Params;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Extract and validate parameters
|
|
19
|
+
const courseId = this.getParamValue(Params, 'CourseID');
|
|
20
|
+
const includeModules = this.getParamValue(Params, 'IncludeModules') !== false;
|
|
21
|
+
const includeInstructors = this.getParamValue(Params, 'IncludeInstructors') !== false;
|
|
22
|
+
const includeStats = this.getParamValue(Params, 'IncludeStats') !== false;
|
|
23
|
+
|
|
24
|
+
if (!courseId) {
|
|
25
|
+
return {
|
|
26
|
+
Success: false,
|
|
27
|
+
ResultCode: 'VALIDATION_ERROR',
|
|
28
|
+
Message: 'CourseID is required',
|
|
29
|
+
Params
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
// Get course details
|
|
35
|
+
const courseResponse = await this.makeLearnWorldsRequest(
|
|
36
|
+
`/courses/${courseId}`,
|
|
37
|
+
'GET',
|
|
38
|
+
null,
|
|
39
|
+
ContextUser
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (!courseResponse.success || !courseResponse.data) {
|
|
43
|
+
return {
|
|
44
|
+
Success: false,
|
|
45
|
+
ResultCode: 'API_ERROR',
|
|
46
|
+
Message: courseResponse.message || 'Failed to retrieve course details',
|
|
47
|
+
Params
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const course = courseResponse.data;
|
|
52
|
+
const courseDetails: any = {
|
|
53
|
+
id: course.id,
|
|
54
|
+
title: course.title,
|
|
55
|
+
slug: course.slug,
|
|
56
|
+
description: course.description,
|
|
57
|
+
shortDescription: course.short_description,
|
|
58
|
+
status: course.status || 'published',
|
|
59
|
+
price: course.price || 0,
|
|
60
|
+
originalPrice: course.original_price,
|
|
61
|
+
currency: course.currency || 'USD',
|
|
62
|
+
level: course.level || 'all',
|
|
63
|
+
language: course.language || 'en',
|
|
64
|
+
duration: course.duration,
|
|
65
|
+
durationText: this.formatDuration(course.duration),
|
|
66
|
+
totalEnrollments: course.total_enrollments || 0,
|
|
67
|
+
averageRating: course.average_rating,
|
|
68
|
+
totalRatings: course.total_ratings || 0,
|
|
69
|
+
tags: course.tags || [],
|
|
70
|
+
categories: course.categories || [],
|
|
71
|
+
imageUrl: course.image_url,
|
|
72
|
+
videoUrl: course.video_url,
|
|
73
|
+
certificateEnabled: course.certificate_enabled || false,
|
|
74
|
+
createdAt: course.created_at,
|
|
75
|
+
updatedAt: course.updated_at,
|
|
76
|
+
publishedAt: course.published_at
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Get curriculum/modules if requested
|
|
80
|
+
if (includeModules) {
|
|
81
|
+
const modulesResponse = await this.makeLearnWorldsRequest(
|
|
82
|
+
`/courses/${courseId}/sections`,
|
|
83
|
+
'GET',
|
|
84
|
+
null,
|
|
85
|
+
ContextUser
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
if (modulesResponse.success && modulesResponse.data) {
|
|
89
|
+
courseDetails.modules = this.formatModules(modulesResponse.data.data || modulesResponse.data);
|
|
90
|
+
courseDetails.totalModules = courseDetails.modules.length;
|
|
91
|
+
courseDetails.totalLessons = courseDetails.modules.reduce((sum: number, module: any) =>
|
|
92
|
+
sum + (module.lessons?.length || 0), 0
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Get instructors if requested
|
|
98
|
+
if (includeInstructors) {
|
|
99
|
+
const instructorsResponse = await this.makeLearnWorldsRequest(
|
|
100
|
+
`/courses/${courseId}/instructors`,
|
|
101
|
+
'GET',
|
|
102
|
+
null,
|
|
103
|
+
ContextUser
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
if (instructorsResponse.success && instructorsResponse.data) {
|
|
107
|
+
courseDetails.instructors = this.formatInstructors(instructorsResponse.data.data || instructorsResponse.data);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Get additional stats if requested
|
|
112
|
+
if (includeStats) {
|
|
113
|
+
const statsResponse = await this.makeLearnWorldsRequest(
|
|
114
|
+
`/courses/${courseId}/stats`,
|
|
115
|
+
'GET',
|
|
116
|
+
null,
|
|
117
|
+
ContextUser
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
if (statsResponse.success && statsResponse.data) {
|
|
121
|
+
courseDetails.stats = {
|
|
122
|
+
totalEnrollments: statsResponse.data.total_enrollments || courseDetails.totalEnrollments,
|
|
123
|
+
activeStudents: statsResponse.data.active_students || 0,
|
|
124
|
+
completionRate: statsResponse.data.completion_rate || 0,
|
|
125
|
+
averageProgressPercentage: statsResponse.data.average_progress || 0,
|
|
126
|
+
averageTimeToComplete: statsResponse.data.average_time_to_complete,
|
|
127
|
+
totalRevenue: statsResponse.data.total_revenue || 0
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Create summary
|
|
133
|
+
const summary = {
|
|
134
|
+
courseId: courseDetails.id,
|
|
135
|
+
title: courseDetails.title,
|
|
136
|
+
status: courseDetails.status,
|
|
137
|
+
level: courseDetails.level,
|
|
138
|
+
duration: courseDetails.durationText,
|
|
139
|
+
totalModules: courseDetails.totalModules || 0,
|
|
140
|
+
totalLessons: courseDetails.totalLessons || 0,
|
|
141
|
+
totalEnrollments: courseDetails.totalEnrollments,
|
|
142
|
+
averageRating: courseDetails.averageRating || 0,
|
|
143
|
+
certificateEnabled: courseDetails.certificateEnabled,
|
|
144
|
+
price: courseDetails.price,
|
|
145
|
+
currency: courseDetails.currency
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// Update output parameters
|
|
149
|
+
const outputParams = [...Params];
|
|
150
|
+
const courseDetailsParam = outputParams.find(p => p.Name === 'CourseDetails');
|
|
151
|
+
if (courseDetailsParam) {
|
|
152
|
+
courseDetailsParam.Value = courseDetails;
|
|
153
|
+
}
|
|
154
|
+
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
155
|
+
if (summaryParam) {
|
|
156
|
+
summaryParam.Value = summary;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
Success: true,
|
|
161
|
+
ResultCode: 'SUCCESS',
|
|
162
|
+
Message: 'Course details retrieved successfully',
|
|
163
|
+
Params: outputParams
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
} catch (error) {
|
|
167
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
168
|
+
return {
|
|
169
|
+
Success: false,
|
|
170
|
+
ResultCode: 'EXECUTION_ERROR',
|
|
171
|
+
Message: `Error retrieving course details: ${errorMessage}`,
|
|
172
|
+
Params
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Format course modules/sections data
|
|
179
|
+
*/
|
|
180
|
+
private formatModules(modules: any[]): any[] {
|
|
181
|
+
return modules.map(module => ({
|
|
182
|
+
id: module.id,
|
|
183
|
+
title: module.title,
|
|
184
|
+
description: module.description,
|
|
185
|
+
order: module.order || module.position || 0,
|
|
186
|
+
duration: module.duration,
|
|
187
|
+
durationText: this.formatDuration(module.duration),
|
|
188
|
+
totalLessons: module.total_lessons || module.lessons?.length || 0,
|
|
189
|
+
lessons: module.lessons?.map((lesson: any) => ({
|
|
190
|
+
id: lesson.id,
|
|
191
|
+
title: lesson.title,
|
|
192
|
+
type: lesson.type || 'video',
|
|
193
|
+
duration: lesson.duration,
|
|
194
|
+
durationText: this.formatDuration(lesson.duration),
|
|
195
|
+
order: lesson.order || lesson.position || 0,
|
|
196
|
+
isFree: lesson.is_free || false,
|
|
197
|
+
hasVideo: lesson.has_video || false,
|
|
198
|
+
hasQuiz: lesson.has_quiz || false,
|
|
199
|
+
hasAssignment: lesson.has_assignment || false
|
|
200
|
+
})) || []
|
|
201
|
+
})).sort((a, b) => a.order - b.order);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Format instructor data
|
|
206
|
+
*/
|
|
207
|
+
private formatInstructors(instructors: any[]): any[] {
|
|
208
|
+
return instructors.map(instructor => ({
|
|
209
|
+
id: instructor.id,
|
|
210
|
+
name: instructor.name || `${instructor.first_name || ''} ${instructor.last_name || ''}`.trim(),
|
|
211
|
+
email: instructor.email,
|
|
212
|
+
bio: instructor.bio,
|
|
213
|
+
title: instructor.title,
|
|
214
|
+
imageUrl: instructor.image_url || instructor.avatar_url,
|
|
215
|
+
totalCourses: instructor.total_courses || 0,
|
|
216
|
+
totalStudents: instructor.total_students || 0,
|
|
217
|
+
averageRating: instructor.average_rating || 0
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Define the parameters this action expects
|
|
223
|
+
*/
|
|
224
|
+
public get Params(): ActionParam[] {
|
|
225
|
+
const baseParams = this.getCommonLMSParams();
|
|
226
|
+
const specificParams: ActionParam[] = [
|
|
227
|
+
{
|
|
228
|
+
Name: 'CourseID',
|
|
229
|
+
Type: 'Input',
|
|
230
|
+
Value: null
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
Name: 'IncludeModules',
|
|
234
|
+
Type: 'Input',
|
|
235
|
+
Value: true
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
Name: 'IncludeInstructors',
|
|
239
|
+
Type: 'Input',
|
|
240
|
+
Value: true
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
Name: 'IncludeStats',
|
|
244
|
+
Type: 'Input',
|
|
245
|
+
Value: true
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
Name: 'CourseDetails',
|
|
249
|
+
Type: 'Output',
|
|
250
|
+
Value: null
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
Name: 'Summary',
|
|
254
|
+
Type: 'Output',
|
|
255
|
+
Value: null
|
|
256
|
+
}
|
|
257
|
+
];
|
|
258
|
+
return [...baseParams, ...specificParams];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Metadata about this action
|
|
263
|
+
*/
|
|
264
|
+
public get Description(): string {
|
|
265
|
+
return 'Retrieves comprehensive details about a specific LearnWorlds course including curriculum structure';
|
|
266
|
+
}
|
|
267
|
+
}
|