11namespace DigitalLearningSolutions . Web . Services
22{
3- using System . Collections . Generic ;
4- using System . Linq ;
53 using DigitalLearningSolutions . Data . DataServices ;
64 using DigitalLearningSolutions . Data . Enums ;
75 using DigitalLearningSolutions . Data . Models ;
86 using DigitalLearningSolutions . Data . Models . Courses ;
97 using DigitalLearningSolutions . Data . Utilities ;
10- using DocumentFormat . OpenXml . Spreadsheet ;
11-
8+ using Microsoft . Extensions . Configuration ;
9+ using System . Collections . Generic ;
10+ using System . Linq ;
11+ using ConfigurationExtensions = DigitalLearningSolutions . Data . Extensions . ConfigurationExtensions ;
1212 public interface ICourseService
1313 {
1414 public IEnumerable < CourseStatistics > GetTopCourseStatistics ( int centreId , int ? categoryId ) ;
1515
1616 public IEnumerable < CourseStatisticsWithAdminFieldResponseCounts >
1717 GetCentreSpecificCourseStatisticsWithAdminFieldResponseCounts (
1818 int centreId ,
19- int ? categoryId ,
20- bool includeAllCentreCourses = false
19+ int ? categoryId
2120 ) ;
2221
22+ public IEnumerable < CourseStatisticsWithAdminFieldResponseCounts >
23+ GetCentreSpecificCourseStatisticsWithAdminFieldResponseCountsForReport (
24+ int centreId ,
25+ int ? categoryId
26+ ) ;
27+
2328 public bool DelegateHasCurrentProgress ( int progressId ) ;
2429
2530 public void RemoveDelegateFromCourse (
@@ -117,6 +122,7 @@ public class CourseService : ICourseService
117122 private readonly IGroupsDataService groupsDataService ;
118123 private readonly IProgressDataService progressDataService ;
119124 private readonly ISectionService sectionService ;
125+ private readonly IConfiguration configuration ;
120126
121127 public CourseService (
122128 IClockUtility clockUtility ,
@@ -126,7 +132,8 @@ public CourseService(
126132 IGroupsDataService groupsDataService ,
127133 ICourseCategoriesDataService courseCategoriesDataService ,
128134 ICourseTopicsDataService courseTopicsDataService ,
129- ISectionService sectionService
135+ ISectionService sectionService ,
136+ IConfiguration configuration
130137 )
131138 {
132139 this . clockUtility = clockUtility ;
@@ -137,6 +144,7 @@ ISectionService sectionService
137144 this . courseCategoriesDataService = courseCategoriesDataService ;
138145 this . courseTopicsDataService = courseTopicsDataService ;
139146 this . sectionService = sectionService ;
147+ this . configuration = configuration ;
140148 }
141149
142150 public IEnumerable < CourseStatistics > GetTopCourseStatistics ( int centreId , int ? categoryId )
@@ -148,15 +156,39 @@ public IEnumerable<CourseStatistics> GetTopCourseStatistics(int centreId, int? c
148156 public IEnumerable < CourseStatisticsWithAdminFieldResponseCounts >
149157 GetCentreSpecificCourseStatisticsWithAdminFieldResponseCounts (
150158 int centreId ,
151- int ? categoryId ,
152- bool includeAllCentreCourses = false
159+ int ? categoryId
153160 )
154161 {
155162 var allCourses = courseDataService . GetCourseStatisticsAtCentreFilteredByCategory ( centreId , categoryId ) ;
156- return allCourses . Where ( c => c . CentreId == centreId || c . AllCentres && includeAllCentreCourses ) . Select (
163+ return allCourses . Where ( c => c . CentreId == centreId ) . Select (
157164 c => new CourseStatisticsWithAdminFieldResponseCounts (
158- c ,
159- courseAdminFieldsService . GetCourseAdminFieldsWithAnswerCountsForCourse ( c . CustomisationId , centreId )
165+ c , courseAdminFieldsService . GetCourseAdminFieldsWithAnswerCountsForCourse ( c . CustomisationId , centreId )
166+ )
167+ ) ;
168+ }
169+
170+ public IEnumerable < CourseStatisticsWithAdminFieldResponseCounts >
171+ GetCentreSpecificCourseStatisticsWithAdminFieldResponseCountsForReport (
172+ int centreId ,
173+ int ? categoryId
174+ )
175+ {
176+ var exportQueryRowLimit = ConfigurationExtensions . GetExportQueryRowLimit ( configuration ) ;
177+
178+ int resultCount = courseDataService . GetCourseStatisticsAtCentreFilteredByCategoryResultCount ( centreId , categoryId ) ;
179+
180+ int totalRun = ( int ) ( resultCount / exportQueryRowLimit ) + ( ( resultCount % exportQueryRowLimit ) > 0 ? 1 : 0 ) ;
181+ int currentRun = 1 ;
182+
183+ List < CourseStatistics > allCourses = new List < CourseStatistics > ( ) ;
184+ while ( totalRun >= currentRun )
185+ {
186+ allCourses . AddRange ( courseDataService . GetCourseStatisticsAtCentreFilteredByCategory ( centreId , categoryId , exportQueryRowLimit , currentRun ) ) ;
187+ currentRun ++ ;
188+ }
189+ return allCourses . Where ( c => c . CentreId == centreId || c . AllCentres ) . Select (
190+ c => new CourseStatisticsWithAdminFieldResponseCounts (
191+ c , courseAdminFieldsService . GetCourseAdminFieldsWithAnswerCountsForCourse ( c . CustomisationId , centreId )
160192 )
161193 ) ;
162194 }
@@ -364,12 +396,12 @@ public CentreCourseDetails GetCentreCourseDetails(int centreId, int? categoryId)
364396 return new CentreCourseDetails ( courses , categories , topics ) ;
365397 }
366398
367-
399+
368400
369401 public ( IEnumerable < CourseStatisticsWithAdminFieldResponseCounts > , int ) GetCentreCourses ( string searchString , int offSet , int itemsPerPage , string sortBy , string sortDirection , int centreId , int ? categoryId , bool allCentreCourses , bool ? hideInLearnerPortal ,
370402 string isActive , string categoryName , string courseTopic , string hasAdminFields )
371403 {
372- var ( allCourses , resultCount ) = courseDataService . GetCourseStatisticsAtCentre ( searchString , offSet , itemsPerPage , sortBy , sortDirection , centreId , categoryId , allCentreCourses , hideInLearnerPortal ,
404+ var ( allCourses , resultCount ) = courseDataService . GetCourseStatisticsAtCentre ( searchString , offSet , itemsPerPage , sortBy , sortDirection , centreId , categoryId , allCentreCourses , hideInLearnerPortal ,
373405 isActive , categoryName , courseTopic , hasAdminFields ) ;
374406
375407 return ( allCourses . Select (
@@ -382,9 +414,7 @@ public CentreCourseDetails GetCentreCourseDetails(int centreId, int? categoryId)
382414
383415 public CentreCourseDetails GetCentreCourseDetailsWithAllCentreCourses ( int centreId , int ? categoryId )
384416 {
385- var ( courses , categories , topics ) = (
386- GetCentreSpecificCourseStatisticsWithAdminFieldResponseCounts ( centreId , categoryId , true ) ,
387- courseCategoriesDataService . GetCategoriesForCentreAndCentrallyManagedCourses ( centreId )
417+ var ( courses , categories , topics ) = ( GetCentreSpecificCourseStatisticsWithAdminFieldResponseCountsForReport ( centreId , categoryId ) , courseCategoriesDataService . GetCategoriesForCentreAndCentrallyManagedCourses ( centreId )
388418 . Select ( c => c . CategoryName ) ,
389419 courseTopicsDataService . GetCourseTopicsAvailableAtCentre ( centreId ) . Select ( c => c . CourseTopic ) ) ;
390420
0 commit comments