diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index a1716767a..825914c97 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -7,6 +7,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; + using LearningHub.Nhs.Models.Entities.Resource; using LearningHub.Nhs.Models.Enums; using LearningHub.Nhs.Models.Resource; using LearningHub.Nhs.Models.Resource.Blocks; @@ -492,8 +493,12 @@ public async Task SaveWeblinkDetailAsync([FromBody] WebLinkViewMod public async Task SaveCaseDetailAsync([FromBody] CaseViewModel request) { var existingResourceState = await this.resourceService.GetResourceVersionExtendedAsync(request.ResourceVersionId); + if (existingResourceState?.CaseDetails?.BlockCollection != null) + { + await this.RemoveBlockCollectionFiles(request.ResourceVersionId, existingResourceState.CaseDetails.BlockCollection, request.BlockCollection); + } + int resourceVersionId = await this.contributeService.SaveCaseDetailAsync(request); - this.RemoveDeletedCaseFiles(existingResourceState?.CaseDetails, request); return this.Ok(resourceVersionId); } @@ -506,6 +511,12 @@ public async Task SaveCaseDetailAsync([FromBody] CaseViewModel req [Route("SaveAssessmentDetail")] public async Task SaveAssessmentDetailAsync([FromBody] AssessmentViewModel request) { + var existingResourceState = await this.resourceService.GetResourceVersionExtendedAsync(request.ResourceVersionId); + if (existingResourceState != null && existingResourceState.AssessmentDetails != null) + { + await this.RemoveBlockCollectionFiles(request.ResourceVersionId, existingResourceState.AssessmentDetails, request); + } + int resourceVersionId = await this.contributeService.SaveAssessmentDetailAsync(request); return this.Ok(resourceVersionId); } @@ -627,15 +638,29 @@ private async Task UserCanEditCatalogue(int catalogueId) return await this.catalogueService.CanCurrentUserEditCatalogue(catalogueId); } - private void RemoveDeletedCaseFiles(CaseViewModel existingResource, CaseViewModel newResource) + private async Task RemoveBlockCollectionFiles(int resourceVersionId, AssessmentViewModel existingModel, AssessmentViewModel newModel) + { + if (existingModel is { EndGuidance: { } } && existingModel.EndGuidance.Blocks != null) + { + await this.RemoveBlockCollectionFiles(resourceVersionId, existingModel.EndGuidance, newModel.EndGuidance); + } + + if (existingModel is { AssessmentContent: { } } && existingModel.AssessmentContent.Blocks != null) + { + await this.RemoveBlockCollectionFiles(resourceVersionId, existingModel.AssessmentContent, newModel.AssessmentContent); + } + } + + private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollectionViewModel existingResource, BlockCollectionViewModel newResource) { try { + var obsoleteFiles = await this.resourceService.GetObsoleteResourceFile(resourceVersionId, true); var filePaths = new List(); - if (existingResource != null && existingResource.BlockCollection != null) + if (existingResource != null) { - var allBlocks = existingResource.BlockCollection.Blocks.ToList(); - var newBlocks = newResource.BlockCollection.Blocks.ToList(); + var allBlocks = existingResource.Blocks.ToList(); + var newBlocks = newResource.Blocks.ToList(); if (allBlocks.Any()) { var existingAttachements = allBlocks.Where(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Attachment && x.MediaBlock.Attachment != null).ToList(); @@ -643,7 +668,7 @@ private void RemoveDeletedCaseFiles(CaseViewModel existingResource, CaseViewMode { foreach (var oldblock in existingAttachements) { - var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Attachment && x.MediaBlock.Attachment != null && x.MediaBlock.Attachment.File?.FileId == oldblock.MediaBlock.Attachment?.File?.FileId); + var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Attachment && x.MediaBlock.Attachment != null && (x.MediaBlock.Attachment.File?.FileId == oldblock.MediaBlock.Attachment?.File?.FileId || x.MediaBlock.Attachment.File?.FilePath == oldblock.MediaBlock.Attachment?.File?.FilePath)); if (entry == null) { filePaths.Add(oldblock.MediaBlock.Attachment?.File?.FilePath); @@ -656,13 +681,22 @@ private void RemoveDeletedCaseFiles(CaseViewModel existingResource, CaseViewMode { foreach (var oldblock in existingVideos) { - var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Video && x.MediaBlock.Video != null && x.MediaBlock.Video.VideoFile?.File?.FileId == oldblock.MediaBlock?.Video?.VideoFile?.File?.FileId); + var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Video && x.MediaBlock.Video != null && (x.MediaBlock.Video.VideoFile?.File?.FileId == oldblock.MediaBlock?.Video?.VideoFile?.File?.FileId || x.MediaBlock.Video.VideoFile?.File?.FilePath == oldblock.MediaBlock?.Video?.VideoFile?.File?.FilePath)); if (entry == null) { - filePaths.Add(oldblock.MediaBlock.Video?.VideoFile?.File?.FilePath); - if (oldblock.MediaBlock?.Video?.VideoFile?.TranscriptFile?.File?.FilePath != null) + if (!string.IsNullOrWhiteSpace(oldblock.MediaBlock.Video.File.FilePath)) { - filePaths.Add(oldblock.MediaBlock.Video?.VideoFile?.TranscriptFile?.File?.FilePath); + filePaths.Add(oldblock.MediaBlock.Video.File.FilePath); + } + + if (!string.IsNullOrWhiteSpace(oldblock.MediaBlock.Video?.File?.VideoFile?.File?.FilePath)) + { + filePaths.Add(oldblock.MediaBlock.Video.File.VideoFile.File.FilePath); + } + + if (oldblock.MediaBlock?.Video?.File?.VideoFile?.TranscriptFile?.File?.FilePath != null) + { + filePaths.Add(oldblock.MediaBlock.Video.File.VideoFile.TranscriptFile.File.FilePath); } } } @@ -673,8 +707,8 @@ private void RemoveDeletedCaseFiles(CaseViewModel existingResource, CaseViewMode { foreach (var oldblock in existingImages) { - var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Image && x.MediaBlock.Image != null && x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId); - if (entry == null) + var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Image && x.MediaBlock.Image != null && (x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId || x.MediaBlock?.Image?.File?.FilePath == oldblock.MediaBlock?.Image?.File?.FilePath)); + if (entry == null) { filePaths.Add(oldblock?.MediaBlock?.Image?.File?.FilePath); } @@ -688,7 +722,7 @@ private void RemoveDeletedCaseFiles(CaseViewModel existingResource, CaseViewMode { foreach (var oldblock in imageBlock?.ImageCarouselBlock?.ImageBlockCollection?.Blocks) { - var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.ImageCarousel && x.ImageCarouselBlock != null && x.ImageCarouselBlock.ImageBlockCollection != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks.Where(x => x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId).Any()); + var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.ImageCarousel && x.ImageCarouselBlock != null && x.ImageCarouselBlock.ImageBlockCollection != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks != null && x.ImageCarouselBlock.ImageBlockCollection.Blocks.Where(x => x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId || x.MediaBlock?.Image?.File?.FilePath == oldblock.MediaBlock?.Image?.File?.FilePath).Any()); if (entry == null) { filePaths.Add(oldblock.MediaBlock?.Image?.File?.FilePath); @@ -704,7 +738,7 @@ private void RemoveDeletedCaseFiles(CaseViewModel existingResource, CaseViewMode { foreach (var oldblock in wsi?.WholeSlideImageBlock?.WholeSlideImageBlockItems) { - var entry = newBlocks.FirstOrDefault(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Where(x => x.WholeSlideImage?.File?.FileId == oldblock.WholeSlideImage?.File?.FileId).Any()); + var entry = newBlocks.FirstOrDefault(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Where(x => x.WholeSlideImage?.File?.FileId == oldblock.WholeSlideImage?.File?.FileId || x.WholeSlideImage?.File?.FilePath == oldblock.WholeSlideImage?.File?.FilePath).Any()); if (entry == null) { filePaths.Add(oldblock.WholeSlideImage?.File?.FilePath); @@ -713,16 +747,167 @@ private void RemoveDeletedCaseFiles(CaseViewModel existingResource, CaseViewMode } } } + + var existingQuestionFiles = this.CheckQuestionBlock(existingResource); + var newQuestionFiles = this.CheckQuestionBlock(newResource); + if (existingQuestionFiles.Any()) + { + if (!newQuestionFiles.Any()) + { + filePaths.AddRange(existingQuestionFiles.Values.ToList()); + } + else + { + foreach (var file in existingQuestionFiles) + { + bool found = false; + var entry = newQuestionFiles.FirstOrDefault(x => (x.Key == file.Key || x.Value == file.Value) && (found = true)); + if (!found) + { + filePaths.Add(file.Value); + } + } + } + } } if (filePaths != null && filePaths.Any()) { - _ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, filePaths); }); + var deleteList = new List(); + foreach (var e in filePaths) + { + if (!obsoleteFiles.Contains(e)) + { + continue; + } + + deleteList.Add(e); + } + + _ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, deleteList); }); } } catch (Exception ex) { } } + + private Dictionary CheckQuestionBlock(BlockCollectionViewModel model) + { + var filePath = new Dictionary(); + if (model != null && model.Blocks.Any()) + { + foreach (var block in model.Blocks) + { + if (block.BlockType == BlockType.Question && block.QuestionBlock != null) + { + if (block.QuestionBlock.QuestionType == QuestionTypeEnum.MatchGame && block.QuestionBlock.Answers != null) + { + foreach (var answerBlock in block.QuestionBlock.Answers) + { + if (answerBlock.BlockCollection != null && answerBlock.BlockCollection.Blocks != null && answerBlock.BlockCollection.Blocks.Any()) + { + foreach (var imageBlock in answerBlock.BlockCollection.Blocks) + { + if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null) + { + filePath.Add(imageBlock.MediaBlock.Image.File.FileId, imageBlock.MediaBlock.Image.File.FilePath); + } + } + } + } + } + + var questionBlockCollection = block.QuestionBlock.QuestionBlockCollection; + if (questionBlockCollection != null && questionBlockCollection.Blocks != null && questionBlockCollection.Blocks.Any()) + { + foreach (var questionBlock in questionBlockCollection.Blocks) + { + if (questionBlock.BlockType == BlockType.Media && questionBlock.MediaBlock != null) + { + if (questionBlock.MediaBlock.Image != null) + { + filePath.Add(questionBlock.MediaBlock.Image.File.FileId, questionBlock.MediaBlock.Image.File.FilePath); + } + + if (questionBlock.MediaBlock.Video != null) + { + if (questionBlock.MediaBlock.Video.VideoFile != null) + { + if (questionBlock.MediaBlock.Video.File != null) + { + filePath.Add(questionBlock.MediaBlock.Video.File.FileId, questionBlock.MediaBlock.Video.File.FilePath); + } + + if (questionBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) + { + filePath.Add(questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FileId, questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); + } + + if (questionBlock.MediaBlock.Video.VideoFile.CaptionsFile != null) + { + filePath.Add(questionBlock.MediaBlock.Video.VideoFile.CaptionsFile.File.FileId, questionBlock.MediaBlock.Video.VideoFile.CaptionsFile.File.FilePath); + } + } + } + } + else if (questionBlock.BlockType == BlockType.WholeSlideImage && questionBlock.WholeSlideImageBlock != null && questionBlock.WholeSlideImageBlock.WholeSlideImageBlockItems.Any()) + { + var existingWholeSlideImages = questionBlock.WholeSlideImageBlock?.WholeSlideImageBlockItems; + if (existingWholeSlideImages != null && existingWholeSlideImages.Any()) + { + foreach (var wsi in existingWholeSlideImages) + { + if (wsi.WholeSlideImage != null && wsi.WholeSlideImage.File != null && wsi.WholeSlideImage.File.WholeSlideImageFile != null && (wsi.WholeSlideImage.File.WholeSlideImageFile.Status == WholeSlideImageFileStatus.ProcessingComplete || wsi.WholeSlideImage.File.WholeSlideImageFile.Status == WholeSlideImageFileStatus.ProcessingFailed)) + { + filePath.Add(wsi.WholeSlideImage.File.FileId, wsi.WholeSlideImage.File.FilePath); + } + } + } + } + } + } + + var feedbackBlockCollection = block.QuestionBlock.FeedbackBlockCollection; + if (feedbackBlockCollection != null && feedbackBlockCollection.Blocks != null && feedbackBlockCollection.Blocks.Any()) + { + foreach (var feedbackBlock in feedbackBlockCollection.Blocks) + { + if (feedbackBlock.BlockType == BlockType.Media && feedbackBlock.MediaBlock != null) + { + if (feedbackBlock.MediaBlock.Image != null) + { + filePath.Add(feedbackBlock.MediaBlock.Image.File.FileId, feedbackBlock.MediaBlock.Image.File.FilePath); + } + + if (feedbackBlock.MediaBlock.Video != null) + { + if (feedbackBlock.MediaBlock.Video.VideoFile != null) + { + if (feedbackBlock.MediaBlock.Video.File != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.File.FileId, feedbackBlock.MediaBlock.Video.File.FilePath); + } + + if (feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FileId, feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); + } + + if (feedbackBlock.MediaBlock.Video.VideoFile.CaptionsFile != null) + { + filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.CaptionsFile.File.FileId, feedbackBlock.MediaBlock.Video.VideoFile.CaptionsFile.File.FilePath); + } + } + } + } + } + } + } + } + } + + return filePath; + } } } diff --git a/LearningHub.Nhs.WebUI/Helpers/ViewActivityHelper.cs b/LearningHub.Nhs.WebUI/Helpers/ViewActivityHelper.cs index f77383f0c..d23e0881e 100644 --- a/LearningHub.Nhs.WebUI/Helpers/ViewActivityHelper.cs +++ b/LearningHub.Nhs.WebUI/Helpers/ViewActivityHelper.cs @@ -226,7 +226,7 @@ public static string GetActivityStatusText(this ActivityDetailedItemViewModel ac /// The . public static bool CanShowScore(this ActivityDetailedItemViewModel activityDetailedItemViewModel) { - if ((activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Scorm && (activityDetailedItemViewModel.MasteryScore > 0 || activityDetailedItemViewModel.MasteryScore == null) && ((activityDetailedItemViewModel.ScorePercentage > 0 && activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Passed) || activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Failed)) || ((activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Assessment || activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Case) && activityDetailedItemViewModel.Complete)) + if ((activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Scorm && (activityDetailedItemViewModel.MasteryScore > 0 || activityDetailedItemViewModel.MasteryScore == null) && ((activityDetailedItemViewModel.ScorePercentage > 0 && activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Passed) || activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Failed)) || (activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Assessment && (activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Completed || activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Passed || activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.Failed)) || (activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Case && activityDetailedItemViewModel.Complete)) { return true; } @@ -241,7 +241,7 @@ public static bool CanShowScore(this ActivityDetailedItemViewModel activityDetai /// The bool. public static bool CanViewPercentage(this ActivityDetailedItemViewModel activityDetailedItemViewModel) { - if (((activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Video || activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Audio) && activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.InProgress) || (activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Assessment && activityDetailedItemViewModel.Complete == false)) + if (((activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Video || activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Audio) && activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.InProgress) || (activityDetailedItemViewModel.ResourceType == ResourceTypeEnum.Assessment && activityDetailedItemViewModel.ActivityStatus == ActivityStatusEnum.InProgress)) { return true; } diff --git a/LearningHub.Nhs.WebUI/Services/FileService.cs b/LearningHub.Nhs.WebUI/Services/FileService.cs index af8d5572c..4e02db124 100644 --- a/LearningHub.Nhs.WebUI/Services/FileService.cs +++ b/LearningHub.Nhs.WebUI/Services/FileService.cs @@ -230,50 +230,10 @@ public async Task PurgeResourceFile(ResourceVersionExtendedViewModel vm = null, { allContentPath.Add(vm.ScormDetails.ContentFilePath); } - else if (vm.GenericFileDetails != null && !string.IsNullOrWhiteSpace(vm.GenericFileDetails.File.FilePath)) - { - allFilePath.Add(vm.GenericFileDetails.File.FilePath); - } else if (vm.HtmlDetails != null && !string.IsNullOrWhiteSpace(vm.HtmlDetails.ContentFilePath)) { allContentPath.Add(vm.HtmlDetails.ContentFilePath); } - else if (vm.ImageDetails != null && !string.IsNullOrWhiteSpace(vm.ImageDetails.File?.FilePath)) - { - allFilePath.Add(vm.ImageDetails.File?.FilePath); - } - else if (vm.ArticleDetails != null) - { - var files = vm.ArticleDetails.Files.ToList(); - if (files.Any()) - { - foreach (var file in files) - { - allFilePath.Add(file.FilePath); - } - } - } - else if (vm.CaseDetails != null) - { - var blockCollection = vm.CaseDetails.BlockCollection; - foreach (var entry in blockCollection.Blocks) - { - if (entry.ImageCarouselBlock != null) - { - foreach (var item in entry.ImageCarouselBlock?.ImageBlockCollection?.Blocks) - { - allFilePath.Add(item?.MediaBlock?.Image?.File.FilePath); - } - } - else if (entry.WholeSlideImageBlock != null) - { - foreach (var item in entry.WholeSlideImageBlock.WholeSlideImageBlockItems) - { - allFilePath.Add(item?.WholeSlideImage?.File.FilePath); - } - } - } - } // audio and video to be added await this.MoveInPutDirectoryToArchive(allFilePath); @@ -349,7 +309,7 @@ private async Task MoveOutPutDirectoryToArchive(List allDirectoryRef) } } - await directory.DeleteAsync(); + await directory.DeleteIfExistsAsync(); } } } @@ -405,6 +365,8 @@ private async Task DeleteSubdirectory(string pathDirectory) await sourceFileClient.DeleteIfExistsAsync(); } } + + await sourceDirectory.DeleteIfExistsAsync(); } private async Task MoveInPutDirectoryToArchive(List allDirectoryRef) diff --git a/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj b/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj index bc730fb58..2613eb68c 100644 --- a/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj +++ b/WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj @@ -513,6 +513,7 @@ + diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql index fdd97300c..1e83fc9b8 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLatestActivityCheck.sql @@ -162,10 +162,15 @@ FROM ( EXISTS ( SELECT 1 FROM [activity].[ResourceActivity] AS [ResAct2] - WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7) + WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7,5,4) ) ) + AND + ( + -- resource type is not assessment and activity status is Complete/Incomplete + [Res].[ResourceTypeId] <> 11 OR [ResourceActivity].[ActivityStatusId] in (7,3) + ) ) AS [t2] LEFT JOIN [resources].[VideoResourceVersion] AS [VideoResourceVersion] ON [t2].[Id1] = [VideoResourceVersion].[ResourceVersionId] diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql index d8b8d3c5a..c96931937 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivities.sql @@ -175,7 +175,7 @@ FROM ( @searchText IS NULL OR ( - Charindex(@searchText, [ResVer].[Title]) > 0 + (Charindex(@searchText, [ResVer].[Title]) > 0 OR Charindex(@searchText, [ResVer].[Description]) > 0 OR @@ -189,8 +189,8 @@ FROM ( [ResVer].[Id] = [ResourceVersionKeyword].[ResourceVersionId] AND Charindex(@searchText, [ResourceVersionKeyword].[Keyword]) > 0 - ) - ) + ) + )) AND [ResourceActivity].ActivityStart is not null ) ) AND @@ -230,10 +230,15 @@ FROM ( EXISTS ( SELECT 1 FROM [activity].[ResourceActivity] AS [ResAct2] - WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7) + WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7,5,4) ) ) + AND + ( + -- resource type is not assessment and activity status is Complete/Incomplete + [Res].[ResourceTypeId] <> 11 OR [ResourceActivity].[ActivityStatusId] in (7,3) + ) AND ( @filterActivityStatus = 0 diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql index 0fff8bc1d..daa20e0e7 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Activity/GetUserLearningActivitiesCount.sql @@ -90,7 +90,7 @@ FROM ( @searchText IS NULL OR ( - Charindex(@searchText, [ResVer].[Title]) > 0 + (Charindex(@searchText, [ResVer].[Title]) > 0 OR Charindex(@searchText, [ResVer].[Description]) > 0 OR @@ -104,8 +104,8 @@ FROM ( [ResVer].[Id] = [ResourceVersionKeyword].[ResourceVersionId] AND Charindex(@searchText, [ResourceVersionKeyword].[Keyword]) > 0 - ) - ) + ) + )) AND [ResourceActivity].ActivityStart is not null ) ) AND @@ -145,10 +145,15 @@ FROM ( EXISTS ( SELECT 1 FROM [activity].[ResourceActivity] AS [ResAct2] - WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7) + WHERE [ResAct2].[Deleted] = 0 AND [ResourceActivity].[Id] = [ResAct2].[LaunchResourceActivityId] AND [ResAct2].[ActivityStatusId] in (3,7,5,4) ) ) + AND + ( + -- resource type is not assessment and activity status is Complete/Incomplete + [Res].[ResourceTypeId] <> 11 OR [ResourceActivity].[ActivityStatusId] in (7,3) + ) AND ( @filterActivityStatus = 0 diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/BlockCollectionFileSearch.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/BlockCollectionFileSearch.sql new file mode 100644 index 000000000..00b4aa351 --- /dev/null +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/BlockCollectionFileSearch.sql @@ -0,0 +1,679 @@ +------------------------------------------------------------------------------- +-- Author Tobi Awe +-- Created 30-05-2024 +-- Purpose search all assessment/case block collections files + + +-- Modification History +-- +-- 31-05-2024 TD-3023 Initial Revision +------------------------------------------------------------------------------- + + +CREATE PROCEDURE [resources].[BlockCollectionFileSearch] ( + @excludeResourceVersionId INT, + @resourceType INT, + @filePath nvarchar(max) output +) +AS +BEGIN + -- Table to hold BlockCollectionIds + DECLARE @BlockCollectionId TABLE (Id INT); + DECLARE @AllBlockAssociatedFiles TABLE (FileId INT, FilePath NVARCHAR(200)); + SET @filePath = NULL; + + -- Insert BlockCollectionIds based on the provided query + IF @resourceType = 10 +BEGIN + --case +INSERT INTO @BlockCollectionId (Id) +SELECT DISTINCT c.BlockCollectionId +FROM [resources].[CaseResourceVersion] AS c +INNER JOIN [resources].[ResourceVersion] AS r + ON c.ResourceVersionId = r.Id +INNER JOIN [resources].[Resource] AS r0 + ON r.ResourceId = r0.Id +WHERE + c.Deleted = 0 + AND r.Deleted = 0 + AND r0.Deleted = 0 + AND c.ResourceVersionId <> @excludeResourceVersionId + AND (r.VersionStatusId <> 2 OR (r.VersionStatusId = 2 AND r0.CurrentResourceVersionId = c.ResourceVersionId)) + AND c.BlockCollectionId IS NOT NULL; + +END +ELSE IF @resourceType = 11 +BEGIN + --assessment + INSERT INTO @BlockCollectionId (Id) +SELECT DISTINCT Id +FROM ( + SELECT + c.AssessmentContentId AS Id + FROM + [resources].AssessmentResourceVersion AS c + INNER JOIN + [resources].ResourceVersion AS r ON c.ResourceVersionId = r.Id + INNER JOIN + [resources].Resource AS r0 ON r.ResourceId = r0.Id + WHERE + c.Deleted = CAST(0 AS bit) + AND r.Deleted = CAST(0 AS bit) + AND r0.Deleted = CAST(0 AS bit) + AND c.ResourceVersionId <> @excludeResourceVersionId + AND (r.VersionStatusId <> 2 OR (r.VersionStatusId = 2 AND r0.CurrentResourceVersionId = c.ResourceVersionId)) + AND c.AssessmentContentId IS NOT NULL + + UNION ALL + + SELECT + c.EndGuidanceId AS Id + FROM + [resources].AssessmentResourceVersion AS c + INNER JOIN + [resources].ResourceVersion AS r ON c.ResourceVersionId = r.Id + INNER JOIN + [resources].Resource AS r0 ON r.ResourceId = r0.Id + WHERE + c.Deleted = CAST(0 AS bit) + AND r.Deleted = CAST(0 AS bit) + AND r0.Deleted = CAST(0 AS bit) + AND c.ResourceVersionId <> @excludeResourceVersionId + AND (r.VersionStatusId <> 2 OR (r.VersionStatusId = 2 AND r0.CurrentResourceVersionId = c.ResourceVersionId)) + AND c.EndGuidanceId IS NOT NULL +) as assessmentBlockCollections; +END + + -- Table to hold temp results for blocks + DECLARE @TempBlockResult TABLE ( + Id INT, + [Order] INT, + Title NVARCHAR(200), + BlockType INT, + BlockCollectionId INT + ); + + -- Table to hold results for blocks + DECLARE @BlockResult TABLE ( + Id INT, + [Order] INT, + Title NVARCHAR(200), + BlockType INT, + BlockCollectionId INT + ); + + -- Insert temp block data + INSERT INTO @TempBlockResult + SELECT Id, [Order], Title, BlockType, BlockCollectionId + FROM resources.Block + WHERE Deleted = 0 AND BlockCollectionId IN (SELECT Id FROM @BlockCollectionId); + + -- Insert ImageCarouselBlockCollectionId + INSERT INTO @BlockCollectionId (Id) + SELECT icb.ImageBlockCollectionId + FROM resources.ImageCarouselBlock icb + INNER JOIN @TempBlockResult b ON icb.BlockId = b.Id + WHERE icb.Deleted = 0; + +--Insert QuestionBlockCollectionId and FeedbackBlockCollectionId + INSERT INTO @BlockCollectionId (Id) + SELECT qb.QuestionBlockCollectionId + FROM resources.QuestionBlock qb + INNER JOIN @TempBlockResult b ON qb.BlockId = b.Id + WHERE qb.Deleted = 0 + + UNION + + SELECT qb.FeedbackBlockCollectionId + FROM resources.QuestionBlock qb + INNER JOIN @TempBlockResult b ON qb.BlockId = b.Id + WHERE qb.Deleted = 0; + + + -- Insert block data + INSERT INTO @BlockResult + SELECT Id, [Order], Title, BlockType, BlockCollectionId + FROM resources.Block + WHERE Deleted = 0 AND BlockCollectionId IN (SELECT Id FROM @BlockCollectionId); + + + + -- WholeSlide Image Block + DECLARE @WsibResult TABLE ( + Id INT, + BlockId INT + ); + + INSERT INTO @WsibResult + SELECT w.Id, w.BlockId + FROM resources.WholeSlideImageBlock w + INNER JOIN @BlockResult b ON b.Id = w.BlockId + WHERE w.Deleted = 0; + + -- SELECT * FROM @WsibResult; + + -- WholeSlide Image Block Items + DECLARE @WsibiResult TABLE ( + Id INT, + WholeSlideImageBlockId INT, + WholeSlideImageId INT, + PlaceholderText NVARCHAR(255), + [Order] INT + ); + + INSERT INTO @WsibiResult + SELECT wi.Id, wi.WholeSlideImageBlockId, wi.WholeSlideImageId, wi.PlaceholderText, wi.[Order] + FROM resources.WholeSlideImageBlockItem wi + INNER JOIN @WsibResult w ON wi.WholeSlideImageBlockId = w.Id + WHERE wi.Deleted = 0; + + --SELECT * FROM @WsibiResult; + + -- WholeSlide Image + DECLARE @WsiResult TABLE ( + Id INT, + Title NVARCHAR(1000), + FileId INT + ); + + INSERT INTO @WsiResult + SELECT wsi.Id, wsi.Title, wsi.FileId + FROM resources.WholeSlideImage wsi + INNER JOIN @WsibiResult wi ON wsi.Id = wi.WholeSlideImageId + WHERE wsi.Deleted = 0; + + + --SELECT * FROM @WsiResult; + + -- WholeSlide Image File + DECLARE @WsiFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @WsiFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @WsiResult wsi ON f.Id = wsi.FileId + WHERE f.Deleted = 0; + + INSERT INTO @AllBlockAssociatedFiles + SELECT Id,FilePath FROM @WsiFileResult; + + + + -- Media Block + DECLARE @MediaBlockResult TABLE ( + Id INT, + BlockId INT, + MediaType INT, + AttachmentId INT, + ImageId INT, + VideoId INT + ); + + INSERT INTO @MediaBlockResult + SELECT mb.Id, mb.BlockId, mb.MediaType, mb.AttachmentId, mb.ImageId, mb.VideoId + FROM resources.MediaBlock mb + INNER JOIN @BlockResult b ON mb.BlockId = b.Id + WHERE mb.Deleted = 0; + + + --SELECT * FROM @MediaBlockResult; + + -- Attachment + DECLARE @AttachmentResult TABLE ( + Id INT, + FileId INT + ); + + INSERT INTO @AttachmentResult + SELECT a.Id, a.FileId + FROM resources.Attachment a + INNER JOIN @MediaBlockResult mb ON a.Id = mb.AttachmentId + WHERE a.Deleted = 0; + + --SELECT * FROM @AttachmentResult; + + -- Attachment File + DECLARE @AttachmentFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @AttachmentFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @AttachmentResult ar ON f.Id = ar.FileId + WHERE f.Deleted = 0; + + INSERT INTO @AllBlockAssociatedFiles + SELECT Id,FilePath FROM @AttachmentFileResult; + + -- Attachment File - Partial File + INSERT INTO @AllBlockAssociatedFiles + SELECT pf.FileId,af.FilePath + FROM resources.PartialFile pf + INNER JOIN @AttachmentFileResult af ON pf.FileId = af.Id + WHERE pf.Deleted = 0; + + -- Image + DECLARE @ImageResult TABLE ( + Id INT, + FileId INT, + AltText NVARCHAR(125), + Description NVARCHAR(250) + ); + + INSERT INTO @ImageResult + SELECT i.Id, i.FileId, i.AltText, i.Description + FROM resources.Image i + INNER JOIN @MediaBlockResult mb ON i.Id = mb.ImageId + WHERE i.Deleted = 0; + + --SELECT * FROM @ImageResult; + + -- Image File + DECLARE @ImageFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @ImageFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @ImageResult ir ON f.Id = ir.FileId + WHERE f.Deleted = 0; + + INSERT INTO @AllBlockAssociatedFiles + SELECT Id,FilePath FROM @ImageFileResult; + + + -- Video + DECLARE @VideoResult TABLE ( + Id INT, + FileId INT + ); + + INSERT INTO @VideoResult + SELECT v.Id, v.FileId + FROM resources.Video v + INNER JOIN @MediaBlockResult mb ON v.Id = mb.VideoId + WHERE v.Deleted = 0; + + -- SELECT * FROM @VideoResult; + + -- Video File + DECLARE @VideoFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @VideoFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @VideoResult vr ON f.Id = vr.FileId + WHERE f.Deleted = 0; + + INSERT INTO @AllBlockAssociatedFiles + SELECT Id,FilePath FROM @VideoFileResult; + + --SELECT * FROM @AllBlockAssociatedFiles; +---------------------------------------------------------------------------------------------------------------------- + + + + -- Table to hold BlockCollectionIds + DECLARE @_BlockCollectionId TABLE (Id INT); + DECLARE @_QuestionBlockCollectionId TABLE (Id INT); + DECLARE @_ImageCarouselBlockCollectionId TABLE (Id INT); + DECLARE @_AllBlockAssociatedFiles TABLE (FileId INT, FilePath NVARCHAR(200)); + + -- Insert BlockCollectionIds based on the provided query +IF @resourceType = 10 +BEGIN + --case +INSERT INTO @_BlockCollectionId (Id) +SELECT DISTINCT c.BlockCollectionId +FROM [resources].[CaseResourceVersion] AS c +INNER JOIN [resources].[ResourceVersion] AS r + ON c.ResourceVersionId = r.Id +INNER JOIN [resources].[Resource] AS r0 + ON r.ResourceId = r0.Id +WHERE + c.Deleted = 0 + AND c.ResourceVersionId = @excludeResourceVersionId + +END +ELSE IF @resourceType = 11 +BEGIN + --assessment +INSERT INTO @_BlockCollectionId (Id) +SELECT DISTINCT Id +FROM ( + SELECT + c.AssessmentContentId AS Id + FROM + [resources].AssessmentResourceVersion AS c + INNER JOIN + [resources].ResourceVersion AS r ON c.ResourceVersionId = r.Id + INNER JOIN + [resources].Resource AS r0 ON r.ResourceId = r0.Id + WHERE + c.Deleted = CAST(0 AS bit) + AND c.ResourceVersionId = @excludeResourceVersionId + + UNION ALL + + SELECT + c.EndGuidanceId AS Id + FROM + [resources].AssessmentResourceVersion AS c + INNER JOIN + [resources].ResourceVersion AS r ON c.ResourceVersionId = r.Id + INNER JOIN + [resources].Resource AS r0 ON r.ResourceId = r0.Id + WHERE + c.Deleted = CAST(0 AS bit) + AND r.Deleted = CAST(0 AS bit) + AND r0.Deleted = CAST(0 AS bit) + AND c.ResourceVersionId <> @excludeResourceVersionId +) as assessmentBlockCollections; +END + + + -- Table to hold temp results for blocks + DECLARE @_TempBlockResult TABLE ( + Id INT, + [Order] INT, + Title NVARCHAR(200), + BlockType INT, + BlockCollectionId INT + ); + + -- Table to hold results for blocks + DECLARE @_BlockResult TABLE ( + Id INT, + [Order] INT, + Title NVARCHAR(200), + BlockType INT, + BlockCollectionId INT + ); + + -- Insert temp block data + INSERT INTO @_TempBlockResult + SELECT Id, [Order], Title, BlockType, BlockCollectionId + FROM resources.Block + WHERE Deleted = 0 AND BlockCollectionId IN (SELECT Id FROM @_BlockCollectionId); + + -- Insert ImageCarouselBlockCollectionId + INSERT INTO @_BlockCollectionId (Id) + SELECT icb.ImageBlockCollectionId + FROM resources.ImageCarouselBlock icb + INNER JOIN @_TempBlockResult b ON icb.BlockId = b.Id + WHERE icb.Deleted = 0; + + --Insert QuestionBlockCollectionId and FeedbackBlockCollectionId + INSERT INTO @_BlockCollectionId (Id) + SELECT qb.QuestionBlockCollectionId + FROM resources.QuestionBlock qb + INNER JOIN @_TempBlockResult b ON qb.BlockId = b.Id + WHERE qb.Deleted = 0 + + UNION + + SELECT qb.FeedbackBlockCollectionId + FROM resources.QuestionBlock qb + INNER JOIN @_TempBlockResult b ON qb.BlockId = b.Id + WHERE qb.Deleted = 0; + + + + + + -- Insert block data + INSERT INTO @_BlockResult + SELECT Id, [Order], Title, BlockType, BlockCollectionId + FROM resources.Block + WHERE Deleted = 0 AND BlockCollectionId IN (SELECT Id FROM @_BlockCollectionId); + + + + -- WholeSlide Image Block + DECLARE @_WsibResult TABLE ( + Id INT, + BlockId INT + ); + + INSERT INTO @_WsibResult + SELECT w.Id, w.BlockId + FROM resources.WholeSlideImageBlock w + INNER JOIN @_BlockResult b ON b.Id = w.BlockId + WHERE w.Deleted = 0; + + -- SELECT * FROM @_WsibResult; + + -- WholeSlide Image Block Items + DECLARE @_WsibiResult TABLE ( + Id INT, + WholeSlideImageBlockId INT, + WholeSlideImageId INT, + PlaceholderText NVARCHAR(255), + [Order] INT + ); + + INSERT INTO @_WsibiResult + SELECT wi.Id, wi.WholeSlideImageBlockId, wi.WholeSlideImageId, wi.PlaceholderText, wi.[Order] + FROM resources.WholeSlideImageBlockItem wi + INNER JOIN @_WsibResult w ON wi.WholeSlideImageBlockId = w.Id + WHERE wi.Deleted = 0; + + --SELECT * FROM @_WsibiResult; + + -- WholeSlide Image + DECLARE @_WsiResult TABLE ( + Id INT, + Title NVARCHAR(1000), + FileId INT + ); + + INSERT INTO @_WsiResult + SELECT wsi.Id, wsi.Title, wsi.FileId + FROM resources.WholeSlideImage wsi + INNER JOIN @_WsibiResult wi ON wsi.Id = wi.WholeSlideImageId + WHERE wsi.Deleted = 0; + + + --SELECT * FROM @_WsiResult; + + -- WholeSlide Image File + DECLARE @_WsiFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @_WsiFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @_WsiResult wsi ON f.Id = wsi.FileId + WHERE f.Deleted = 0; + + INSERT INTO @_AllBlockAssociatedFiles + SELECT Id,FilePath FROM @_WsiFileResult; + + + + -- Media Block + DECLARE @_MediaBlockResult TABLE ( + Id INT, + BlockId INT, + MediaType INT, + AttachmentId INT, + ImageId INT, + VideoId INT + ); + + INSERT INTO @_MediaBlockResult + SELECT mb.Id, mb.BlockId, mb.MediaType, mb.AttachmentId, mb.ImageId, mb.VideoId + FROM resources.MediaBlock mb + INNER JOIN @_BlockResult b ON mb.BlockId = b.Id + WHERE mb.Deleted = 0; + + + --SELECT * FROM @_MediaBlockResult; + + -- Attachment + DECLARE @_AttachmentResult TABLE ( + Id INT, + FileId INT + ); + + INSERT INTO @_AttachmentResult + SELECT a.Id, a.FileId + FROM resources.Attachment a + INNER JOIN @_MediaBlockResult mb ON a.Id = mb.AttachmentId + WHERE a.Deleted = 0; + + --SELECT * FROM @_AttachmentResult; + + -- Attachment File + DECLARE @_AttachmentFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @_AttachmentFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @_AttachmentResult ar ON f.Id = ar.FileId + WHERE f.Deleted = 0; + + INSERT INTO @_AllBlockAssociatedFiles + SELECT Id,FilePath FROM @_AttachmentFileResult; + + -- Attachment File - Partial File + INSERT INTO @_AllBlockAssociatedFiles + SELECT pf.FileId,af.FilePath + FROM resources.PartialFile pf + INNER JOIN @_AttachmentFileResult af ON pf.FileId = af.Id + WHERE pf.Deleted = 0; + + -- Image + DECLARE @_ImageResult TABLE ( + Id INT, + FileId INT, + AltText NVARCHAR(125), + Description NVARCHAR(250) + ); + + INSERT INTO @_ImageResult + SELECT i.Id, i.FileId, i.AltText, i.Description + FROM resources.Image i + INNER JOIN @_MediaBlockResult mb ON i.Id = mb.ImageId + WHERE i.Deleted = 0; + + --SELECT * FROM @_ImageResult; + + -- Image File + DECLARE @_ImageFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @_ImageFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @_ImageResult ir ON f.Id = ir.FileId + WHERE f.Deleted = 0; + + INSERT INTO @_AllBlockAssociatedFiles + SELECT Id,FilePath FROM @_ImageFileResult; + + + -- Video + DECLARE @_VideoResult TABLE ( + Id INT, + FileId INT + ); + + INSERT INTO @_VideoResult + SELECT v.Id, v.FileId + FROM resources.Video v + INNER JOIN @_MediaBlockResult mb ON v.Id = mb.VideoId + WHERE v.Deleted = 0; + + -- SELECT * FROM @_VideoResult; + + -- Video File + DECLARE @_VideoFileResult TABLE ( + Id INT, + FileTypeId INT, + FileChunkDetailId INT, + [FileName] NVARCHAR(255), + FilePath NVARCHAR(1024), + FileSizekb INT + ); + + INSERT INTO @_VideoFileResult + SELECT f.Id, f.FileTypeId, f.FileChunkDetailId, f.[FileName], f.FilePath, f.FileSizeKb + FROM resources.[File] f + INNER JOIN @_VideoResult vr ON f.Id = vr.FileId + WHERE f.Deleted = 0; + + INSERT INTO @_AllBlockAssociatedFiles + SELECT Id,FilePath FROM @_VideoFileResult; + + --SELECT * FROM @_AllBlockAssociatedFiles; +---------------------------------------------------------------------------------------------------------------------- + + DECLARE @SearchResult TABLE ( + Id INT, + FilePath NVARCHAR(1024), + MatchId INT, + MatchedPath NVARCHAR(1024) + ); + + INSERT INTO @SearchResult + SELECT f.FileId, f.FilePath, isMatched.FileId, isMatched.FilePath + FROM @_AllBlockAssociatedFiles f + LEFT JOIN @AllBlockAssociatedFiles isMatched ON (f.FileId = isMatched.FileId or f.FilePath = isMatched.FilePath) + + + DECLARE @result VARCHAR(MAX); + + SELECT @result= STUFF(( + SELECT ', ' + FilePath + FROM @SearchResult WHERE MatchId is NULL + FOR XML PATH(''), TYPE + ).value('.', 'NVARCHAR(MAX)'), 1, 2, ''); + + SET @filePath = @result; + END diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql index 194eb9dac..0a5da6e56 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/GetDashboardResources.sql @@ -17,6 +17,8 @@ -- 08 Nov 2023 OA Fixed latest resource activity entry selection(with updated logic for media activities) and status check for incomplete assessment. -- 17 Jan 2024 SA Changes to accomadate activity status changes -- 27 Feb 2024 SS Fixed missing In progress resources in the My Accessed Learning tray issue +-- 2 May 2024 SA Fixed the issue on showing statuses on 'My accessed Learning' for resource type file +-- 13 May 2024 SA TD-4115 ------------------------------------------------------------------------------- CREATE PROCEDURE [resources].[GetDashboardResources] @@ -225,7 +227,7 @@ BEGIN INSERT INTO @MyActivity SELECT TOP (@MaxRows) ra.ResourceId, MAX(ra.Id) ResourceActivityId FROM - (SELECT a.* FROM activity.ResourceActivity a INNER JOIN (SELECT ResourceId, MAX(Id) as id FROM activity.ResourceActivity GROUP BY ResourceId,ActivityStatusId ) AS b ON a.ResourceId = b.ResourceId AND a.id = b.id order by a.Id desc OFFSET 0 ROWS) ra + (SELECT a.* FROM activity.ResourceActivity a INNER JOIN (SELECT ResourceId, MAX(Id) as id FROM activity.ResourceActivity GROUP BY ResourceId) AS b ON a.ResourceId = b.ResourceId AND a.id = b.id order by a.Id desc OFFSET 0 ROWS) ra JOIN [resources].[Resource] r ON ra.ResourceId = r.Id JOIN [resources].[ResourceVersion] rv ON rv.Id = ra.ResourceVersionId LEFT JOIN [resources].[AssessmentResourceVersion] arv ON arv.ResourceVersionId = ra.ResourceVersionId @@ -237,12 +239,12 @@ BEGIN (r.ResourceTypeId IN (1, 5, 8, 9,10, 12) AND ra.ActivityStatusId <> 3) OR (r.ResourceTypeId IN (2, 7) AND (mar.Id IS NULL OR (mar.Id IS NOT NULL AND mar.PercentComplete < 100) OR ra.ActivityStart < '2020-09-07 00:00:00 +00:00')) OR (r.ResourceTypeId = 6 AND (sa.CmiCoreLesson_status NOT IN (3, 5) AND (ra.ActivityStatusId NOT IN(3, 5)))) - OR (r.ResourceTypeId IN (9) AND ra.ActivityStatusId NOT IN (6)) - OR (r.ResourceTypeId = 11 AND ((ara.Id IS NOT NULL AND ara.score < arv.PassMark) OR ra.ActivityStatusId IN (1))) + OR ((r.ResourceTypeId = 11 AND arv.AssessmentType = 2) AND ((ara.Id IS NOT NULL AND ara.score < arv.PassMark) OR ra.ActivityStatusId IN (7))) + OR ((r.ResourceTypeId = 11 AND arv.AssessmentType = 1) AND ra.ActivityStatusId = 7) ) GROUP BY ra.ResourceId ORDER BY ResourceActivityId DESC - + SELECT ma.ResourceActivityId, r.Id AS ResourceId ,( SELECT TOP 1 rr.OriginalResourceReferenceId FROM [resources].[ResourceReference] rr @@ -312,7 +314,7 @@ BEGIN (r.ResourceTypeId IN (2, 7) AND ra.ActivityStatusId IN (3) AND ((mar.Id IS NOT NULL AND mar.PercentComplete = 100) OR ra.ActivityStart < '2020-09-07 00:00:00 +00:00')) OR (r.ResourceTypeId = 6 AND (sa.CmiCoreLesson_status IN(3,5) OR (ra.ActivityStatusId IN(3, 5)))) OR (r.ResourceTypeId = 11 AND ara.Score >= arv.PassMark OR ra.ActivityStatusId IN( 3, 5)) - OR (r.ResourceTypeId IN (1, 5, 8, 9, 10, 12) AND ra.ActivityStatusId IN (3))) + OR (r.ResourceTypeId IN (1, 5, 8, 9, 10, 12) AND ra.ActivityStatusId = 3)) GROUP BY ra.ResourceId ORDER BY ResourceActivityId DESC @@ -384,8 +386,9 @@ BEGIN AND ( (r.ResourceTypeId IN (2, 7) AND ra.ActivityStatusId IN (3) OR ra.ActivityStart < '2020-09-07 00:00:00 +00:00' OR mar.Id IS NOT NULL AND mar.PercentComplete = 100) OR (r.ResourceTypeId = 6 AND (sa.CmiCoreLesson_status IN(3,5) OR (ra.ActivityStatusId IN(3, 5)))) - OR (r.ResourceTypeId = 11 AND ara.Score >= arv.PassMark OR ra.ActivityStatusId IN(3, 5)) - OR (r.ResourceTypeId IN (1, 5, 8, 9, 10, 12) AND ra.ActivityStatusId IN (3))) + OR ((r.ResourceTypeId = 11 AND arv.AssessmentType = 2) AND (ara.Score >= arv.PassMark OR ra.ActivityStatusId IN(3, 5))) + OR ((r.ResourceTypeId = 11 AND arv.AssessmentType =1) AND (ara.Score >= arv.PassMark AND ra.ActivityStatusId IN(3, 5,7))) + OR (r.ResourceTypeId IN (1, 5, 8, 9, 10, 12) AND ra.ActivityStatusId = 3)) GROUP BY ra.ResourceId ORDER BY ResourceActivityId DESC diff --git a/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IBlockCollectionRepository.cs b/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IBlockCollectionRepository.cs index 0a1a52618..2a5bbb916 100644 --- a/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IBlockCollectionRepository.cs +++ b/WebAPI/LearningHub.Nhs.Repository.Interface/Resources/IBlockCollectionRepository.cs @@ -1,8 +1,10 @@ namespace LearningHub.Nhs.Repository.Interface.Resources { + using System; using System.Collections.Generic; using System.Threading.Tasks; using LearningHub.Nhs.Models.Entities.Resource.Blocks; + using LearningHub.Nhs.Models.Enums; /// /// The BlockRepository interface. @@ -30,5 +32,13 @@ public interface IBlockCollectionRepository : IGenericRepositoryThe Block Collection Id. /// The . Task> GetQuestionBlocks(int blockCollectionId); + + /// + /// Gets the Case, AssessmentContent, AssessmentGuidance Block Collections (including child Blocks, TextBlocks, WholeSlideImageBlocks and Files) except that of the provided resource version. + /// + /// The excluded ResourceVersion Id. + /// The resource type. + /// The . + Task GetResourceBlockCollectionsFileAsync(int excludeResourceVersionId, ResourceTypeEnum resourceTypeEnum); } } diff --git a/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs b/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs index be2bc4f98..dc9ac9d94 100644 --- a/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs +++ b/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs @@ -166,6 +166,28 @@ await Task.WhenAll(blockCollection.Blocks return blockCollection; } + /// + /// Gets the Case, AssessmentContent, AssessmentGuidance Block Collections (including child Blocks, TextBlocks, WholeSlideImageBlocks and Files) except that of the provided resource version. + /// + /// The excluded ResourceVersion Id. + /// The resource type. + /// The . + public async Task GetResourceBlockCollectionsFileAsync(int excludeResourceVersionId, ResourceTypeEnum resourceTypeEnum) + { + if (excludeResourceVersionId > 0) + { + var param0 = new SqlParameter("@excludeResourceVersionId", SqlDbType.Int) { Value = excludeResourceVersionId }; + var param1 = new SqlParameter("@resourceType", SqlDbType.Int) { Value = (int)resourceTypeEnum }; + var param2 = new SqlParameter("@filePath", SqlDbType.NVarChar) { Direction = ParameterDirection.Output, Size = -1 }; + await this.DbContext.Database.ExecuteSqlRawAsync("[resources].[BlockCollectionFileSearch] @excludeResourceVersionId, @resourceType, @filePath output", param0, param1, param2); + return param2.Value.ToString(); + } + else + { + return string.Empty; + } + } + /// /// Gets the Question blocks for a particular blockCollectionId. /// @@ -416,5 +438,73 @@ private void SetAuditFieldsOnChildren(int userId, ImageCarouselBlock imageCarous this.SetAuditFieldsForCreateOrDelete(userId, imageCarouselBlock.ImageBlockCollection, isCreate); this.SetAuditFieldsOnChildren(userId, imageCarouselBlock.ImageBlockCollection, isCreate); } + + private async Task GetResourceBlockCollectionsFilePath(int excludeResourceVersionId) + { + var command = new SqlCommand + { + CommandType = CommandType.StoredProcedure, + CommandText = "[resources].[CaseBlockCollectionGetAll]", + Parameters = { new SqlParameter("@excludeResourceVersionId", SqlDbType.Int) { Value = excludeResourceVersionId } }, + }; + + var results = this.DbContext.MultipleResults(command) + .With() + .With() + .With() + .With() + .With() + .With() + .With() + .With() + .With() + .With() + .With() + .With() + .With() + .With() + .With() + .With() + .With() + .With