From 01c1335572e292c47201fc71d55797764f6ef92b Mon Sep 17 00:00:00 2001 From: Jonathan Bloxsom Date: Thu, 18 Aug 2022 15:45:56 +0100 Subject: [PATCH 1/8] HEEDLS-1038 AdminFieldsDataService methods --- .../DataServices/CourseAdminFieldsDataService.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/DigitalLearningSolutions.Data/DataServices/CourseAdminFieldsDataService.cs b/DigitalLearningSolutions.Data/DataServices/CourseAdminFieldsDataService.cs index 941317057e..807bf637bd 100644 --- a/DigitalLearningSolutions.Data/DataServices/CourseAdminFieldsDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/CourseAdminFieldsDataService.cs @@ -68,8 +68,7 @@ LEFT JOIN CoursePrompts AS cp2 LEFT JOIN CoursePrompts AS cp3 ON cu.CourseField3PromptID = cp3.CoursePromptID INNER JOIN dbo.Applications AS ap ON ap.ApplicationID = cu.ApplicationID - WHERE ap.ArchivedDate IS NULL - AND ap.DefaultContentTypeID <> 4 + WHERE ap.DefaultContentTypeID <> 4 AND cu.CustomisationID = @customisationId", new { customisationId } ).Single(); @@ -183,7 +182,6 @@ int customisationId FROM Customisations AS cu INNER JOIN dbo.Applications AS ap ON ap.ApplicationID = cu.ApplicationID WHERE CustomisationID = @customisationId - AND ap.ArchivedDate IS NULL AND ap.DefaultContentTypeID <> 4", new { customisationId } ).Single(); From d0a5aa53116e6adf33c01685cf9fabc2358d41b7 Mon Sep 17 00:00:00 2001 From: Jonathan Bloxsom Date: Thu, 18 Aug 2022 16:22:17 +0100 Subject: [PATCH 2/8] HEEDLS-1038 resolve simple cases in CourseDataService --- .../DataServices/CourseDataService.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs index 35e9b4d853..9e363af386 100644 --- a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs @@ -309,7 +309,6 @@ FROM dbo.Customisations AS cu AND cu.Active = 1 AND cu.CentreID = @centreId AND ca.CentreID = @centreId - AND ap.ArchivedDate IS NULL AND ap.DefaultContentTypeID <> 4", new { centreId, adminCategoryId } ); @@ -346,7 +345,7 @@ FROM dbo.Customisations AS cu WHERE (ap.CourseCategoryID = @categoryId OR @categoryId IS NULL) AND (cu.CentreID = @centreId OR (cu.AllCentres = 1 AND ca.Active = 1)) AND ca.CentreID = @centreId - AND ap.ArchivedDate IS NULL + --AND ap.ArchivedDate IS NULL AND ap.DefaultContentTypeID <> 4", new { centreId, categoryId } ); @@ -357,7 +356,7 @@ public IEnumerable GetDelegateCoursesInfo(int delegateId) return connection.Query( $@"{selectDelegateCourseInfoQuery} WHERE pr.CandidateID = @delegateId - AND ap.ArchivedDate IS NULL + --AND ap.ArchivedDate IS NULL AND pr.RemovedDate IS NULL AND ap.DefaultContentTypeID <> 4", new { delegateId } @@ -369,7 +368,7 @@ AND pr.RemovedDate IS NULL return connection.QuerySingleOrDefault( $@"{selectDelegateCourseInfoQuery} WHERE pr.ProgressID = @progressId - AND ap.ArchivedDate IS NULL + --AND ap.ArchivedDate IS NULL AND ap.DefaultContentTypeID <> 4", new { progressId } ); @@ -496,7 +495,7 @@ FROM Customisations AS c INNER JOIN Applications AS ap ON ap.ApplicationID = c.ApplicationID INNER JOIN CourseCategories AS cc ON ap.CourseCategoryId = cc.CourseCategoryId INNER JOIN CourseTopics AS ct ON ap.CourseTopicId = ct.CourseTopicId - WHERE ap.ArchivedDate IS NULL + --WHERE ap.ArchivedDate IS NULL AND (c.CentreID = @centreId OR c.AllCentres = 1) AND (ap.CourseCategoryID = @categoryId OR @categoryId IS NULL) AND EXISTS (SELECT CentreApplicationID FROM CentreApplications WHERE (ApplicationID = c.ApplicationID) AND (CentreID = @centreID) AND (Active = 1)) @@ -567,7 +566,6 @@ FROM Candidates AS cn INNER JOIN dbo.Applications AS ap ON ap.ApplicationID = c.ApplicationID WHERE cn.CentreID = @centreID AND (ap.CourseCategoryID = @categoryId OR @categoryId IS NULL) - AND ap.ArchivedDate IS NULL AND ap.DefaultContentTypeID <> 4", new { centreId, categoryId } ); From 331c2343fb2c454b3932b80f6dd29f041282434b Mon Sep 17 00:00:00 2001 From: Jonathan Bloxsom Date: Thu, 18 Aug 2022 17:39:45 +0100 Subject: [PATCH 3/8] HEEDLS-1038 split GetCourseStatisticsAtCentreFilteredByCategory into two --- .../DataServices/CourseDataService.cs | 68 +++++++++++-------- .../Services/CourseService.cs | 18 ++++- 2 files changed, 58 insertions(+), 28 deletions(-) diff --git a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs index 9e363af386..f2e6a7dd45 100644 --- a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs @@ -28,6 +28,8 @@ public interface ICourseDataService IEnumerable GetCourseStatisticsAtCentreFilteredByCategory(int centreId, int? categoryId); + IEnumerable GetNonArchivedCourseStatisticsAtCentreFilteredByCategory(int centreId, int? categoryId); + IEnumerable GetDelegateCoursesInfo(int delegateId); DelegateCourseInfo? GetDelegateCourseInfoByProgressId(int progressId); @@ -144,6 +146,33 @@ FROM dbo.AssessAttempts AS aa private readonly IDbConnection connection; private readonly ILogger logger; + private readonly string CourseStatisticsQuery = @$"SELECT + cu.CustomisationID, + cu.CentreID, + cu.Active, + cu.AllCentres, + ap.ApplicationId, + ap.ApplicationName, + cu.CustomisationName, + {DelegateCountQuery}, + {CompletedCountQuery}, + {AllAttemptsQuery}, + {AttemptsPassedQuery}, + cu.HideInLearnerPortal, + cc.CategoryName, + ct.CourseTopic, + cu.LearningTimeMins AS LearningMinutes, + cu.IsAssessed + FROM dbo.Customisations AS cu + INNER JOIN dbo.CentreApplications AS ca ON ca.ApplicationID = cu.ApplicationID + INNER JOIN dbo.Applications AS ap ON ap.ApplicationID = ca.ApplicationID + INNER JOIN dbo.CourseCategories AS cc ON cc.CourseCategoryID = ap.CourseCategoryID + INNER JOIN dbo.CourseTopics AS ct ON ct.CourseTopicID = ap.CourseTopicId + WHERE (ap.CourseCategoryID = @categoryId OR @categoryId IS NULL) + AND (cu.CentreID = @centreId OR (cu.AllCentres = 1 AND ca.Active = 1)) + AND ca.CentreID = @centreId + AND ap.DefaultContentTypeID <> 4"; + private readonly string selectDelegateCourseInfoQuery = @$"SELECT cu.CustomisationID AS CustomisationId, @@ -320,33 +349,18 @@ public IEnumerable GetCourseStatisticsAtCentreFilteredByCatego ) { return connection.Query( - @$"SELECT - cu.CustomisationID, - cu.CentreID, - cu.Active, - cu.AllCentres, - ap.ApplicationId, - ap.ApplicationName, - cu.CustomisationName, - {DelegateCountQuery}, - {CompletedCountQuery}, - {AllAttemptsQuery}, - {AttemptsPassedQuery}, - cu.HideInLearnerPortal, - cc.CategoryName, - ct.CourseTopic, - cu.LearningTimeMins AS LearningMinutes, - cu.IsAssessed - FROM dbo.Customisations AS cu - INNER JOIN dbo.CentreApplications AS ca ON ca.ApplicationID = cu.ApplicationID - INNER JOIN dbo.Applications AS ap ON ap.ApplicationID = ca.ApplicationID - INNER JOIN dbo.CourseCategories AS cc ON cc.CourseCategoryID = ap.CourseCategoryID - INNER JOIN dbo.CourseTopics AS ct ON ct.CourseTopicID = ap.CourseTopicId - WHERE (ap.CourseCategoryID = @categoryId OR @categoryId IS NULL) - AND (cu.CentreID = @centreId OR (cu.AllCentres = 1 AND ca.Active = 1)) - AND ca.CentreID = @centreId - --AND ap.ArchivedDate IS NULL - AND ap.DefaultContentTypeID <> 4", + CourseStatisticsQuery, + new { centreId, categoryId } + ); + } + + public IEnumerable GetNonArchivedCourseStatisticsAtCentreFilteredByCategory( + int centreId, + int? categoryId + ) + { + return connection.Query( + @$"{CourseStatisticsQuery} AND ap.ArchivedDate IS NULL", new { centreId, categoryId } ); } diff --git a/DigitalLearningSolutions.Data/Services/CourseService.cs b/DigitalLearningSolutions.Data/Services/CourseService.cs index 4bbb7ede65..a801b21fc9 100644 --- a/DigitalLearningSolutions.Data/Services/CourseService.cs +++ b/DigitalLearningSolutions.Data/Services/CourseService.cs @@ -156,6 +156,22 @@ public IEnumerable ); } + public IEnumerable + GetNonArchivedCentreSpecificCourseStatisticsWithAdminFieldResponseCounts( + int centreId, + int? categoryId, + bool includeAllCentreCourses = false + ) + { + var allCourses = courseDataService.GetNonArchivedCourseStatisticsAtCentreFilteredByCategory(centreId, categoryId); + return allCourses.Where(c => c.CentreId == centreId || c.AllCentres && includeAllCentreCourses).Select( + c => new CourseStatisticsWithAdminFieldResponseCounts( + c, + courseAdminFieldsService.GetCourseAdminFieldsWithAnswerCountsForCourse(c.CustomisationId, centreId) + ) + ); + } + public IEnumerable GetAllCoursesInCategoryForDelegate( int delegateId, int centreId, @@ -335,7 +351,7 @@ public IEnumerable GetTopicsForCentreAndCentrallyManagedCourses(int cent public CentreCourseDetails GetCentreCourseDetails(int centreId, int? categoryId) { var (courses, categories, topics) = ( - GetCentreSpecificCourseStatisticsWithAdminFieldResponseCounts(centreId, categoryId), + GetNonArchivedCentreSpecificCourseStatisticsWithAdminFieldResponseCounts(centreId, categoryId), courseCategoriesDataService.GetCategoriesForCentreAndCentrallyManagedCourses(centreId) .Select(c => c.CategoryName), courseTopicsDataService.GetCourseTopicsAvailableAtCentre(centreId).Select(c => c.CourseTopic)); From b335dbf69985148ba8dc729b88176c0d66c02f8f Mon Sep 17 00:00:00 2001 From: Jonathan Bloxsom Date: Thu, 18 Aug 2022 18:02:02 +0100 Subject: [PATCH 4/8] HEEDLS-1038 split GetCoursesAvailableToCentreByCategory --- .../DataServices/CourseDataService.cs | 33 ++++++++++++------- .../Services/CourseService.cs | 2 +- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs index f2e6a7dd45..f4653ce652 100644 --- a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs @@ -40,6 +40,8 @@ public interface ICourseDataService IEnumerable GetCoursesAvailableToCentreByCategory(int centreId, int? categoryId); + IEnumerable GetNonArchivedCoursesAvailableToCentreByCategory(int centreId, int? categoryId); + IEnumerable GetApplicationsAvailableToCentreByCategory(int centreId, int? categoryId); IEnumerable GetApplicationsByBrandId(int brandId); @@ -475,16 +477,14 @@ FROM Customisations cu return names; } - public IEnumerable GetCoursesAvailableToCentreByCategory(int centreId, int? categoryId) - { - const string tutorialWithLearningCountQuery = - @"SELECT COUNT(ct.TutorialID) + private const string tutorialWithLearningCountQuery = + @"SELECT COUNT(ct.TutorialID) FROM CustomisationTutorials AS ct INNER JOIN Tutorials AS t ON ct.TutorialID = t.TutorialID WHERE ct.Status = 1 AND ct.CustomisationID = c.CustomisationID"; - const string tutorialWithDiagnosticCountQuery = - @"SELECT COUNT(ct.TutorialID) + private const string tutorialWithDiagnosticCountQuery = + @"SELECT COUNT(ct.TutorialID) FROM CustomisationTutorials AS ct INNER JOIN Tutorials AS t ON ct.TutorialID = t.TutorialID INNER JOIN Customisations AS c ON c.CustomisationID = ct.CustomisationID @@ -492,8 +492,7 @@ FROM CustomisationTutorials AS ct WHERE ct.DiagStatus = 1 AND a.DiagAssess = 1 AND ct.CustomisationID = c.CustomisationID AND a.ArchivedDate IS NULL AND a.DefaultContentTypeID <> 4"; - return connection.Query( - $@"SELECT + private readonly string CourseAssessmentDetailsQuery = $@"SELECT c.CustomisationID, c.CentreID, c.ApplicationID, @@ -509,11 +508,23 @@ FROM Customisations AS c INNER JOIN Applications AS ap ON ap.ApplicationID = c.ApplicationID INNER JOIN CourseCategories AS cc ON ap.CourseCategoryId = cc.CourseCategoryId INNER JOIN CourseTopics AS ct ON ap.CourseTopicId = ct.CourseTopicId - --WHERE ap.ArchivedDate IS NULL - AND (c.CentreID = @centreId OR c.AllCentres = 1) + WHERE (c.CentreID = @centreId OR c.AllCentres = 1) AND (ap.CourseCategoryID = @categoryId OR @categoryId IS NULL) AND EXISTS (SELECT CentreApplicationID FROM CentreApplications WHERE (ApplicationID = c.ApplicationID) AND (CentreID = @centreID) AND (Active = 1)) - AND ap.DefaultContentTypeID <> 4", + AND ap.DefaultContentTypeID <> 4"; + + public IEnumerable GetCoursesAvailableToCentreByCategory(int centreId, int? categoryId) + { + return connection.Query( + CourseAssessmentDetailsQuery, + new { centreId, categoryId } + ); + } + + public IEnumerable GetNonArchivedCoursesAvailableToCentreByCategory(int centreId, int? categoryId) + { + return connection.Query( + @$"{CourseAssessmentDetailsQuery} AND ap.ArchivedDate IS NULL", new { centreId, categoryId } ); } diff --git a/DigitalLearningSolutions.Data/Services/CourseService.cs b/DigitalLearningSolutions.Data/Services/CourseService.cs index a801b21fc9..54022c5ba4 100644 --- a/DigitalLearningSolutions.Data/Services/CourseService.cs +++ b/DigitalLearningSolutions.Data/Services/CourseService.cs @@ -257,7 +257,7 @@ public void UpdateLearningPathwayDefaultsForCourse( int? categoryId ) { - var activeCourses = courseDataService.GetCoursesAvailableToCentreByCategory(centreId, categoryId) + var activeCourses = courseDataService.GetNonArchivedCoursesAvailableToCentreByCategory(centreId, categoryId) .Where(c => c.Active = true); var orderedCourses = activeCourses.OrderBy(c => c.ApplicationName); return orderedCourses.Select(c => (c.CustomisationId, c.CourseName)); From 0c738400e15bbfa781eaff289e4807ad8fd252f9 Mon Sep 17 00:00:00 2001 From: Jonathan Bloxsom Date: Fri, 19 Aug 2022 11:39:49 +0100 Subject: [PATCH 5/8] HEEDLS-1038 update tests --- .../DataServices/CourseDataServiceTests.cs | 69 ++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs b/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs index 2f388ba5cc..68240fd974 100644 --- a/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs +++ b/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs @@ -290,13 +290,13 @@ public void GetNumberOfActiveCoursesAtCentreFilteredByCategory_with_filtered_cat } [Test] - public void GetNumberOfActiveCoursesAtCentreFilteredByCategory_excludes_courses_from_archived_applications() + public void GetNumberOfActiveCoursesAtCentreFilteredByCategory_includes_courses_from_archived_applications() { // When var count = courseDataService.GetNumberOfActiveCoursesAtCentreFilteredByCategory(101, null); // Then - count.Should().Be(141); + count.Should().Be(144); } [Test] @@ -345,6 +345,40 @@ public void GetCourseStatisticsAtCentreFilteredByCategory_should_return_course_s LearningMinutes = "N/A", }; + result.Should().HaveCount(259); + result.First().Should().BeEquivalentTo(expectedFirstCourse); + } + + [Test] + public void GetNonArchivedCourseStatisticsAtCentreFilteredByCategory_should_return_course_statistics_correctly() + { + // Given + const int centreId = 101; + int? categoryId = null; + + // When + var result = courseDataService.GetNonArchivedCourseStatisticsAtCentreFilteredByCategory(centreId, categoryId).ToList(); + + // Then + var expectedFirstCourse = new CourseStatistics + { + CustomisationId = 100, + CentreId = 101, + Active = false, + AllCentres = false, + ApplicationId = 1, + ApplicationName = "Entry Level - Win XP, Office 2003/07 OLD", + CustomisationName = "Standard", + DelegateCount = 25, + AllAttempts = 49, + AttemptsPassed = 34, + CompletedCount = 5, + HideInLearnerPortal = false, + CategoryName = "Office 2007", + CourseTopic = "Microsoft Office", + LearningMinutes = "N/A", + }; + result.Should().HaveCount(256); result.First().Should().BeEquivalentTo(expectedFirstCourse); } @@ -463,6 +497,37 @@ public void GetCoursesAvailableToCentreByCategory_returns_expected_values() IsAssessed = false, }; + result.Should().HaveCount(259); + result.First().Should().BeEquivalentTo(expectedFirstCourse); + } + + [Test] + public void GetNonArchivedCoursesAvailableToCentreByCategory_returns_expected_values() + { + // Given + const int centreId = 101; + int? categoryId = null; + + // When + var result = courseDataService.GetNonArchivedCoursesAvailableToCentreByCategory(centreId, categoryId) + .ToList(); + + // Then + var expectedFirstCourse = new CourseAssessmentDetails + { + CustomisationId = 100, + CentreId = 101, + ApplicationId = 1, + ApplicationName = "Entry Level - Win XP, Office 2003/07 OLD", + CustomisationName = "Standard", + Active = false, + CategoryName = "Undefined", + CourseTopic = "Undefined", + HasDiagnostic = false, + HasLearning = true, + IsAssessed = false, + }; + result.Should().HaveCount(256); result.First().Should().BeEquivalentTo(expectedFirstCourse); } From 03d38eae51348ef82b1d0142c287111ab2e08fda Mon Sep 17 00:00:00 2001 From: Jonathan Bloxsom Date: Fri, 19 Aug 2022 11:52:03 +0100 Subject: [PATCH 6/8] HEEDLS-1038 fix test --- .../Services/CourseServiceTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DigitalLearningSolutions.Data.Tests/Services/CourseServiceTests.cs b/DigitalLearningSolutions.Data.Tests/Services/CourseServiceTests.cs index 66a60c8d4c..b3f665907b 100644 --- a/DigitalLearningSolutions.Data.Tests/Services/CourseServiceTests.cs +++ b/DigitalLearningSolutions.Data.Tests/Services/CourseServiceTests.cs @@ -550,14 +550,14 @@ public void GetCourseOptionAlphabeticalListForCentre_calls_data_service() const int categoryId = 1; const int centreId = 1; var courseOptions = new List(); - A.CallTo(() => courseDataService.GetCoursesAvailableToCentreByCategory(centreId, categoryId)) + A.CallTo(() => courseDataService.GetNonArchivedCoursesAvailableToCentreByCategory(centreId, categoryId)) .Returns(courseOptions); // When var result = courseService.GetCourseOptionsAlphabeticalListForCentre(centreId, categoryId); // Then - A.CallTo(() => courseDataService.GetCoursesAvailableToCentreByCategory(centreId, categoryId)) + A.CallTo(() => courseDataService.GetNonArchivedCoursesAvailableToCentreByCategory(centreId, categoryId)) .MustHaveHappened(); result.Should().BeEquivalentTo(courseOptions); } From 4d7137e248446a957ecf40ba8bcf54266e3d95f3 Mon Sep 17 00:00:00 2001 From: Jonathan Bloxsom Date: Fri, 19 Aug 2022 11:59:29 +0100 Subject: [PATCH 7/8] HEEDLS-1038 reorganise code --- .../DataServices/CourseDataService.cs | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs index f4653ce652..2193145d70 100644 --- a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs @@ -145,6 +145,21 @@ FROM dbo.AssessAttempts AS aa WHERE aa.CustomisationID = cu.CustomisationID AND aa.[Status] = 1 AND can.CandidateId = ca.CandidateId) AS AttemptsPassed"; + private const string TutorialWithLearningCountQuery = + @"SELECT COUNT(ct.TutorialID) + FROM CustomisationTutorials AS ct + INNER JOIN Tutorials AS t ON ct.TutorialID = t.TutorialID + WHERE ct.Status = 1 AND ct.CustomisationID = c.CustomisationID"; + + private const string TutorialWithDiagnosticCountQuery = + @"SELECT COUNT(ct.TutorialID) + FROM CustomisationTutorials AS ct + INNER JOIN Tutorials AS t ON ct.TutorialID = t.TutorialID + INNER JOIN Customisations AS c ON c.CustomisationID = ct.CustomisationID + INNER JOIN Applications AS a ON a.ApplicationID = c.ApplicationID + WHERE ct.DiagStatus = 1 AND a.DiagAssess = 1 AND ct.CustomisationID = c.CustomisationID + AND a.ArchivedDate IS NULL AND a.DefaultContentTypeID <> 4"; + private readonly IDbConnection connection; private readonly ILogger logger; @@ -225,6 +240,27 @@ FROM Customisations cu LEFT OUTER JOIN AdminUsers auEnrolledBy ON auEnrolledBy.AdminID = pr.EnrolledByAdminID INNER JOIN Candidates AS ca ON ca.CandidateID = pr.CandidateID"; + private readonly string courseAssessmentDetailsQuery = $@"SELECT + c.CustomisationID, + c.CentreID, + c.ApplicationID, + ap.ApplicationName, + c.CustomisationName, + c.Active, + c.IsAssessed, + cc.CategoryName, + ct.CourseTopic, + CASE WHEN ({TutorialWithLearningCountQuery}) > 0 THEN 1 ELSE 0 END AS HasLearning, + CASE WHEN ({TutorialWithDiagnosticCountQuery}) > 0 THEN 1 ELSE 0 END AS HasDiagnostic + FROM Customisations AS c + INNER JOIN Applications AS ap ON ap.ApplicationID = c.ApplicationID + INNER JOIN CourseCategories AS cc ON ap.CourseCategoryId = cc.CourseCategoryId + INNER JOIN CourseTopics AS ct ON ap.CourseTopicId = ct.CourseTopicId + WHERE (c.CentreID = @centreId OR c.AllCentres = 1) + AND (ap.CourseCategoryID = @categoryId OR @categoryId IS NULL) + AND EXISTS (SELECT CentreApplicationID FROM CentreApplications WHERE (ApplicationID = c.ApplicationID) AND (CentreID = @centreID) AND (Active = 1)) + AND ap.DefaultContentTypeID <> 4"; + public CourseDataService(IDbConnection connection, ILogger logger) { this.connection = connection; @@ -477,46 +513,10 @@ FROM Customisations cu return names; } - private const string tutorialWithLearningCountQuery = - @"SELECT COUNT(ct.TutorialID) - FROM CustomisationTutorials AS ct - INNER JOIN Tutorials AS t ON ct.TutorialID = t.TutorialID - WHERE ct.Status = 1 AND ct.CustomisationID = c.CustomisationID"; - - private const string tutorialWithDiagnosticCountQuery = - @"SELECT COUNT(ct.TutorialID) - FROM CustomisationTutorials AS ct - INNER JOIN Tutorials AS t ON ct.TutorialID = t.TutorialID - INNER JOIN Customisations AS c ON c.CustomisationID = ct.CustomisationID - INNER JOIN Applications AS a ON a.ApplicationID = c.ApplicationID - WHERE ct.DiagStatus = 1 AND a.DiagAssess = 1 AND ct.CustomisationID = c.CustomisationID - AND a.ArchivedDate IS NULL AND a.DefaultContentTypeID <> 4"; - - private readonly string CourseAssessmentDetailsQuery = $@"SELECT - c.CustomisationID, - c.CentreID, - c.ApplicationID, - ap.ApplicationName, - c.CustomisationName, - c.Active, - c.IsAssessed, - cc.CategoryName, - ct.CourseTopic, - CASE WHEN ({tutorialWithLearningCountQuery}) > 0 THEN 1 ELSE 0 END AS HasLearning, - CASE WHEN ({tutorialWithDiagnosticCountQuery}) > 0 THEN 1 ELSE 0 END AS HasDiagnostic - FROM Customisations AS c - INNER JOIN Applications AS ap ON ap.ApplicationID = c.ApplicationID - INNER JOIN CourseCategories AS cc ON ap.CourseCategoryId = cc.CourseCategoryId - INNER JOIN CourseTopics AS ct ON ap.CourseTopicId = ct.CourseTopicId - WHERE (c.CentreID = @centreId OR c.AllCentres = 1) - AND (ap.CourseCategoryID = @categoryId OR @categoryId IS NULL) - AND EXISTS (SELECT CentreApplicationID FROM CentreApplications WHERE (ApplicationID = c.ApplicationID) AND (CentreID = @centreID) AND (Active = 1)) - AND ap.DefaultContentTypeID <> 4"; - public IEnumerable GetCoursesAvailableToCentreByCategory(int centreId, int? categoryId) { return connection.Query( - CourseAssessmentDetailsQuery, + courseAssessmentDetailsQuery, new { centreId, categoryId } ); } @@ -524,7 +524,7 @@ public IEnumerable GetCoursesAvailableToCentreByCategor public IEnumerable GetNonArchivedCoursesAvailableToCentreByCategory(int centreId, int? categoryId) { return connection.Query( - @$"{CourseAssessmentDetailsQuery} AND ap.ArchivedDate IS NULL", + @$"{courseAssessmentDetailsQuery} AND ap.ArchivedDate IS NULL", new { centreId, categoryId } ); } From 5322540f6f8730b5e4d1e5b3f2607c9a3b0e7c3e Mon Sep 17 00:00:00 2001 From: Jonathan Bloxsom Date: Fri, 19 Aug 2022 14:48:29 +0100 Subject: [PATCH 8/8] HEEDLS-1038 markups --- DigitalLearningSolutions.Data/DataServices/CourseDataService.cs | 2 -- DigitalLearningSolutions.Data/Services/CourseService.cs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs index 2193145d70..b5f9deeed8 100644 --- a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs @@ -408,7 +408,6 @@ public IEnumerable GetDelegateCoursesInfo(int delegateId) return connection.Query( $@"{selectDelegateCourseInfoQuery} WHERE pr.CandidateID = @delegateId - --AND ap.ArchivedDate IS NULL AND pr.RemovedDate IS NULL AND ap.DefaultContentTypeID <> 4", new { delegateId } @@ -420,7 +419,6 @@ AND pr.RemovedDate IS NULL return connection.QuerySingleOrDefault( $@"{selectDelegateCourseInfoQuery} WHERE pr.ProgressID = @progressId - --AND ap.ArchivedDate IS NULL AND ap.DefaultContentTypeID <> 4", new { progressId } ); diff --git a/DigitalLearningSolutions.Data/Services/CourseService.cs b/DigitalLearningSolutions.Data/Services/CourseService.cs index 54022c5ba4..8f8fbd3a52 100644 --- a/DigitalLearningSolutions.Data/Services/CourseService.cs +++ b/DigitalLearningSolutions.Data/Services/CourseService.cs @@ -156,7 +156,7 @@ public IEnumerable ); } - public IEnumerable + private IEnumerable GetNonArchivedCentreSpecificCourseStatisticsWithAdminFieldResponseCounts( int centreId, int? categoryId,