Пример #1
0
        private static IEnumerable <Vertical> OrdinarySlideToVerticals(string courseId, Slide slide, string ulearnBaseUrl, Dictionary <string, string> videoGuids, string ltiId, DirectoryInfo coursePackageRoot)
        {
            var componentIndex = 0;
            var components     = new List <Component>();

            while (componentIndex < slide.Blocks.Length)
            {
                var blocks = slide.Blocks.Skip(componentIndex).TakeWhile(x => !(x is YoutubeBlock) && !(x is ExerciseBlock)).ToList();
                if (blocks.Count != 0)
                {
                    var innerComponents = new List <Component>();
                    foreach (var block in blocks)
                    {
                        if (!block.Hide)
                        {
                            var component = block.ToEdxComponent("", courseId, slide, componentIndex, ulearnBaseUrl, coursePackageRoot);
                            innerComponents.Add(component);
                        }
                        componentIndex++;
                    }

                    if (innerComponents.Any())
                    {
                        var displayName    = componentIndex == blocks.Count ? slide.Title : "";
                        var header         = displayName == "" ? "" : "<h2>" + displayName + "</h2>";
                        var slideComponent = new HtmlComponent
                        {
                            DisplayName   = displayName,
                            UrlName       = slide.NormalizedGuid + componentIndex,
                            Filename      = slide.NormalizedGuid + componentIndex,
                            Source        = header + string.Join("", innerComponents.Select(x => x.AsHtmlString())),
                            Subcomponents = innerComponents.ToArray()
                        };
                        components.Add(slideComponent);
                    }
                }
                if (componentIndex >= slide.Blocks.Length)
                {
                    break;
                }

                var exerciseBlock  = slide.Blocks[componentIndex] as ExerciseBlock;
                var otherComponent = exerciseBlock != null
                                        ? exerciseBlock.GetExerciseComponent(componentIndex == 0?slide.Title : "Упражнение", slide, componentIndex, string.Format(ulearnBaseUrl + SlideUrlFormat, courseId, slide.Id), ltiId)
                                     : ((YoutubeBlock)slide.Blocks[componentIndex]).GetVideoComponent(componentIndex == 0 ? slide.Title : "", slide, componentIndex, videoGuids);

                components.Add(otherComponent);
                componentIndex++;
            }

            var exerciseWithSolutionsToShow = slide.Blocks.OfType <ExerciseBlock>().FirstOrDefault(e => !e.HideShowSolutionsButton);

            if (exerciseWithSolutionsToShow != null)
            {
                var comp = exerciseWithSolutionsToShow.GetSolutionsComponent(
                    "Решения",
                    slide, componentIndex,
                    string.Format(ulearnBaseUrl + SolutionsUrlFormat, courseId, slide.Id), ltiId);
                components.Add(comp);
                //yield return new Vertical(slide.NormalizedGuid + "0", "Решения", new[] { comp });
            }
            var exBlock = slide.Blocks.OfType <ExerciseBlock>().FirstOrDefault();

            if (exBlock == null)
            {
                yield return(new Vertical(slide.NormalizedGuid, slide.Title, components.ToArray()));
            }
            else
            {
                yield return(new Vertical(slide.NormalizedGuid, slide.Title, components.ToArray(), EdxScoringGroupsHack.ToEdxName(exBlock.ScoringGroup), exBlock.MaxScore));
            }
        }
Пример #2
0
        private static IEnumerable <Vertical> QuizToVerticals(string courseId, QuizSlide slide, string slideUrl, string ltiId)
        {
            var ltiComponent =
                new LtiComponent(slide.Title, slide.NormalizedGuid + "-quiz", string.Format(slideUrl, courseId, slide.Id), ltiId, true, slide.MaxScore, false);

            yield return(new Vertical(slide.NormalizedGuid, slide.Title, new Component[] { ltiComponent }, EdxScoringGroupsHack.ToEdxName(slide.ScoringGroup), slide.MaxScore));
        }