Skip to content

Commit 515f0ce

Browse files
authored
Merge pull request #2724 from TechnologyEnhancedLearning/Develop/Fixes/TD-4238-Launchingfewcoursesfrom'Currentactivities'orfrom'Coursesetup'seeingbacklinkasCompletedactivities'
TD-4238 launching few courses from 'current activities' or from 'course setup' seeing back link as completed activities'
2 parents 60bc596 + 6202973 commit 515f0ce

File tree

7 files changed

+50
-19
lines changed

7 files changed

+50
-19
lines changed

DigitalLearningSolutions.Data/DataServices/CourseDataService.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ int EnrolOnActivitySelfAssessment(int selfAssessmentId, int candidateId, int sup
125125
int selfAssessmentSupervisorRoleId, DateTime? completeByDate, int delegateUserId, int centreId, int? enrolledByAdminId);
126126

127127
bool IsCourseCompleted(int candidateId, int customisationId);
128-
128+
bool IsCourseCompleted(int candidateId, int customisationId, int progressID);
129129
public IEnumerable<Course> GetApplicationsAvailableToCentre(int centreId);
130130

131131
public (IEnumerable<CourseStatistics>, int) GetCourseStatisticsAtCentre(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection, int centreId, int? categoryId, bool allCentreCourses, bool? hideInLearnerPortal,
@@ -1828,13 +1828,28 @@ SELECT p.Completed
18281828
FROM Progress AS p INNER JOIN
18291829
Customisations AS cu ON p.CustomisationID = cu.CustomisationID INNER JOIN
18301830
Applications AS a ON cu.ApplicationID = a.ApplicationID
1831-
WHERE (p.CandidateID = @candidateId) AND p.CustomisationID = @customisationId
1831+
WHERE (p.CandidateID = @candidateId) AND p.CustomisationID = @customisationId
18321832
AND (NOT (p.Completed IS NULL)))
18331833
THEN CAST(1 AS BIT)
18341834
ELSE CAST(0 AS BIT) END",
18351835
new { candidateId, customisationId }
18361836
);
18371837
}
1838+
public bool IsCourseCompleted(int candidateId, int customisationId, int progressID)
1839+
{
1840+
return connection.ExecuteScalar<bool>(
1841+
@"SELECT CASE WHEN EXISTS (
1842+
SELECT p.Completed
1843+
FROM Progress AS p INNER JOIN
1844+
Customisations AS cu ON p.CustomisationID = cu.CustomisationID INNER JOIN
1845+
Applications AS a ON cu.ApplicationID = a.ApplicationID
1846+
WHERE (p.CandidateID = @candidateId) AND p.CustomisationID = @customisationId AND progressID =@progressID
1847+
AND (NOT (p.Completed IS NULL)))
1848+
THEN CAST(1 AS BIT)
1849+
ELSE CAST(0 AS BIT) END",
1850+
new { candidateId, customisationId, progressID }
1851+
);
1852+
}
18381853

18391854
public IEnumerable<Course> GetApplicationsAvailableToCentre(int centreId)
18401855
{

DigitalLearningSolutions.Web.Tests/Controllers/LearningMenu/IndexTests.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void Index_should_render_view()
2121
A.CallTo(() => courseContentService.GetProgressId(CandidateId, CustomisationId)).Returns(10);
2222

2323
// When
24-
var result = controller.Index(CustomisationId);
24+
var result = controller.Index(CustomisationId, progressID);
2525

2626
// Then
2727
var expectedModel = new InitialMenuViewModel(expectedCourseContent);
@@ -44,7 +44,7 @@ public void Index_should_redirect_to_section_page_if_one_section_in_course()
4444
A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, customisationId, CentreId)).Returns(10);
4545

4646
// When
47-
var result = controller.Index(customisationId);
47+
var result = controller.Index(customisationId, progressID);
4848

4949
// Then
5050
result.Should()
@@ -74,7 +74,7 @@ public void Index_should_not_redirect_to_section_page_if_more_than_one_section_i
7474
A.CallTo(() => courseContentService.GetProgressId(CandidateId, customisationId)).Returns(10);
7575

7676
// When
77-
var result = controller.Index(customisationId);
77+
var result = controller.Index(customisationId, progressID);
7878

7979
// Then
8080
var expectedModel = new InitialMenuViewModel(expectedCourseContent);
@@ -91,7 +91,7 @@ public void Index_should_return_404_if_unknown_course()
9191
.Returns(3);
9292

9393
// When
94-
var result = controller.Index(CustomisationId);
94+
var result = controller.Index(CustomisationId, progressID);
9595

9696
// Then
9797
result.Should()
@@ -112,7 +112,7 @@ public void Index_should_return_404_if_unable_to_enrol()
112112
.Returns(null);
113113

114114
// When
115-
var result = controller.Index(CustomisationId);
115+
var result = controller.Index(CustomisationId, progressID);
116116

117117
// Then
118118
result.Should()
@@ -129,7 +129,7 @@ public void Index_always_calls_get_course_content()
129129
const int customisationId = 1;
130130

131131
// When
132-
controller.Index(1);
132+
controller.Index(1,2);
133133

134134
// Then
135135
A.CallTo(() => courseContentService.GetCourseContent(CandidateId, customisationId)).MustHaveHappened();
@@ -147,7 +147,7 @@ public void Index_valid_customisation_id_should_update_login_and_duration()
147147
A.CallTo(() => courseContentService.GetProgressId(CandidateId, CustomisationId)).Returns(progressId);
148148

149149
// When
150-
controller.Index(CustomisationId);
150+
controller.Index(CustomisationId, progressID);
151151

152152
// Then
153153
A.CallTo(() => sessionService.StartOrUpdateDelegateSession(CandidateId, CustomisationId, A<ISession>._)).MustHaveHappened();
@@ -160,7 +160,7 @@ public void Index_invalid_customisation_id_should_not_insert_new_progress()
160160
A.CallTo(() => courseContentService.GetCourseContent(CandidateId, CustomisationId)).Returns(null);
161161

162162
// When
163-
controller.Index(CustomisationId);
163+
controller.Index(CustomisationId, progressID);
164164

165165
// Then
166166
A.CallTo(() => courseContentService.GetOrCreateProgressId(A<int>._, A<int>._, A<int>._)).MustNotHaveHappened();
@@ -173,7 +173,7 @@ public void Index_invalid_customisation_id_should_not_update_login_and_duration(
173173
A.CallTo(() => courseContentService.GetCourseContent(CandidateId, CustomisationId)).Returns(null);
174174

175175
// When
176-
controller.Index(CustomisationId);
176+
controller.Index(CustomisationId, progressID);
177177

178178
// Then
179179
A.CallTo(() => courseContentService.UpdateProgress(A<int>._)).MustNotHaveHappened();
@@ -186,7 +186,7 @@ public void Index_failing_to_insert_progress_should_not_update_progress()
186186
A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId)).Returns(null);
187187

188188
// When
189-
controller.Index(CustomisationId);
189+
controller.Index(CustomisationId, progressID);
190190

191191
// Then
192192
A.CallTo(() => courseContentService.UpdateProgress(A<int>._)).MustNotHaveHappened();
@@ -203,7 +203,7 @@ public void Index_valid_customisationId_should_StartOrUpdate_course_sessions()
203203
A.CallTo(() => courseContentService.GetProgressId(CandidateId, CustomisationId)).Returns(1);
204204

205205
// When
206-
controller.Index(CustomisationId);
206+
controller.Index(CustomisationId, progressID);
207207

208208
// Then
209209
A.CallTo(() => sessionService.StartOrUpdateDelegateSession(CandidateId, CustomisationId, httpContextSession)).MustHaveHappenedOnceExactly();
@@ -221,7 +221,7 @@ public void Index_invalid_customisationId_should_not_StartOrUpdate_course_sessio
221221
A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId)).Returns(1);
222222

223223
// When
224-
controller.Index(CustomisationId);
224+
controller.Index(CustomisationId, progressID);
225225

226226
// Then
227227
A.CallTo(() => sessionService.StartOrUpdateDelegateSession(A<int>._, A<int>._, A<ISession>._)).MustNotHaveHappened();
@@ -236,7 +236,7 @@ public void Index_unable_to_enrol_should_not_StartOrUpdate_course_sessions()
236236
A.CallTo(() => courseContentService.GetOrCreateProgressId(CandidateId, CustomisationId, CentreId)).Returns(null);
237237

238238
// When
239-
controller.Index(CustomisationId);
239+
controller.Index(CustomisationId, progressID);
240240

241241
// Then
242242
A.CallTo(() => sessionService.StartOrUpdateDelegateSession(A<int>._, A<int>._, A<ISession>._)).MustNotHaveHappened();
@@ -298,7 +298,7 @@ public void Index_not_detects_id_manipulation_self_register_true()
298298
A.CallTo(() => courseService.GetSelfRegister(CustomisationId)).Returns(true);
299299

300300
// When
301-
var result = controller.Index(CustomisationId);
301+
var result = controller.Index(CustomisationId, progressID);
302302

303303
// Then
304304
result.Should()

DigitalLearningSolutions.Web.Tests/Controllers/LearningMenu/LearningMenuControllerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public partial class LearningMenuControllerTests
1717
private const int CandidateId = 11;
1818
private const int CentreId = 2;
1919
private const int CustomisationId = 12;
20+
const int progressID = 34;
2021
private const int SectionId = 199;
2122
private const int TutorialId = 842;
2223
private ISession httpContextSession = null!;

DigitalLearningSolutions.Web/Controllers/LearningMenuController/LearningMenuController.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ IClockUtility clockUtility
5858
}
5959

6060
[Route("/LearningMenu/{customisationId:int}")]
61-
public IActionResult Index(int customisationId)
61+
public IActionResult Index(int customisationId, int progressID)
6262
{
6363
var centreId = User.GetCentreIdKnownNotNull();
6464
var candidateId = User.GetCandidateIdKnownNotNull();
@@ -100,7 +100,7 @@ public IActionResult Index(int customisationId)
100100
courseContentService.UpdateProgress(progressId.Value);
101101
};
102102

103-
SetTempData(candidateId, customisationId);
103+
SetTempData(candidateId, customisationId, progressID);
104104

105105
var model = new InitialMenuViewModel(courseContent);
106106
return View(model);
@@ -605,6 +605,14 @@ private void SetTempData(int candidateId, int customisationId)
605605
else
606606
TempData["LearningActivity"] = "Current";
607607
}
608+
private void SetTempData(int candidateId, int customisationId,int progressID)
609+
{
610+
var isCompleted = courseService.IsCourseCompleted(candidateId, customisationId, progressID);
611+
if (isCompleted)
612+
TempData["LearningActivity"] = "Completed";
613+
else
614+
TempData["LearningActivity"] = "Current";
615+
}
608616

609617
private bool UniqueIdManipulationDetected(int candidateId, int customisationId)
610618
{

DigitalLearningSolutions.Web/Services/CourseService.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ int diagCompletionThreshold
123123
public IEnumerable<DelegateAssessmentStatistics> GetDelegateAssessments(string searchString, int centreId, string categoryName, string isActive);
124124
IEnumerable<AvailableCourse> GetAvailableCourses(int delegateId, int? centreId, int categoryId);
125125
bool IsCourseCompleted(int candidateId, int customisationId);
126+
bool IsCourseCompleted(int candidateId, int customisationId, int progressID);
126127
bool GetSelfRegister(int customisationId);
127128
IEnumerable<CurrentCourse> GetCurrentCourses(int candidateId);
128129
void SetCompleteByDate(int progressId, int candidateId, DateTime? completeByDate);
@@ -570,10 +571,14 @@ public IEnumerable<AvailableCourse> GetAvailableCourses(int delegateId, int? cen
570571
return courseDataService.GetAvailableCourses(delegateId, centreId, categoryId);
571572
}
572573

573-
public bool IsCourseCompleted(int candidateId, int customisationId)
574+
public bool IsCourseCompleted(int candidateId, int customisationId )
574575
{
575576
return courseDataService.IsCourseCompleted(candidateId, customisationId);
576577
}
578+
public bool IsCourseCompleted(int candidateId, int customisationId, int progressID)
579+
{
580+
return courseDataService.IsCourseCompleted(candidateId, customisationId, progressID);
581+
}
577582

578583
public bool GetSelfRegister(int customisationId)
579584
{

DigitalLearningSolutions.Web/Views/LearningPortal/Completed/CompletedCourseCard/_CompletedCourseCard.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
asp-controller="LearningMenu"
3939
asp-action="Index"
4040
asp-route-customisationId="@Model.Id"
41+
asp-route-progressID="@Model.ProgressId"
4142
role="button">
4243
Launch course <span class="nhsuk-u-visually-hidden">@Model.Name</span>
4344
</a>

DigitalLearningSolutions.Web/Views/LearningPortal/Current/CurrentCourseCard/_CurrentCourseCard.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
asp-controller="LearningMenu"
4747
asp-action="Index"
4848
asp-route-customisationId="@Model.Id"
49+
asp-route-progressID="@Model.ProgressId"
4950
role="button">
5051
Launch course <span class="nhsuk-u-visually-hidden">@Model.Name</span>
5152
</a>

0 commit comments

Comments
 (0)