Skip to content

Commit 854eb7f

Browse files
authored
Merge pull request #1084 from TechnologyEnhancedLearning/Develop/POC/TD-5285_retrieve_enrolled_courses_from_moodle_for_user
TD- 5285 retrieve enrolled courses from moodle for user and display in LH
2 parents c83d6b5 + bee6cdb commit 854eb7f

23 files changed

+10502
-345
lines changed

LearningHub.Nhs.WebUI/Controllers/BaseController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Net.Http;
44
using LearningHub.Nhs.Models.Extensions;
55
using LearningHub.Nhs.WebUI.Configuration;
6+
using LearningHub.Nhs.WebUI.Extensions;
67
using LearningHub.Nhs.WebUI.Filters;
78
using LearningHub.Nhs.WebUI.Helpers;
89
using LearningHub.Nhs.WebUI.Models;
@@ -76,6 +77,11 @@ protected BaseController(
7677
/// </summary>
7778
protected int CurrentUserId => this.User.Identity.GetCurrentUserId();
7879

80+
/// <summary>
81+
/// Gets the CurrentUserId.
82+
/// </summary>
83+
protected int CurrentMoodleUserId => this.User.Identity.GetMoodleUserId();
84+
7985
/// <summary>
8086
/// The OnActionExecuting.
8187
/// </summary>

LearningHub.Nhs.WebUI/Controllers/HomeController.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,23 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
214214
var resourcesTask = this.dashboardService.GetResourcesAsync(resourceDashboard, 1);
215215
var cataloguesTask = this.dashboardService.GetCataloguesAsync(catalogueDashboard, 1);
216216

217+
var enrolledCoursesTask = Task.FromResult(new List<MoodleCourseResponseViewModel>());
218+
var enableMoodle = Task.Run(() => this.featureManager.IsEnabledAsync(FeatureFlags.EnableMoodle)).Result;
219+
this.ViewBag.EnableMoodle = enableMoodle;
220+
this.ViewBag.ValidMoodleUser = this.CurrentMoodleUserId > 0;
221+
if (enableMoodle && myLearningDashboard == "my-enrolled-courses")
222+
{
223+
enrolledCoursesTask = this.dashboardService.GetEnrolledCoursesFromMoodleAsync(this.CurrentMoodleUserId, 1);
224+
}
225+
217226
await Task.WhenAll(learningTask, resourcesTask, cataloguesTask);
218227

219228
var model = new DashboardViewModel()
220229
{
221230
MyLearnings = await learningTask,
222231
Resources = await resourcesTask,
223232
Catalogues = await cataloguesTask,
233+
EnrolledCourses = await enrolledCoursesTask,
224234
};
225235

226236
if (!string.IsNullOrEmpty(this.Request.Query["preview"]) && Convert.ToBoolean(this.Request.Query["preview"]))

LearningHub.Nhs.WebUI/Extensions/ClaimsPrincipalExtensions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Security.Claims;
5+
using System.Security.Principal;
56

67
/// <summary>
78
/// Defines the <see cref="ClaimsPrincipalExtensions" />.
@@ -23,5 +24,21 @@ public static string GetTimezoneOffsetCacheKey(this ClaimsPrincipal claimsPrinci
2324

2425
return $"usr_{userId}_tz";
2526
}
27+
28+
/// <summary>
29+
/// Get MoodleUserId.
30+
/// </summary>
31+
/// <param name="identity">The identity.</param>
32+
/// <returns>The System.Int32.</returns>
33+
public static int GetMoodleUserId(this IIdentity identity)
34+
{
35+
Claim claim = (identity as ClaimsIdentity)?.FindFirst("moodle_username");
36+
if (claim != null)
37+
{
38+
return int.Parse(claim.Value);
39+
}
40+
41+
return 0;
42+
}
2643
}
2744
}

LearningHub.Nhs.WebUI/Helpers/FeatureFlags.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@ public static class FeatureFlags
1414
/// The DisplayAudioVideoResource.
1515
/// </summary>
1616
public const string DisplayAudioVideoResource = "DisplayAudioVideoResource";
17+
18+
/// <summary>
19+
/// The EnableMoodle.
20+
/// </summary>
21+
public const string EnableMoodle = "EnableMoodle";
1722
}
1823
}

LearningHub.Nhs.WebUI/Interfaces/IDashboardService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace LearningHub.Nhs.WebUI.Interfaces
22
{
3+
using System.Collections.Generic;
34
using System.Threading.Tasks;
45
using LearningHub.Nhs.Models.Dashboard;
56
using LearningHub.Nhs.WebUI.Models;
@@ -39,5 +40,13 @@ public interface IDashboardService
3940
/// <param name="dashboardEventViewModel">dashboardEventViewModel.</param>
4041
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
4142
Task RecordDashBoardEventAsync(DashboardEventViewModel dashboardEventViewModel);
43+
44+
/// <summary>
45+
/// GetEnrolledCoursesFromMoodleAsync.
46+
/// </summary>
47+
/// <param name="currentUserId">The current User Id type.</param>
48+
/// <param name="pageNumber">The page Number.</param>
49+
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
50+
Task<List<MoodleCourseResponseViewModel>> GetEnrolledCoursesFromMoodleAsync(int currentUserId, int pageNumber);
4251
}
4352
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace LearningHub.Nhs.WebUI.Interfaces
2+
{
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
using LearningHub.Nhs.Models.Dashboard;
6+
using LearningHub.Nhs.WebUI.Models;
7+
8+
/// <summary>
9+
/// IMoodleApiService.
10+
/// </summary>
11+
public interface IMoodleApiService
12+
{
13+
/// <summary>
14+
/// GetEnrolledCoursesAsync.
15+
/// </summary>
16+
/// <param name="currentUserId">Moodle user id.</param>
17+
/// <param name="pageNumber">pageNumber.</param>
18+
/// <returns> List of MoodleCourseResponseViewModel.</returns>
19+
Task<List<MoodleCourseResponseViewModel>> GetEnrolledCoursesAsync(int currentUserId, int pageNumber);
20+
21+
/// <summary>
22+
/// GetEnrolledCoursesAsync.
23+
/// </summary>
24+
/// <param name="userId">Moodle user id.</param>
25+
/// <param name="courseId">Moodle course id.</param>
26+
/// <param name="pageNumber">pageNumber.</param>
27+
/// <returns> List of MoodleCourseResponseViewModel.</returns>
28+
Task<MoodleCourseCompletionViewModel> GetCourseCompletionAsync(int userId, int courseId, int pageNumber);
29+
}
30+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace LearningHub.Nhs.Services.Interface
2+
{
3+
using System.Net.Http;
4+
using System.Threading.Tasks;
5+
6+
/// <summary>
7+
/// The Moodle Http Client interface.
8+
/// </summary>
9+
public interface IMoodleHttpClient
10+
{
11+
/// <summary>
12+
/// The get cient async.
13+
/// </summary>
14+
/// <returns>The <see cref="Task"/>.</returns>
15+
Task<HttpClient> GetClient();
16+
17+
/// <summary>
18+
/// GetDefaultParameters.
19+
/// </summary>
20+
/// <returns>defaultParameters.</returns>
21+
string GetDefaultParameters();
22+
}
23+
}

LearningHub.Nhs.WebUI/Models/DashboardViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace LearningHub.Nhs.WebUI.Models
22
{
3+
using System.Collections.Generic;
34
using LearningHub.Nhs.Models.Dashboard;
45

56
/// <summary>
@@ -28,5 +29,10 @@ public DashboardViewModel()
2829
/// Gets or sets a list of catalogues to be displayed in the dashboard.
2930
/// </summary>
3031
public DashboardCatalogueResponseViewModel Catalogues { get; set; }
32+
33+
/// <summary>
34+
/// Gets or sets a list of enrolled courses to be displayed in the dashboard.
35+
/// </summary>
36+
public List<MoodleCourseResponseViewModel> EnrolledCourses { get; set; }
3137
}
3238
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace LearningHub.Nhs.WebUI.Models
2+
{
3+
/// <summary>
4+
/// MoodleCompletionResponseViewModel.
5+
/// </summary>
6+
public class MoodleCompletionResponseViewModel
7+
{
8+
/// <summary>
9+
/// Gets or sets the completion status.
10+
/// </summary>
11+
public string Exception { get; set; }
12+
13+
/// <summary>
14+
/// Gets or sets error code.
15+
/// </summary>
16+
public string Errorcode { get; set; }
17+
18+
/// <summary>
19+
/// Gets or sets Error message.
20+
/// </summary>
21+
public string Message { get; set; }
22+
23+
/// <summary>
24+
/// Gets or sets Debug info.
25+
/// </summary>
26+
public string Debuginfo { get; set; }
27+
}
28+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
namespace LearningHub.Nhs.WebUI.Models
2+
{
3+
using System.Collections.Generic;
4+
5+
/// <summary>
6+
/// MoodleCourseCompletionViewModel.
7+
/// </summary>
8+
public class MoodleCourseCompletionViewModel
9+
{
10+
/// <summary>
11+
/// Gets or sets the completion status.
12+
/// </summary>
13+
public CompletStatus CompletionStatus { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets the list of warnings.
17+
/// </summary>
18+
public List<object> Warnings { get; set; }
19+
20+
/// <summary>
21+
/// CompletionStatus.
22+
/// </summary>
23+
public class CompletStatus
24+
{
25+
/// <summary>
26+
/// Gets or sets a value indicating whether the course is completed.
27+
/// </summary>
28+
public bool Completed { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the aggregation method.
32+
/// </summary>
33+
public int Aggregation { get; set; }
34+
35+
/// <summary>
36+
/// Gets or sets the list of completions.
37+
/// </summary>
38+
public List<Completion> Completions { get; set; }
39+
40+
/// <summary>
41+
/// Completion.
42+
/// </summary>
43+
public class Completion
44+
{
45+
/// <summary>
46+
/// Gets or sets the type of completion.
47+
/// </summary>
48+
public int Type { get; set; }
49+
50+
/// <summary>
51+
/// Gets or sets the title of the completion requirement.
52+
/// </summary>
53+
public string Title { get; set; }
54+
55+
/// <summary>
56+
/// Gets or sets the status of the completion.
57+
/// </summary>
58+
public string Status { get; set; }
59+
60+
/// <summary>
61+
/// Gets or sets a value indicating whether the requirement is complete.
62+
/// </summary>
63+
public bool Complete { get; set; }
64+
65+
/// <summary>
66+
/// Gets or sets the timestamp when completion was achieved.
67+
/// </summary>
68+
public long? TimeCompleted { get; set; }
69+
70+
/// <summary>
71+
/// Gets or sets the completion details.
72+
/// </summary>
73+
public CompletionDetails Details { get; set; }
74+
75+
/// <summary>
76+
/// CompletionDetails.
77+
/// </summary>
78+
public class CompletionDetails
79+
{
80+
/// <summary>
81+
/// Gets or sets the type of completion requirement.
82+
/// </summary>
83+
public string Type { get; set; }
84+
85+
/// <summary>
86+
/// Gets or sets the criteria for completion.
87+
/// </summary>
88+
public string Criteria { get; set; }
89+
90+
/// <summary>
91+
/// Gets or sets the requirement for completion.
92+
/// </summary>
93+
public string Requirement { get; set; }
94+
95+
/// <summary>
96+
/// Gets or sets the status of the requirement.
97+
/// </summary>
98+
public string Status { get; set; }
99+
}
100+
}
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)